How many goroutines can I use painless? For example wikipedia says, in Erlang 20 million processes can be created without degrading performance.
Update: I’ve just investigated in goroutines performance a little and got such a results:
- It looks like goroutine lifetime is more then calculating sqrt() 1000 times ( ~45µs for me ), the only limitation is memory
- Goroutine costs 4 — 4.5 KB
If a goroutine is blocked, there is no cost involved other than:
The costs (in terms of memory and average time to actually start executing a goroutine) are:
On a machine with 4 GB of memory installed, this limits the maximum number of goroutines to slightly less than 1 million.
Source code (no need to read this if you already understand the numbers printed above):