|
-
Jan 6th, 2011, 04:26 AM
#1
Thread Starter
Frenzied Member
Persistent, non-persistent or idle-closing MySQL connection?
Hi,
I have this application that can produce up to 100 queries per minute, but most of the times is idle.
It seems to me that reopening the connection for each query is rather inefficient, so I'm inclined to use a persistent connection.
But suppose the application would be used on a bigger scale.
Won't the server at a certain point overflow with all the persistent connections?
Would it be an idea to use some sort of idle monitor that detects inactivity and closes the connection?
What would be the best design for such a thing be?
I was thinking the query handler could set a timestamp for the last execution and a timer or a background thread would check whether a certain time passed every few seconds.
Suggestions?
Thanks
Last edited by TheBigB; Apr 5th, 2011 at 03:07 PM.
Delete it. They just clutter threads anyway.
-
Jan 6th, 2011, 08:23 AM
#2
Re: Persistent, non-persistent or idle-closing MySQL connection?
I like the timer idea. After every query you can start the timer. If the timer is already running, just restart it. If the timer runs then whatever time you decided has passed then close the connection.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Jan 6th, 2011, 08:41 AM
#3
Re: Persistent, non-persistent or idle-closing MySQL connection?
ADO.NET uses connection pooling, so what you're suggesting is basically what happens under the covers anyway. An ADO.NET connection object is very lightweight. The actual database connection is handled at a lower level. That is why, when using ADO.NET, you should open a connection as late as possible and close it as early as possible. Only keep a connection open if you have multiple data access operations to perform immediately. Don't worry about what you might have to do in the future.
-
Jan 6th, 2011, 10:45 AM
#4
Thread Starter
Frenzied Member
Re: Persistent, non-persistent or idle-closing MySQL connection?
 Originally Posted by MarMan
I like the timer idea. After every query you can start the timer. If the timer is already running, just restart it. If the timer runs then whatever time you decided has passed then close the connection.
That's actually even simpler than what I had in mind 
 Originally Posted by jmcilhinney
ADO.NET uses connection pooling, so what you're suggesting is basically what happens under the covers anyway. An ADO.NET connection object is very lightweight. The actual database connection is handled at a lower level. That is why, when using ADO.NET, you should open a connection as late as possible and close it as early as possible. Only keep a connection open if you have multiple data access operations to perform immediately. Don't worry about what you might have to do in the future.
Didn't know that. Thanks.
I guess I'll go for the non-persistent then.
Delete it. They just clutter threads anyway.
-
Apr 5th, 2011, 03:12 PM
#5
Thread Starter
Frenzied Member
Re: Persistent, non-persistent or idle-closing MySQL connection?
A completely different application now, working with a SQLite database.
Does that change the situation?
(I'm using the Mono SQLite library here, if it makes any difference)
Delete it. They just clutter threads anyway.
-
Apr 5th, 2011, 06:44 PM
#6
Re: Persistent, non-persistent or idle-closing MySQL connection?
I don't know. Never used SQLite, never used Mono. Connection pooling may or may not be used.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|