Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I poll a database every 3 seconds

I am building a system to asynchronously send mails after processing data (it could take up to 10 seconds the processing).

My initial idea was to have a Windows service poll the database with data processing requests every 3 seconds for the first record to be processed. When done, poll and get the new first record to be processed.

When there are no records left wait 3 seconds and poll again to check for records.

I'm not sure if this is a good idea. The use of a timer is not a great way to program in my opinion. Also the performance and the use of the database even when not needed is a concern.

What is the best practice in this case?

Technologies used: .NET 3.5, SQL Server, and servers are in farm.

like image 749
BBQ Avatar asked Oct 07 '22 02:10

BBQ


1 Answers

It all depends on how much overhead you create.

If you can efficiently poll the database (i.e., with a simple query) and if such a polling does not require extensive network traffic (which it usually doesn't), why not poll every 3 seconds?

How did you reach the number 3? Is it arbitrary or is there a reason to check precisely every 3 seconds?

To keep the query simple, you may use 2 queries: one to detect whether there is new data, and another to actually fetch the data. This way you can optimize the one that will occur most often (the first one, obviously).

like image 82
Roy Dictus Avatar answered Oct 10 '22 00:10

Roy Dictus