Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread increases processor usage gradually

I have a .NET thread which is allocated to core #7. The thread function is triggered once in 300ms. Initially it takes around 20-30 ms to execute one call. But this time increases gradually and becomes more than 150ms after some 2,52,000 calls.

Also I have noticed usage of core #7 starts at 10%. By the time the number of calls to the thread function reaches 2,52,000 processor usage of core #7 becomes around 60%. When I stop triggering the thread function, processor usage becomes 0%. But when I start triggering again core usage starts from 60% (not from 0%) and again gradually increases.

I have also noticed there is no memory leak for the application.

Inside my thread function I am combining the elements of two Dictionaries and adding it to another dictionary in a foreach loop. Number of elements in the dictionary will be always 45.

I want this application to be running 24/7. Please let me know some tips to make this processor usage constant.

like image 902
Amruth Raj.V Avatar asked Oct 07 '22 00:10

Amruth Raj.V


1 Answers

When you add an item to a Dictionary the capacity may have to be increased. Does your dictionary continue to grow forever?

From MSDN:

If Count is less than the capacity, this method approaches an O(1) operation. If the capacity must be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

like image 114
Jonathon Reinhart Avatar answered Oct 10 '22 02:10

Jonathon Reinhart