
The Secret Life of Go: Worker Pools
How to Stop Crashing Your Server with 10,000 Goroutines Part 26: Controlling Concurrency and The Dispatcher Ethan was staring at a wall of red text on his monitor. "Out of memory," he muttered. "How? Go is supposed to be incredibly efficient." Eleanor walked by with her coffee. "What did you crash this time?" "The image processing service," Ethan sighed. "We had a backlog of ten thousand images to resize. Since goroutines are lightweight, I just launched one for every single image so they would all process at the same time." He showed her the code: func ProcessAll ( images [] string ) { var wg sync . WaitGroup for _ , img := range images { wg . Add ( 1 ) go func ( imageName string ) { defer wg . Done () resizeImage ( imageName ) // Opens the file, decodes, resizes, saves }( img ) } wg . Wait () } "You are right that goroutines are cheap," Eleanor said. "They only take a couple of kilobytes of memory to start. But the work they do is not cheap. You just told your operating system to ope
Continue reading on Dev.to
Opens in a new tab


