massivevirtualparallelism

command module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: ISC Imports: 11 Imported by: 0

README

massivevirtualparallelism

15 million virtual threads — averaging 600,000 new per second

This program tests how many threads Go can run in practice

There is no apparent limit to the number of threads other than available swap space, time and the size of int

On a 2021 Apple MacBook Pro 64 GiB 32 gpu, Go can without swap on a 64 GiB computer launch 15 million threads at a rate of 600,000 per second. Threads consume about 3 kilobytes a piece.

  • Running Go with many virtual threads is memory limited at 3 KiB per thread
  • Running without using swap (2/3 of memory) on 64 GiB is 15 million threads launching at 600,000 threads per second at 41 GiB memory usage completing in about 30 seconds
  • 50 million threads completes in about 10 minutes at 140 GiB memory usage
  • At 85 million threads and 4 times overcommit, the computer is thrashing
  • 100 million threads completes in 70 minutes: go run ./ 1e8
  • There is no apparent limit to the number of threads other than available swap space and the size of int
    • In particular, Go produces no errors or panics
  • Go is processor usage per top is in the 600% to 980% range at 10% idle for 8+2 cores per top -ocpu
    • Go is processor limited
  • Go and swap together consumes about 900% processor cores with 10% idle
  • See the file 50million.txt and 15million.txt: go run ./ 5e7 2>&1 | tee 50million.txt

© 2022–present Harald Rudell (https://haraldrudell.github.io/haraldrudell/)
ISC License

“justice, peace and massive virtual parallelism”

go run ./ 1e8

massivevirtualparallelism 2022-03-21 14:20:34-07:00
host: c66 go1.18 os-arch: darwin arm64 64 GiB cores: 10
Launching threads: 100,000,000…
265μs Status thread count: 100. Waiting for thread launch to complete…
1.0s running: 805,898 launched: 805,898 launch-rate: 771,632/s started: 804,929 start-rate: 770,708/s
…
4.1s running: 2,892,619 launched: 2,892,619 launch-rate: 272,506/s started: 2,892,600 start-rate: 272,505/s
6.3s EXECUTION DELAY: 2.1s expected: 1.0s
23.3s EXECUTION DELAY: 10.3s expected: 1.0s
1m45s EXECUTION DELAY: 31.2s expected: 1.0s
3m4s EXECUTION DELAY: 1m19s expected: 1.0s
…
5m4s Thread launch complete
5m4s Waiting 3s s for ticker events
5m4s running: 100,000,000 launched: 100,000,000 launch-rate: 270,944/s started: 100,000,000 start-rate: 273,236/s
…
5m7s Shutting down…
5m7s running: 99,987,400 exited: 12,600 exit-rate: 12,600/s
…
1h9m9s Thread shutdown complete: Maximum time between ticks (normally 1 second): 1m19s
1h9m9s Maxima observed: max duration: 3m29s max value: 100,000,000 max rate: 1,308,930
1h9m9s running: 0 ticks: 218 launched: 100,000,000 started: 100,000,000 exited: 100,000,000 panic: 0 errs: none
1h9m9s massivevirtualparallelism completed successfully

How to use

  • go get codeberg.org/haraldrudell/massivevirtualparallelism
  • Download and build the Go project from codeberg.org
  • Download the executable for your platform (macOS will not immediately execute)

Documentation

Go Reference  Documentation in the Go Package Index

On March 19, 2022, massivevirtualparallelism was open-sourced under an ISC License

© 2022–present Harald Rudell harald.rudell@gmail.com (https://haraldrudell.github.io/haraldrudell/)

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/)

Directories

Path Synopsis
Package goer manages a large number of virtual threads
Package goer manages a large number of virtual threads

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL