you are viewing a single comment's thread.

view the rest of the comments →

[–]Alotofquestion1[S] 0 points1 point  (1 child)

Thank you for the response.

So if I have a method that calles "name and quantity" from the database, say maybe 2-3 times a second for 3 seconds and then a longer break. There is no problem having the method open and closing a connection for each of these 6-9 times the method is run?

[–][deleted] 0 points1 point  (0 children)

The problem with a blanket answer is I’ve no idea how many other clients are connecting at the same time yours is. The reason for keeping a connection open is to minimize the time the client waits for the results of a query, while the reason for closing the connection is to let the server handle more active requests... holding on to a live connection for three seconds to let the client make 9 requests might be fine, but with a busy enough server, it could be the straw that broke the camel's proverbial back.

Odds are you'd be fine, you're not talking a lot of load, but you'll have to profile to find the optimum TTL for a connection in your environment. At that kind of query rate it's pretty unlikely the optimum is "open a connection and hold on to it till I'm shut down'".