Home > Backend Development > Golang > Why docker uses go language

Why docker uses go language

青灯夜游
Release: 2023-02-17 14:33:35
Original
3176 people have browsed it

Reasons: 1. Mainstream services use the Unix/Linux operating system, and the go language has very little dependence on third parties. In this way, Docker developed using the go language can basically run perfectly on most Unix/Linux installations. operating system on the server. 2. Go language has many advantages such as simple deployment, good concurrency, and good execution performance.

Why docker uses go language

The operating environment of this tutorial: windows10 system, GO 1.18, thinkpad t480 computer.

Docker is an open source application container engine that allows developers to package their applications and dependency packages into a portable container, and then publish them to any popular Linux machine or Windows machine. It can also be implemented In virtualization, containers completely use the sandbox mechanism and will not have any interfaces with each other.

Why does docker use go language?

First of all, our current mainstream services all use Unix/Linux operating systems, and as described earlier, Golang has very little dependence on third parties (only relying on glibc). This is both a limitation and an advantage. Because in this case, Docker developed using Golang can basically run perfectly on most servers installed with Unix/Linux operating systems.

Secondly, Golang development has many advantages:

1. Simple deployment.

Go compilation generates a static executable file with no other external dependencies except glibc. This makes deployment extremely convenient: only a basic system and necessary management and monitoring tools are needed on the target machine, and there is no need to worry about the dependencies of various packages and libraries required by the application, greatly reducing the burden of maintenance. This is hugely different from Python. Due to historical reasons, Python's deployment tool ecology is quite confusing [such as the different applicable occasions and compatibility issues of setuptools, distutils, pip, buildout]. The official PyPI source often has problems, and a private mirror needs to be built, and maintaining this mirror takes a lot of time and energy.

2. Good concurrency.

Goroutine and channel make it very easy to write high-concurrency server-side software. In many cases, there is no need to consider the lock mechanism and the various problems caused by it. A single Go application can also effectively utilize multiple CPU cores and achieve good parallel execution performance. This is also worlds apart from Python. Multi-threaded and multi-process server programs are not simple to write, and due to the global lock GIL, multi-threaded Python programs cannot effectively utilize multiple cores and can only be deployed in a multi-process manner; if you use multiprocessing in the standard library Packages will also pose many challenges to monitoring and management [the supervisor we use to manage the process does not support fork well]. When deploying Python applications, one application is usually deployed per CPU core, which will cause a lot of waste of resources. For example, assuming that a Python application needs to occupy 100MB of memory after startup, and the server has 32 CPU cores, then one core is left for System, running 31 application copies will waste 3GB of memory resources.

3. Good language design.

From an academic point of view, the Go language is actually very mediocre and does not support many advanced language features; but from an engineering point of view, the design of Go is very excellent: the specifications are simple and flexible enough, and have the basis of other languages. Programmers can get started quickly. More importantly, Go comes with a complete tool chain, which greatly improves the consistency of team collaboration. For example, gofmt automatically formats Go code, which largely eliminates the problem of inconsistent formatting styles of codes written by different people. Configure the editor to automatically run gofmt when editing the archive, so that you can place it anywhere when writing code, and it will automatically become correctly formatted code when archiving. In addition, there are very useful tools such as gofix and govet.

4. Good execution performance.

Although it is not as good as C and Java, it is usually an order of magnitude higher than native Python applications, and is suitable for writing some bottleneck businesses. The memory usage is also very economical.

Recommended learning: Golang tutorial

The above is the detailed content of Why docker uses go language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template