[Translation] Why You Should Go learn the language? (on)

Original Address

"Go will be the future server-side language." --Tobias Lütke, Shopify

In the past few years, the rise of a new language: Go, also known as GoLang. As a developer, there is nothing more exciting than a new programming language, so I started learning Go until four or five months. In this article, I will tell you why you should learn this new programming language.

In this article, I will not teach you how to write "Hello World !!". There has been such a tutorial on the network a lot. In this article I will explain the current status of the development of hardware and software, as well as, in such a situation, why should we like Go learn a new language. Because there is a problem, it is necessary to find a solution.

Hardware limitations

Moore's Law in failure.

In 2004, the company introduced the first Intel Pentium 4 processor with 3.0GHz clock speed. Now, my Macbook Pro 2016 models only 2.9GHz clock speed. Therefore, raw processing power in the past decade, there is little improvement. The figure below clearly shows the relationship between the growth of processing power and time.

We can see from the figure above, single-threaded processor performance and frequency of almost flat growth in the last decade. If you think adding more transistors can be resolved, then you are wrong. Because at the microscopic level, quantum characteristics began to appear (for example: quantum tunneling through), put more transistors cost will be higher ( Why? ), And the number of transistors that can be added per dollar began to fall.

Therefore, to address the problem, the solution is as follows:

  • Manufacturers began adding more cores to the processor. Today we have quad-core and eight-core CPU available.
  • The introduction of Hyper-Threading technology.
  • Processor to add more cache to improve performance

However, the above scheme itself has limitations. Because of the physical limitations of the cache itself: the larger the cache, the slower the speed, so we can not always increase the cache to the processor to improve performance. Adding more cores to the processor is not without its costs. This expansion is also limited. The multi-core processor may run multiple threads simultaneously, thereby realizing concurrency. We'll discuss it later.

So, if we can not rely on hardware upgrade, the only way that can only be to improve performance through more efficient software. Unfortunately, the modern programming languages ​​are not very efficient.

“Modern processors are a like nitro fueled funny cars,they excel at the quarter mile. Unfortunately modern programming languages are like Monte Carlo,they are full of twists and turns.” --David Ungar

Go have goroutine !!

As mentioned above, hardware manufacturers to improve performance by adding more cores to the processor. All data centers are run on these processors, we should expect in the next few years the number of cores increase. Furthermore, today's applications use multiple services to maintain the connection of micro databases, message queues, and to keep the cache. Therefore, we developed software and programming languages ​​should be easier to support concurrency, and, with the growth in the number of cores, they should be scalable.

However, most modern programming languages ​​(such as Java, Python, etc.) are from single-threaded environment in the 1990s. While most of these language support multithreading, but the real problem is the concurrent execution, thread-locking, race conditions and deadlocks. These problems make it difficult to create a multi-threaded application in these languages.

For example, to create a new thread in Java, memory utilization is not efficient. Each thread consumes about 1 MB of heap memory, ultimately, if you run thousands of threads, they will heap enormous pressure, and downtime due to insufficient memory. In addition, you want to communicate between two or more threads, it is very difficult.

On the other hand, Go released in 2009, when the multi-core processors already available. This is why Go to consider when building will ensure concurrency. Go have goroutine instead of thread, single goroutine consumes about 2 KB of heap memory. So, you can start at any time on one million goroutine.

Other benefits:

  • Goroutine has a retractable segmented stack (after version 1.4, has been changed to continuous stack), which means more memory will be used when needed.
  • Goroutine start up faster than thread.
  • Goroutine own secure communications protocol, channels.
  • Goroutine allows you to avoid the use of mutex in shared data structures.
  • In addition, goroutine system thread and no 1: 1 relationship mapping. Single goroutine can run on multiple threads. Goroutine also be multiplexed onto a small number of system threads.

You can lecture by Rob Pike concurrency is not parallel to deepen understanding.

Based on the above, the Go can be like Java, C or C ++ as has a strong concurrent processing capability, but also like Erlang as to ensure the rigor of concurrent execution of code, while also very elegant.

Guess you like

Origin juejin.im/post/5dbeaaec6fb9a020556db0b0