Hello,
I made a previous post about a query that runs a couple of times every hour dealing with 'siteidentifier' slowing down the mySQL server rendering all moodle installs unable to communicate with the DB. This brings down all of our sites.
We have 130+ websites that communicate with a very large mySQL database (32 cores, 128 gigs ram, 5TB storage), and our DB settings are perfect for a server of that size. It should not have any issues with handling any set of queries that are being thrown at it and most of the time things are great.
However, after investigating quite a bit I noticed a 3 or 4 stage set of queries dealing with mdl_sessions. First is a request for a user lock that looks like this:
<pid> <dbusername> <connection source ip> <dbname> Query <time elapsed> User lock SELECT GET_LOCK('<dbname>-mdl_-session-68804', 120)
Then it will do this:
<pid> <dbusername> <connection source ip> <dbname> Query <time elapsed> Opening Tables SELECT id FROM mdl_sessions WHERE sid = '<sid>';
Then this:
<pid> <dbusername> <connection source ip> <dbname> Query <time elapsed> query end UPDATE mdl_sessions SET state = '0',sid = '<sid>',userid = '<uid>',timecreated = '1412669850',timemodified = '1412674008',firstip = '<user ip>',lastip = '<user ip>',sessdata = '' WHERE id='<session id pulled from previous query>'
BTW, the "sessdata" this query can be like 1000-2000 lines, which is massive and I'm unsure if this is actually necessary.
Anyway, these queries will take about 5 minutes to perform, where the database is flooded with these requests (hundreds of them) and then the database becomes unresponsive. These are all very slow queries.
Things I've done to fix:
- reschedule crons to give reasonable time for completion and no overlap and ensure cronlocks are being used
- move intensive crons/queries to run during night instead of during business hours
- moved sessions handling from DB to moodledata (I thought this would help but it didn't, and it still talks to the DB for the rest of the session data even though it's no longer doing the "USER LOCK" request)
- Confirmed that the database settings are ok.
Even after all this, it's still coming down from 02-07 after the hour and 27-32 after the hour.
Any help would be appreciated. This is a beast of a problem.