Affects Version/s: 2.5.1
1. Go to /my page, having logged in as the user who enrolled in more than 80 courses.
2. Make sure there are no errors on the page.
3. Reverse patch for
MDL-34785and do the same (those two issues address different problems but both affect /my/ page)Show1. Go to /my page, having logged in as the user who enrolled in more than 80 courses. 2. Make sure there are no errors on the page. 3. Reverse patch for MDL-34785 and do the same (those two issues address different problems but both affect /my/ page)
Fixed Branches:MOODLE_24_STABLE, MOODLE_25_STABLE
Pull from Repository:
Pull Master Branch:
Pull Master Diff URL:
Some users reported 502 error on attempt to open /my page in Moodle. Apache error log only indicated:
which was not useful enough. Seems like apache process just dies without reporting anything else in the log. The closer look indicated that problem appear with users who is enrolled to too many courses (above 80 in our case).
The next logical step was to make Apache produce a core dump for analysis of the problem. As it was impossible to replicated issue on our test system, for this purpose we removed of the frontends from the live pool used it for testing. After spending some time playing with gdb and learning how it works, I moved further in analysis and got backtrace of events from the memory dump:
The top line gave a clue what causes the problem:
This has been introduced in
MDL-25191 and had a good reason for being there, as we know that unsetting static variables in PHP is not trivial. They sort of remain set in the memory, just a reference being removed.
The first thought, what Andrew suggested was to introduce gc_collect_cycles(); before doing unsets. This solved the problem resulting in script execution for particular user lasts 53 seconds:
The second approach I tried was to remove what has been added in
MDL-25191, leaving just single unset (unset($cache[$key]). Surprisingly, this worked as well taking less time:
This seems like a problem related to particular system and Moodle configuration, which is difficult to replicate. We realised that if we reduce MAX_MODINFO_CACHE_SIZE (we had it set to 62) the problem also disappears. Having looked further into unsetting static variable, I found a solution that does both - killing the variable in memory and not causing problems in our installation:
The performance remain the same as in the previous case where
MDL-25191 changes are reverted. I suggest to implement it, though, given that problem is weird and not applicable to everyone, I am not 100% sure we need to change existing code.
Comments are welcome.