In recent programming languages, Golang is undoubtedly the wind, the annual language, server-side language, concurrency language, the crown is a lot. Golang Development was originally designed to replace C + +, as a system-level language, and in the 1.3 version of the plan to compile the system from the original C language development of the Plan 9 compiler, to Golang implementation, is ambitious. Golang The most admirable is the simple grammar, you may not spend a day to master the Golang grammar, keywords. Golang's goroutine and channel give you a simple concurrency programming model (it is pointed out that the channel is another option, not to replace the lock mechanism of concurrent programming, but mutual subsidy).
Here, pour cold water on golang, or, if Golang want to become the mainstream language, still need to solve which important problem.
- A lock-free sched scheduling algorithm. Golang allows you to create thousands of goroutine, unlike native system-level threads, Goroutine's schedule is not done by the system kernel, but by golang its own sched dispatch system. Golang's Sched scheduling system uses the more famous Work-steel algorithm, we all know that the most core of the algorithm is a data structure is a task queue, how to ensure that the correctness of the queue high concurrency is the focus of the algorithm, more familiar with Java students should know, master Doug Lea's uncle William's Fork-join The concurrency framework uses a 64-bit volatile long field to ensure high concurrency without locking of the queue (note that volatile is different from the semantics in C + + in Java), while Golang uses locks to implement concurrent access. This undoubtedly dropped a grade, fortunately in the Golang 1.3 of the plan has been clearly identified sched unlocked as an important work.
- A more lightweight memory management framework. We all know that Google has a very cow performance analysis and strengthening framework called Google Perftools, the framework has a multi-threaded malloc (). Golang Internal memory Management framework adopts the formal framework, so if it is the Golang program there is no need to link perftools to improve performance. This framework is very good for a common framework, however, Golang memory allocation at the beginning of the definition of memory size, 64-bit system is 128G of memory, so the memory allocation in this case is simple, and the use of an extremely complex malloc is it necessary? Despite the community reaction, even Russ Cox expressed the need to simplify the idea, unfortunately did not join the Golang 1.3 plan.
- an optimized garbage collection algorithm. golang the current garbage collection mechanism is extremely naïve, when the system uses memory to reach the last GC collection of the proportion of time to do a full memory of the tag scan recovery, the default is twice times, that is, by default, 64-bit system you can use up to 64g of memory, of course, this is the ideal situation, in reality , you don't expect to be relieved to create a large memory system under this GC algorithm. CMS has been widely used in Java and is the best GC in practice. Golang If you want to be a mainstream language, you have to be on GC and Java at a level, otherwise you can often simply Golang vs python articles. At present, to improve the garbage collection accuracy (Golang in the memory of the object is not determined, will default 4 bytes a time scan memory, this is too slow), the scanning phase does not pause the system is more realistic, divided into the long-term partition will be.
- a heap Dump tool. If you do not know how the Golang program instance memory is distributed, to optimize your program, it is elephant. Online there is a group of students, in an online system, found that using map will slow down the GC, he can only guess is the GC to map has a special processing caused, in fact, the actual reason is a map in the GC will retain a lock, and the GC can not be recycled the map, if the map is a main structure, The CMS GC becomes a single-threaded scan GC, fortunately the problem has been fixed in Golang 1.2. It is gratifying that Golang 1.3 is likely to release the heap dump tool. Replace the existing split stack with the copy stack. Golang most boast is that the lightweight goroutine,goroutine management has golang to implement, each goroutine will default in the heap allocation of a 4k memory block as the Goroutine stack. Unlike Java, the Golang stack can theoretically be infinitely large, thanks to the Golang split stack mechanism, when the goroutine stack is full, Golang allocates a block of memory to complement it, creating an infinitely large stack. However, analyticals, reminder. When the stack becomes an hour, the Golang releases the idle stack, and if a long-running program, the stack is bound to scale frequently, so that the memory allocated and released is quite frequent, affecting performance. Fortunately, Ross Cox has decided to use the copy stack approach to solve the problem, and copy stack will not cause memory surplus, such as a goroutine a large stack, the future stack is very small, let us wait and see.
- Replace the existing split stack with the copy stack. Golang most boast is that the lightweight goroutine,goroutine management has golang to implement, each goroutine will default in the heap allocation of a 4k memory block as the Goroutine stack. Unlike Java, the Golang stack can theoretically be infinitely large, thanks to the Golang split stack mechanism, when the goroutine stack is full, Golang allocates a block of memory to complement it, creating an infinitely large stack. However, analyticals, reminder. When the stack becomes an hour, the Golang releases the idle stack, and if a long-running program, the stack is bound to scale frequently, so that the memory allocated and released is quite frequent, affecting performance. Fortunately, Ross Cox has decided to use the copy stack approach to solve the problem, and copy stack will not cause memory surplus, such as a goroutine a large stack, the future stack is very small, let us wait and see.
Golang in grammar I think is impeccable, above is I think golang urgently need to solve the problem, if can solve these problems, especially GC and scheduling, I think I will not go back to the Golang camp.