Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-71731

PHPUnit memory usage almost doubled recently (3.10dev)

XMLWordPrintable

    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_400_STABLE
    • MOODLE_310_STABLE, MOODLE_311_STABLE
    • Hide

      Just ensure that unit tests (ToBiC ones, with the patches applied) are passing, and the total memory (peak) reported by PHPUnit at the end is clearly under 1.8 GB (it should be around "only" 1.0 GB with the patch.

      Not much else to verify.

      Show
      Just ensure that unit tests (ToBiC ones, with the patches applied) are passing , and the total memory (peak) reported by PHPUnit at the end is clearly under 1.8 GB (it should be around "only" 1.0 GB with the patch. Not much else to verify.

      We have started to get some out-of-memory errors in some branches having a good number of unit tests. But it was hard to trace.

      So we tried some "phpunit leak detectors" (a plugin, a listerner...) and, while they reported a good number of tests leaking memory, it was not easy to go checking each:

      https://gist.github.com/stronk7/3632139e3a52d4137a66338c5b005719

      But the final surprise came when it was discovered that 39_STABLE (and earlier) was using "only" ~800 MB to perform complete runs. And MOODLE_310_STABLE (current) and up are the ones requiring ~1800 MB to perform the very same complete runs.

      Initially my thoughts were that, maybe, the upgrade to PHPUnit 8.5 (MDL-67673) could be the culprit, but did run a test before that issue and the memory problem was already there (~1700 MB to run).

      Note that all the runs are with PHPUNIT_LONGTEST set.

      So, at the end, a bisect has been performed between:

      • good: 500c131 - Moodle 3.9.0 release : 886 MB
      • bad: 5903054 - The issue BEFORE PHPUnit 8.5, already wrong: 1700 MB

      And the bisect has ended with:

      0deb19468d0e61c0f3c41fb8d350cd2611fad47e is the first bad commit
      commit 0deb19468d0e61c0f3c41fb8d350cd2611fad47e
      Author: sam marshall <s.marshall@open.ac.uk>
      Date:   Wed May 13 12:11:21 2020 +0100
       
          MDL-68690 Search: Allow Solr to add documents in batches
          
          Adding documents in batches instead of one at a time can make
          indexing using Solr significantly faster.
          
          This adds new API functions for search engines, including
          add_document_batch() to add a batch of documents,
          supports_add_document_batch(), get_batch_max_documents() and
          get_batch_max_content().
       
       search/classes/engine.php                |  97 +++++++++++++++++++--
       search/classes/manager.php               |  36 ++++++--
       search/engine/solr/classes/engine.php    | 100 +++++++++++++++++++++-
       search/engine/solr/tests/engine_test.php | 142 +++++++++++++++++++++++++++++++
       search/upgrade.txt                       |   8 ++
       5 files changed, 367 insertions(+), 16 deletions(-)
      

      To confirm it, I've run PHPUnit tests @ CI:

      So, double confirmation about the issue causing the double memory regression.

      Ciao

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Marina Glancy Marina Glancy
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 35 minutes
                4h 35m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.