Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I was assigned to implement a wrapper class to manage DB connections using ADO in unmanaged C++ and then build an application that works as follow:

"I'll have 3 (or maybe more) instances of the application running as a service, each instance has to check if exists any pending submition in the DB each 2s (a pending submition is a program submition [a solution to a given problem] waiting for evaluation), if exists I get and evaluate it, then I update that submition setting the results and deleting it from the pending table. (the range time to evaluate a submition is: 0s > range < ~(5-10)s and an instance never evaluate more that one submition at the same time)."

My problem is:
I have 2 possibles solutions here:
Stablish a connection once I instanciate the application and never close it (close it when I delete the instance, that theorically never will happen.) or open a connection each 2s in order to get the pending submition (if exists any) and close it, then re-open it to update the submition and close it again....
What solution is better and why?
Posted
Updated 28-Jun-13 16:48pm
v2
Comments
The_Inventor 29-Jun-13 1:29am    
It would depend on available bandwidth and network uptime reliability. Aside from inquiries to either database, your main goal, as stated above, is to write a wrapper to manage DB connections. The best way is to let the 'system' decide. (2s = queues)

And then there is ->http://msdn.microsoft.com/en-us/library/aa231217(v=VS.60).aspx

1 solution

It depends on your real time latencies. I would use one open connection, but you need some fallback for the errorcase.

You should consider bigger intervals and than open and close the connection.

All 2 seconds and 24 hours and that 7 days a week???

Do you AND your user REALLY need such small intervals?
 
Share this answer
 
Comments
mdarefull 1-Jul-13 19:05pm    
Yes, the site is an online-judge so it must remains open 24 hours. Because the users may submit a solution any time of the day, it must check por submitions pending to be evaluated periodically.
KarstenK 3-Jul-13 4:13am    
In such cases should the clients submit the data and i would favour a webservice to listen for data.

Like that but the other direction:

http://www.codeproject.com/Articles/428200/How-to-invoke-a-Web-Service-from-a-Stored-Procedur

And: in client-server architectrue you REALLY SHOULD clode the connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900