I'm developing a backend for a networking product, that serves a dozen of clients (N
= 10-100). Each connection requires 2 periodic tasks, the heartbeat, and downloading of telemetry via SSH, each at H
Hz. There are also extra events of different kind coming from the frontend. By nature of every of the tasks, there is a solid part of waiting in select
call on each connection's socket, which allows OS to switch between threads often to serve other clients while waiting for response.
In my initial implementation, I create 3 threads per connection (heartbeat, telemetry, extra), each waiting on a single condition variable, which is poked every time there is something to do in a workqueue. The workqueue is filled with the above-mentioned periodic events using a timer and commands from the frontend.
I have a few questions here.
Would it be a good idea to switch a worker thread pool approach to Intel TBB tasks? If so, to which value of threads do I need to initialize
tbb::task_scheduler_init
?In the current approach with 300 threads waiting on a conditional variable, which is
signal
edN * H * 3
times per second, it is likely to become a bottleneck for scalability (especially on the side which callssignal
). Are there any better approaches for waking up just one worker per task?How is waking of a worker thread implemented in TBB?
Thanks for your suggestions!