4 ms·
The one that comes to mind in particular was something that sent email. We wanted to limit emails being sent per email server to each ISP. We went with: queue
by sbov 15y ago
The one that comes to mind in particular was something that sent email. We wanted to limit emails being sent per email server to each ISP.
We went with: queue per ISP for emails to send out, then each server that could send email to that ISP had its own thread. Each thread would take X emails out of the queue every 10 seconds, send them, then sleep for any leftover time - or not if there isn't any.
Most of the time is spent sleeping or on I/O - the point of threads wasn't for CPU usage, it was because it made everything so simple to implement. The only synchronization issues were taking emails out of the queue and putting them back somewhere if they failed to send.
All of the logic for each thread in its main loop read like a normal, sequential program. I guess you could call this an embarrassingly easy problem, but part of why it's so easy is it maps so easily to threads.