timer - infinite loop vs boost::asio::deadline_timer C++ performance -
i develop server application handles many connections clients. server sends message each clients periodically(ex: every 1 second), check client's expiry times(each client must disconnected server forcibly when connected time reaches predetermined value) , other timer tasks. consider 2 solutions:
- use while(true){foreach clients{check time}}
- for each client, delcare deadline_timer , call async_wait each task, spawn lot of deadline_timer instances
which solution better performance? in general, should use infinite loop or declaring many timer instances? , 1 more, can explain how os manages deadline_timer?
q. solution better performance?
infinite loops bad. exceptions found in cpu-saturating workers thread affinity (but doesn't appear applicable here).
q. in general, should use infinite loop
no
q. or declaring many timer instances?
or
std::vector<boost::shared_ptr<asio::deadline_timer> > m_timers;
or similar :)
q. , 1 more, can explain how os manages deadlien_timer?
the timers using platform specific kernel events, under hood. meaning, in practice, if have e.g. 10 tasks blocked on different timers, kernel keep process in sleep state (not running @ all) until first 1 expires.
kernel-level synchronization primitives in general fastest way non-cpu bound work loads, far.
Comments
Post a Comment