Debugging memory_limit problems in version 1.4

Debugging memory_limit problems in version 1.4

by Zbigniew Fiedorowicz -
Number of replies: 10
First of all I am using Moodle version 1.4 (2004083100). The only nonstandard module I have been using is the webwork module, which I have been using since version 1,08 without any problems.

I haven't noticed any problems with Moodle 1.4 with the 16M memory_limit, unless I try to view the site logs. This results in the script hanging in a database call without any error messages, even with debugging turned on.

I've created a minimalistic PHP script which illustrates the problem. You can access it on my site. The URL
https://webwork2.math.ohio-state.edu/moodle/memory.php?mem=16M&rec=2394
works, whereas
https://webwork2.math.ohio-state.edu/moodle/memory.php?mem=16M&rec=2395

fails.

Here is the script:

<?PHP

require_once("./config.php");
global $db;
global $CFG;
@ini_set('memory_limit' , $mem);
error_reporting(999999);
$db->debug = true;
$select = "deleted = 0 AND confirmed = '1'";
$sort = "ORDER BY lastaccess DESC";
$limit = "LIMIT 0,$rec";
$fields = "*";
$sql = "SELECT $fields FROM $CFG->prefix"
        . "user WHERE $select $sort $limit";
$rs = $db->Execute("$sql");
$count = $rs->RecordCount();
//error($count);
$rs->GetAssoc(true);
error("Returned from rs->GetAssoc with $count records");
?>

Average of ratings: -
In reply to Zbigniew Fiedorowicz

Re: Debugging memory_limit problems in version 1.4

by Bernard Boucher -
Hi Zbigniew,
I just tested your script on your site and it fail at 2417mixed

mem1.png

On my small site, about 120 users, it works fine.

I modified the script to check moodle log table instead.
It works fine at more that 12,000 records ( the actual number of records of the table, not an error).

mem2.png
I also try a crazy log display with:

course/log.php?id=1&chooselog=1&user=0&date=0&modid=&modaction=&group=-1&perpage=10000&page=0

and it works fine but not fastwink

I hope these results are significants and helpfull.

Bye,

Bernard


In reply to Zbigniew Fiedorowicz

Re: Debugging memory_limit problems in version 1.4

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hmm ... you are retrieving 2394 user records in their entirety, including descriptions and other big fields, so this is a bit artificial.  I can't think of anywhere that happens in Moodle, even on the log pages.

My site logs are working great on this site with Moodle 1.4, a 16Mb limit and 21795 users ..

Are you able to find the exact point in course/log.php at which the script is hanging on your server?  The mtrace("message") function may be useful, just sprinkle lots of them around ...
In reply to Martin Dougiamas

Re: Debugging memory_limit problems in version 1.4

by Zbigniew Fiedorowicz -
Martin,

My example is not artificial at all.  It is a slightly simplified version of the database call that ensues from calling course/log.php?id=1
You can check this yourself by inserting the following debugging code into course/log.php:
        global $db; //debugging
        $db->debug = true; //debugging
        print_log_selector_form($course);
        $db->debug =false;//debugging
The third DB debugging output line I get is:

(mysql): SELECT * FROM mdl_user WHERE username <> 'guest' AND deleted = 0 AND confirmed = '1' AND id NOT IN (1, 2, 5, 6, 1878, 3605) ORDER BY lastaccess DESC LIMIT 0, 99999

Zig


In reply to Zbigniew Fiedorowicz

Re: Debugging memory_limit problems in version 1.4

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Wha?   OK, I see it now. Thanks, Zig.

It's caused by a bug in some of the last-minute changes Gustav was adding for the site-level user stuff.

In print_log_selector_form you'll see this call:

$courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname");

which is only supposed to get those three fields. If you follow the calls down, though, this parameter now gets completely ignored ...

I'll fix this immediately in STABLE and release a 1.4.1 very soon.

Next I'll have to work out why moodle.org wasn't bugging out on this. mixed
In reply to Martin Dougiamas

Re: Debugging memory_limit problems in version 1.4

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
This is now in MOODLE_14_STABLE and DEV ... seems to be working OK for me. Please test!  tongueout
In reply to Martin Dougiamas

Re: Debugging memory_limit problems in version 1.4

by Zbigniew Fiedorowicz -
I can confirm that my site logs now work with memory_limit = 16M.
In reply to Martin Dougiamas

Re: Debugging memory_limit problems in version 1.4

by Sushil Bajpai -

I was reading the release notes pertaining to php accelerator http://www.php-accelerator.co.uk/releases/1.3.3/release_notes

and there is mention of a bug in PHP memory handling

"A bug in PHP memory handling causes PHP builds with --enable-memory-limit to believe that memory is already allocated at the start of each request, and for the amount to increase at each request.

The bug exists in PHP 4.2.1, 4.2.2, and probably some or all other releases.

Release 1.3.3 incorporates an experimental workaround for this PHP bug and
can be enabled with by setting the php.ini entry
enable_php_memory_bug_workaround = 1"

Further in http://www.php-accelerator.co.uk/releases/1.3.3/CONFIGURATION

they write

"; Enable a workaround for a bug in PHP that can cause PHP to incorrectly
; report that a script has run out of memory. Defaults to 0, i.e. disabled.
; Set to on or 1 to enable.
; NOTE: This is only relevant is PHP was built with --enable-memory-limit

phpa.enable_php_memory_bug_workaround = 0"

Could this be the reason that some sites are/were having problems and others like those on moodle.com not?

In reply to Zbigniew Fiedorowicz

Re: Debugging memory_limit problems in version 1.4

by Herbert Keijers -

Hi Zbigniew,

If your php version => 4.3.2 , could you implement :

echo memory_get_usage() . "\n";

in your script ?