I have a .NET Windows Service that has a timer with interval set to 10 seconds. Every 10 seconds, it queries the database for any work to be done, picks up top 3 work items and processes them. The time taken to process each work item would depend on the user. It might range from a few seconds to several minutes.
I feel that 10 seconds is too short. I picked a low interval as the user is waiting for the process to be completed (they see a progress bar in the front end) and the faster the service picks up the work, the better. Also, the # of work items (three) was picked in random.
I do have “lock(this)” in my code to prevent one thread from stepping over the other. Is a short duration of 10 seconds okay in production environments?
EDIT: Also, does it make sense that I am picking only 3 items every time to be processed.
…Also, does it make sense that I am picking only 3 items every time to be processed…
Having a hard number of items to pick up could be dangerous. You have the potential to have items enter the queue faster than they can be processed. Consider what would happen if more than three items get enqueued every ten seconds. You would begin to see that it takes longer and longer for an item to get processed.
Either spawning additional threads or using an event-driven approach might be better.