Is System.Threading.Timer efficient enough for thousands of concurrent timers?

I am working on a request timeout mechanism. My initial approach would be to create one System.Threading.Timer for each request. The number of simultaneous requests can increase to a thousand.

I am wondering if I should instead create a TimeoutScheduler that will use only one timer instead of a single request.

Could someone who knows the insides of System.Threading.Timer give me some idea of ​​whether TimeoutScheduler would be a good idea or if it tries to optimize something that is already quite efficient.

Note. For my scenario, timer accuracy is not important.

(I did some performance tests with System.Threading.Timer with a lot of parallel timers. It seemed to scale well, but I'm not sure if it will exert unwanted pressure in a real system)

+5
source share
5 answers

I will direct you to this post from Raymond Chen:

What is the maximum number of timers that a program can create?

Technically, there is no problem creating thousands of them. Just keep in mind that they use global system resources, so you will end up in the upper limit and / or starve other programs (including Windows themselves) if you go crazy.

, , , .


, , ; -, . , ; , 5 , .

-; . ( ), ( , , ).

, , , .

+11

- - , - . - , , QueryPerormanceCounter QueryPerformanceFrequency. , . , - .

+1

System.Threading.Timer TimerCallback ThreadPool, 1000, , threadpool.

MSDN System.Threating.Timer

TimerCallback, , . , . , ; ThreadPool, .

+1
0

, , , , , .

, , , , , .

0

All Articles