Documentation ¶
Overview ¶
massivevirtualparallelism tests how many goroutines can be run in practice
Virtual Threads ¶
What sets Go apart is the concept of virtual threads. Other languages have had similar concepts but not like Go with machine-instruction synchronization mechanics and runtime support hiding blocking
Virutal threads is a necessity going forward because there is not adequate hardware support in terms of processor cores and operating system threads to respond in a performant way. Polling and event queues is not performant. With virtual threads, the programmer can define millions of activities and possible events to be urgent
Virtual threads is how to effectively utilize the processors, cores and hyper threads offered by the hardware in 2022
Because virtual threads is difficult to retrofit, it was the right decision by the Pike to create a new language. Either the runtime has to be re-written or the programmer becomes subject to draconian restictions. Oracle has a Java Loom project to rewrite the Java runtime for virtual threads
Other Go Benefits ¶
Go also has a practically pause-less garbage collector, the ability to utilize native platform interfaces easily and the concept of contexts allowing all possible actions to be started immediately and subsequently cancelling those circumstances do not call for. This is the fastest way to obtain results, allows encapsulated threads and avoids complex and error prone execution graphs
The Go ability to cross compile, support many architectures and operating systems and deploy as a self-contained executable brings comforting portability with machine-code performance
Massive Parallelism ¶
Massive parallelism is a system with hundreds or thousands of processor cores allowing for a large number of tasks to execute in parallel. The related concept concurrency is perceived parallelism by access to processing resources shared over time. Go is not usually massively parallel but still parallel on four or so processor cores
Parallelsim is important because the historically single-threaded Node.js can lock up from a single mistake, while Go would still have additional parallel threads to continue execution and the ability to schedule a different virtual thread for the operating system thread. An event queue is troublesome for high-traffic servers, because it introduces delays in processing of incoming requests. Most scripted languages are single-threaded by a global interpreter lock. Besides Go, the good options are very few
Multi-threaded programming can be diffcult and fault prone. In Go, Rob Pike has simplified mercilessly to only support one synchornization mechanic in the Go memory model: the lock. Because a thread may have dozens of locks for different things, those locks are low-contention. Pike no like atomics
Conclusion — 50 million virtual threads — averaging 240,000 launched per second ¶
On a 2021 Apple MacBook Pro 64 GiB 32 gpu, Go can sustainably launch about 240,000 virtual threads per second until available memory becomes a problem. The program runs fairly well for 5 minutes and 4 cores up to 50 million threads where progress effectively stops. Go does not produce an error and the program continues to run, but after a 5-minute swap session and 233 GiB of acquired memory, Go resigns to a single core and new threads are no longer launched.
For anyone a former multi-threaded Java programmer, such numbers are unbelievably fantastic
Go was discovered in 2009 by Rob Pike, Robert Griesemer and Ken Thompson at Google ¶
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)