I have gotten rid of most of the select queries on the payout table actually, almost all queries hitting that table are simple inserts or updates ("insert into payouts(websiteId, address, amount, datetime, paid, isRef ...."). Strangely enough alot of these insert/updates are showing up in the slow query log...
Im really at a loss as to whats causing this. And apparantly upgrading your linode gives you no extra processing power, just higher priority and more ram. Tried upgrading to the next level and increasing my cache, and even lowered my max connections. still same problem, easily getting up to 700+ %
Tried dropping all indexes and foreign keys, running 'optimize table' on all tables, adding all the keys back in and then running mysqlcheck -A (I saw this suggested somewhere). That seemed to actually work somewhat... for like less than a day. Now back to the same problem.
Also tried doing a database dump, dropping the database and then completely reinstalling MySQL (made sure its version 5.5) and then loading up the DB again. still nothing.
The only other thing I can think of doing really is just exporting all the rows into JSON files or something, dropping the database, rebuilding it from scratch and then create a script to add all the rows back in. Im not even sure if that will work though... About a month ago I basically did just that, created a new version of the database, exported everything from the old version and re-imported it (I had this same CPU problem with the old database).
Here are some example queries that are showing up in my slow log now (for a little bit I seemed to have very few but now several are showing up again, and from other tables)
Code:
INSERT INTO payouts(websiteId, address, amount, datetime, paid, isRef) VALUES('649', '<address withheld>', '3.0E-8', '2014-01-30 07:36:16', '0', '1');
Query time: 24 seconds
SET timestamp=1391092096;
Query time: 10 seconds (?????)
SELECT count(*) FROM website_visits WHERE websiteId = '457'
AND (IP = '<IP withheld>' OR address = '<address withheld>')
AND valid = 1
AND `datetime` > "2014-01-29 06:27:42";
query time: 23 seconds
That website visits table is another one besides payouts that I have had issues with, seemed to not cause any issues for a while until again just recently though. Here is the create table for it:
Code:
CREATE TABLE `website_visits` (
`visitId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`websiteId` int(11) unsigned NOT NULL,
`IP` varchar(40) DEFAULT NULL,
`valid` int(2) DEFAULT '0',
`skip` int(2) DEFAULT '0',
`datetime` datetime DEFAULT NULL,
`endtime` datetime DEFAULT NULL,
`address` varchar(40) DEFAULT NULL,
PRIMARY KEY (`visitId`),
KEY `websiteId` (`websiteId`),
KEY `address` (`address`),
KEY `IP` (`IP`)
) ENGINE=InnoDB AUTO_INCREMENT=261590 DEFAULT CHARSET=latin1
Any ideas?? Would having the database on its own dedicated linode (its shared with apache right now) work better maybe? There has to be something messed up or something im doing wrong here...
also, there have been a few times where MySQL has just crashed and then wont start up again (job start failed). Only way I have been able to get it back up when that happens is adding innodb_force_recover = 1, which lets it start up, then when I turn that off again and restart it appears to work fine. Could have something to do with it?
thanks