Throttling Goroutines
Control concurrency.
Throttling Concurrency
Sometimes you do not limit per second, you limit how many goroutines run at once. This caps simultaneous load on a resource regardless of timing.
- Bounds parallelism
- Protects connection pools
- Prevents memory spikes
The Semaphore Channel
A buffered channel works as a counting semaphore. Its capacity equals the maximum concurrency. Acquiring sends a token; releasing receives one.
sem := make(chan struct{}, 3)All lessons in this course
- Token Bucket Concept
- golang.org/x/time/rate
- Throttling Goroutines
- Backoff and Retry