Thread: SQL Connections

Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1 SQL Connections 
    Banned
    Join Date
    Apr 2012
    Posts
    479
    Thanks given
    36
    Thanks received
    72
    Rep Power
    0
    In your opinion, which is better

    Keeping SQL connections alive 24/7, checking every 10 seconds to ensure connection is alive. Reconnect if not.

    or....

    Create a new connection every time, execute the sql, close the connection.
     

  2. #2  
    Registered Member

    Join Date
    Dec 2011
    Posts
    1,622
    Thanks given
    1,984
    Thanks received
    830
    Rep Power
    1049
    Not having much knowledge of this, I may be quite wrong.

    But it would be less stressing to the SQL server if connections were only made when required.. would it not?
     

  3. #3  
    Banned
    Join Date
    Apr 2012
    Posts
    479
    Thanks given
    36
    Thanks received
    72
    Rep Power
    0
    Quote Originally Posted by Austin P View Post
    Not having much knowledge of this, I may be quite wrong.

    But it would be less stressing to the SQL server if connections were only made when required.. would it not?
    well in my eyes i think the everlasting connection seems like a better idea, let's say you have donations/voting/highscores all sql checking constantly. random number maybe like 500 connections an hour....
    i feel as if making 500 connections an hour would be a great idea but keeping the connection open is probably worse
    hence why i'm curious of peoples views on this matter
     

  4. #4  
    Renown Programmer


    Join Date
    Dec 2006
    Posts
    1,716
    Thanks given
    268
    Thanks received
    217
    Rep Power
    1836
    just connect, do what you need and then disconnect. no point in leaving a connection open. also, do things like highscores upon log out.
     

  5. #5  
    arrowzftw
    Guest
    Quote Originally Posted by SGPK View Post
    In your opinion, which is better

    Keeping SQL connections alive 24/7, checking every 10 seconds to ensure connection is alive. Reconnect if not.

    or....

    Create a new connection every time, execute the sql, close the connection.
    Yeh you should keep one connection open and not use this destroy connection crap. You don't need to check it you can just make a getter like getConnection() and in that method you can add the check to see if its closed. So it'll check every-time you get the connection.

    Imo if you have a lot of players you shouldn't be creating a new connection everytime like the post above me says you should be re-using the current connection.

    They give benefits and examples of re-using the connection.
    [Only registered and activated users can see links. ]


    Quote Originally Posted by Shiver View Post
    just connect, do what you need and then disconnect. no point in leaving a connection open. also, do things like highscores upon log out.
    Dont comment if your comment is based on complete shit you saw in a PI source.
     

  6. Thankful user:


  7. #6  
    Registered Member

    Join Date
    Dec 2011
    Posts
    1,622
    Thanks given
    1,984
    Thanks received
    830
    Rep Power
    1049
    Quote Originally Posted by SGPK View Post
    well in my eyes i think the everlasting connection seems like a better idea, let's say you have donations/voting/highscores all sql checking constantly. random number maybe like 500 connections an hour....
    i feel as if making 500 connections an hour would be a great idea but keeping the connection open is probably worse
    hence why i'm curious of peoples views on this matter
    What about having the game just check every now and then, say like every two minutes. Just check for any updates, changes, or queries, and then if there's a donation reward, voting reward, or highscore change that needs to be done, it's done.

    If the player deserving the donation reward is online, it sends it to them, (granted their inventory space allows it, otherwise just a notification message telling them to prepare for the item(s) in two or so minutes)

    Much the same for voting rewards. It could be done using the same stradegy as global server messages that are often seen, or even done per account preferance, based on whatever time set the user so chooses, some users like their highscores to be updated immediate, whereas others may not care.
     

  8. #7  
    Programmer, Contributor, RM and Veteran




    Join Date
    Mar 2007
    Posts
    5,074
    Thanks given
    2,625
    Thanks received
    3,578
    Discord
    View profile
    Rep Power
    5000
    Keep the connection open. If your server ever scales beyond a handful of players, closing it and opening it for each query or transaction would lead to really bad performance. On Emps we typically have between 100-500 queries per second depending on the time of day, and we've needed to tune things carefully to be able to handle this:

    - keeping a pool of connections open
    - using the InnoDB table engine (which uses row locking so allows more concurrency than MyISAM)
    - make InnoDB only commit once per second instead of once per transaction
    - tweaking the file system settings to commit the journal every 60 seconds (the above two would be bad if you were a bank or something important, but for a private server losing up to 60 seconds of data in a power loss/crash isn't important)
    - configured MySQL to have a larger InnoDB buffer pool, log file and log buffer - as well as various other settings I can't remember now

    Btw I think an idle connection to MySQL won't harm anything. Sure, it'll consume a bit of memory in MySQL and your server (this is probably better than allocating and deallocating that all the time though, this would happen if you kept opening/closing it) - but it'll probably have a thread in MySQL that is sitting there blocking, so won't be consuming any CPU power. So I don't see any reason for not keeping the connections open.
    .
     


  9. #8  
    Banned
    Join Date
    Apr 2012
    Posts
    479
    Thanks given
    36
    Thanks received
    72
    Rep Power
    0
    Quote Originally Posted by Graham View Post
    Keep the connection open. If your server ever scales beyond a handful of players, closing it and opening it for each query or transaction would lead to really bad performance. On Emps we typically have between 100-500 queries per second depending on the time of day, and we've needed to tune things carefully to be able to handle this:

    - keeping a pool of connections open
    - using the InnoDB table engine (which uses row locking so allows more concurrency than MyISAM)
    - make InnoDB only commit once per second instead of once per transaction
    - tweaking the file system settings to commit the journal every 60 seconds (the above two would be bad if you were a bank or something important, but for a private server losing up to 60 seconds of data in a power loss/crash isn't important)
    - configured MySQL to have a larger InnoDB buffer pool, log file and log buffer - as well as various other settings I can't remember now

    Btw I think an idle connection to MySQL won't harm anything. Sure, it'll consume a bit of memory in MySQL and your server (this is probably better than allocating and deallocating that all the time though, this would happen if you kept opening/closing it) - but it'll probably have a thread in MySQL that is sitting there blocking, so won't be consuming any CPU power. So I don't see any reason for not keeping the connections open.

    oh how i'd really love to see your sql classes :L

    but on topic, as for keeping the connection, a connection usually closes after 15 seconds doesn't it? you'd have to keep opening it back up every 15 seconds. and not entirely sure about pooling but i'm assuming several connections to the same database?
    and one last thing i'm concerned about, you said sending all the queries once per second or once per 60 seconds?
     

  10. #9  
    Programmer, Contributor, RM and Veteran




    Join Date
    Mar 2007
    Posts
    5,074
    Thanks given
    2,625
    Thanks received
    3,578
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by SGPK View Post
    oh how i'd really love to see your sql classes :L

    but on topic, as for keeping the connection, a connection usually closes after 15 seconds doesn't it? you'd have to keep opening it back up every 15 seconds. and not entirely sure about pooling but i'm assuming several connections to the same database?
    and one last thing i'm concerned about, you said sending all the queries once per second or once per 60 seconds?
    MySQL can be configured to have longer timeouts.

    The queries are executed as required, it's the file system that commits every 60 seconds.
    .
     

  11. #10  
    Banned
    Join Date
    Apr 2012
    Posts
    479
    Thanks given
    36
    Thanks received
    72
    Rep Power
    0
    Quote Originally Posted by Graham View Post
    MySQL can be configured to have longer timeouts.

    The queries are executed as required, it's the file system that commits every 60 seconds.
    so a majority of performance configurations are done through website settings
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 3
    Last Post: 09-11-2012, 04:07 PM
  2. Replies: 12
    Last Post: 10-17-2009, 06:52 PM
  3. SQL - The massive guide to SQL
    By Martin in forum Tutorials
    Replies: 10
    Last Post: 01-31-2009, 12:37 AM
  4. [SQL]Adding World Objects[/SQL]
    By Harvey in forum Tutorials
    Replies: 7
    Last Post: 02-16-2008, 04:55 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •