Go language GOMAXPROCS (adjusted operating performance concurrent)

In the  Go language runtime (runtime) implements a small task scheduler. This works similar to the operating system scheduler schedules threads, Go scheduler CPU resources can be efficiently allocated to each task. Traditional logic, developers need to maintain the thread pool and the number of CPU core correspondence. The same, Go may be ground () function is done by runtime.GOMAXPROCS, the format:

runtime.GOMAXPROCS (number of logical CPU)

Here the number of logical CPU can have several values ​​are as follows:

  • <1: does not modify any value.
  • = 1: single-core execution.
  • > 1: Multicore concurrently.


Under normal circumstances, it can be used runtime.NumCPU () number of queries the CPU, and runtime.GOMAXPROCS () function is provided, for example:

  1. runtime.GOMAXPROCS(runtime.NumCPU())

Before Go 1.5 version, the default is to use single-core execution. Starting Go 1.5 version, the default implementation of the above statements in order to make the code execute concurrently, the maximum efficient use of CPU.

GOMAXPROCS but also an environment variable, before the application starts to set environment variables can also play the same role.

Also note that the point here is: Go performed using the default number of CPU cores for maximum system CPU core.

Guess you like

Origin www.cnblogs.com/smallleiit/p/11769226.html