Results 1 to 6 of 6

Thread: Persistent, non-persistent or idle-closing MySQL connection?

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    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.

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Persistent, non-persistent or idle-closing MySQL connection?

    Quote Originally Posted by MarMan View Post
    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
    Quote Originally Posted by jmcilhinney View Post
    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.

  5. #5

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width