mysql db needs optimizing i think...advice appreciated.

Discussion in 'MySQL' started by jacklaidlaw, Mar 7, 2007.

  1. #1
    When visiting any sites on my server during peak times, they either take ages to load or simply don't load at all. I done a TOP and mysqld sometimes is using like 80% and higher cpu usage. and sometimes the server load is at 15 and higher. Every other day I'm having to optimize tables etc before there is any slight improvement.

    The server is an Intel pentium 4 3.06GHz, with 512mb ram. this is what is in my.cnf

    
    [mysqld]
    set-variable = max_connections=1000
    safe-show-database
    
    Code (markup):
    What should i do to that to make the situation better?
     
    jacklaidlaw, Mar 7, 2007 IP
  2. spachev

    spachev Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    First thing to check - are you using mysql_pconnect() in PHP or some other form of persistent connection? If yes, turn it off. In MySQL the overhead of establishing a connection is very minimal - a couple of milliseconds. But the risk of leaking connections is quite high.
     
    spachev, Mar 8, 2007 IP
  3. jacklaidlaw

    jacklaidlaw Active Member

    Messages:
    298
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    thanks for the tip :)
     
    jacklaidlaw, Mar 9, 2007 IP
  4. Sini

    Sini Peon

    Messages:
    119
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    could you copy paste your whole my.cnf here? It's very hard to say what is the problem without seeing the config. Also, is your cpu usage high?
     
    Sini, Mar 9, 2007 IP
  5. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #5
    hello
    reduce wait_timeout connect_timeout in you my.cnf
     
    Estevan, Mar 9, 2007 IP
  6. Forrest

    Forrest Peon

    Messages:
    500
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Can you get more RAM into your server? Databases like to cache frequently needed data in memory so they don't have to keep pulling it off the disc.
     
    Forrest, Mar 9, 2007 IP
  7. SilkySmooth

    SilkySmooth Well-Known Member

    Messages:
    1,583
    Likes Received:
    269
    Best Answers:
    0
    Trophy Points:
    180
    #7
    Hey,

    Before spending any money on more RAM or changing any of your settings in the configuration, make sure the queries are properly optimized.

    To do this start by checking the slow queries log, if it is not enabled then to enable the slow query log, start mysqld with the --log-slow-queries[=file_name] option.

    Leave it running for a few hours and then check the file to see which queries are causing your server problems.
     
    SilkySmooth, Mar 10, 2007 IP
  8. JenniP

    JenniP Peon

    Messages:
    250
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I dont come from a PHP/MYSQL Background so I cant give you specifics but in the general database world these are pretty good tips

    • Keep your database connection open for the shortest time possible, if PHP has an equlivant of ASP's GetRows() use it where appropriate
    • Only return data that you need, if you only need 3 columns only return 3 columns
    • Select * is normally a bad move, even if your selecting all the columns
    • Avoid using wildcard string searches if you dont need them
    • Check to see your indexing the right things, basically anything you search on frequently should have an index as well as columns used in join conditions
    • While optimizing slowest running queries is good its a good idea to optimize the queries run most, you may get a smaller benefit on each run but it may add up to a bigger saving

    Jen
     
    JenniP, Mar 10, 2007 IP
    SilkySmooth likes this.