Moodle

Patch for DB overload with sessiondb

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9.5
  • Fix Version/s: None
  • Labels:
    None
  • Environment:
    SessionDB = On
  • Database:
    Any, MySQL
  • Affected Branches:
    MOODLE_19_STABLE

Description

Our server (100-200 online users) was been block with expiry-update requests in mdl_session2.
When we used MyISAM tables were locked, when we used InoDB requests worket too long.

When session DB switches on, database is overloaded with queries for expiry time update.
Every http request needs 'expiry' update and it needs db indexes update. If there are thousands records in mdl_session2, the indexes update take a long time.
If page includes some pictures etc the one page needs 30-50 http-requests and 30-50 expiry updates every time.
But it isn't necessary - there aren't any sense in every seconds expiry updates.

This is patch for lib/adodb/session/adodb-session2.php (method write()):

$timeNoUpdate = $conn->OffsetDate($lifetime/(24*3600)-60,$sysTimeStamp);
$sql = "UPDATE $table SET expiry = $expiry ,expireref=".$conn->Param('0').", modified = $sysTimeStamp WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= $sysTimeStamp AND expity < $timeNoUpdate";

It's adding "AND expity < $timeNoUpdate".

Activity

Hide
Petr Škoda (skodak) added a comment -

I have added not to the new session code in 2.0, thanks for the report

Show
Petr Škoda (skodak) added a comment - I have added not to the new session code in 2.0, thanks for the report
Hide
Alex Djachenko added a comment -

Hi!
Could you apply this simple, ready to apply, but very useful for big sites patch to 1.9.x?
It takes only 5 minutes from you...

We have to apply it to every install or upgrade, becouse it doesn't work without (dozens of
"UPDATE mdl_sessions2 SET expiry = NOW( ) + INTERVAL 10800 SECOND ,
expireref = '',
modified = NOW( ) WHERE sesskey = 'zzz' AND expiry >= NOW( ) "
in the database)

2.0 isn't ready to use in production sites (before end of 2011) and 1.9.x will live a long time.

Show
Alex Djachenko added a comment - Hi! Could you apply this simple, ready to apply, but very useful for big sites patch to 1.9.x? It takes only 5 minutes from you... We have to apply it to every install or upgrade, becouse it doesn't work without (dozens of "UPDATE mdl_sessions2 SET expiry = NOW( ) + INTERVAL 10800 SECOND , expireref = '', modified = NOW( ) WHERE sesskey = 'zzz' AND expiry >= NOW( ) " in the database) 2.0 isn't ready to use in production sites (before end of 2011) and 1.9.x will live a long time.
Hide
Gilles-Philippe Leblanc added a comment -

Does this problem also exists in Moodle 2.x.x?

Show
Gilles-Philippe Leblanc added a comment - Does this problem also exists in Moodle 2.x.x?

Dates

  • Created:
    Updated: