Mysqld 100% CPU - HELP

Discussion in 'Databases' started by udikantz, Sep 30, 2010.

  1. #1
    Hello everyone i have a high CPU problem with MYSQL using "top" ( linux ) shows cpu peaks of 90%.

    I was trying to find the source of the problem, turned on general log and slow query log, The slow query log did not find anything.

    The Db contains a few small tables and one large table that contains almost 100k rows, Database Engine is MyIsam. strange thing i have noticed that on the large table, select, insert are very fast but update takes 0.2 - 0.5 secs.

    already used optimize and repair and no improvement.

    this is the table structure:

    CREATE TABLE IF NOT EXISTS `customers` (
      `CustFullName` varchar(45) NOT NULL,
      `CustPassword` varchar(45) NOT NULL,
      `CustEmail` varchar(128) NOT NULL,
      `SocialNetworkId` tinyint(4) NOT NULL,
      `CustUID` varchar(64) character set ascii NOT NULL,
      `CustMoney` bigint(20) NOT NULL default '0',
      `LastIpAddress` varchar(45) character set ascii NOT NULL,
      `LastLoginTime` datetime NOT NULL default '1900-10-10 10:10:10',
      `SmallPicURL` varchar(120) character set ascii default '',
      `LargePicURL` varchar(120) character set ascii default '',
      `LuckyChips` int(10) unsigned NOT NULL default '0',
      `AccountCreationTime` datetime NOT NULL default '2009-11-11 11:11:11',
      `AccountStatus` tinyint(4) NOT NULL default '1',
      `CustLevel` int(11) NOT NULL default '0',
      `City` varchar(32) NOT NULL default '',
      `State` varchar(32) NOT NULL default '0',
      `Country` varchar(32) NOT NULL default '',
      `Zip` varchar(16) character set ascii NOT NULL,
      `CustExp` bigint(20) NOT NULL default '0',
      PRIMARY KEY  (`CustUID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    Code (markup):
    Any update statement on that table based on the table's key is slow. for
    example:


    UPDATE customers SET CustMoney = 1 WHERE CustUID = 'someid'
    Code (markup):
    Again im not sure that this is the cause for the high CPU Usage but it seems to me that its not normal for an update statement to take that long. ( 0.5 sec)

    The table is being updated up to 3 times in a sec at the moment and in the future it will update even more frequently.

    What can i do to improve this?
     
    udikantz, Sep 30, 2010 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    If you are having concurrent select / update queries running on a table, best engine to use is InnoDB for such tables.

    MyISAM engine acquires table level lock when update query is executed.
    InnoDB engine acquires row level lock when update query is executed.

    This is just one aspect to the proposed solution. There could be other enhancements as well.
     
    mastermunj, Sep 30, 2010 IP
  3. udikantz

    udikantz Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes i do have many select / update / insert on this table. do you think that this is the main cause for the high cpu?

    is there an easy way to change the engine to innoDB?
     
    udikantz, Sep 30, 2010 IP