On which type of load (CPU-bound or I/O-bound) can you run the most goroutines in Go?
sobes.tech AI
Answer from AI
In Go, you can run more goroutines for I/O-bound workloads than for CPU-bound ones.
The reason is that goroutines are lightweight threads that switch efficiently during I/O wait times (e.g., network requests, disk operations). In such cases, goroutines are idle, waiting for the operation to complete, and the Go scheduler can switch between them without significant CPU load.
For CPU-bound tasks, goroutines actively use the processor, and the number of effectively concurrent goroutines is limited by the available CPUs (GOMAXPROCS). Launching too many CPU-bound goroutines will lead to overhead from context switching and reduced performance.
Thus, for I/O-bound tasks, thousands or even tens of thousands of goroutines can be created, whereas for CPU-bound tasks, the number of goroutines should typically be limited to the number of processor cores.