4 ms·
> If you have multiple channels that you could read from in a select call but none are ready, could you block that select instance and process a different proce
by Galanwe 3y ago
> If you have multiple channels that you could read from in a select call but none are ready, could you block that select instance and process a different process where other selects are potentially waiting?
From my experience, the most versatile approach for the wait on channels is best implemented as a spin lock with exponential backoff, up to a threshold that yields - effectively letting other threads perform their own select. Note that most of the time, if you are targeting latency, you would try not to get more workers than cores, meaning you would pin each worker to a core, thus not really benefiting from yielding on select.
> But there's balance between latency and throughput, if you send a big task you get higher latency to react to the next task but better throughput.
Agree, but that's mainly a client concern, the queue can propose multiple APIs. Most queues handle that with a "burst" mode, where you pop or push multiple messages at once instead of 1 by 1, to balance throughput vs latency.
- jpc0 3y ago> a spin lock with exponential backoff Also measure before you implement this yourself, to my knowledge this is infact what the linux mutex does anyway.