1. Moodle
  2. MDL-18768

Moodle has memory issues with large sites e.g. in role_assign


    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.4
    • Fix Version/s: 1.9.5
    • Component/s: Libraries
    • Labels:
    • Affected Branches:
    • Fixed Branches:


      If you role_assign somebody to the teacher role at site level on a large site (~5k courses, ~110k contexts), this runs out of memory.

      There are three causes:

      1) In forum_role_assign, it does get_records('course'). This should restrict to required fields (only id!) and should be a recordset anyway. Easily changed.

      but more seriously

      2) The get_fast_modinfo data is cached. This cache gradually expands to contain the complete modinfo for all courses.


      3) get_fast_modinfo also causes contexts to be cached. This cache gradually expands to contain all contexts for courses, modules, and blocks (ie virtually the whole context table).

      Petr suggested that the best approach would be to limit the size of these caches, discarding old records. I have implemented this. The changes appear to work (the memory issues go away) on our test system.

      Could somebody review this patch please as it's for 1.9 and is not trivial?

        Gliffy Diagrams

        1. memoryissues.patch
          6 kB
          Sam Marshall
        2. memoryissues2.patch
          6 kB
          Sam Marshall

          Issue Links


            Sam Marshall created issue -
            Sam Marshall made changes -
            Field Original Value New Value
            Attachment memoryissues2.patch [ 16757 ]
            Sam Marshall made changes -
            Status Open [ 1 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Petr Skoda made changes -
            Link This issue has been marked as being related by MDL-19288 [ MDL-19288 ]
            Jens Eremie made changes -
            Link This issue has a non-specific relationship to MDL-19702 [ MDL-19702 ]
            Martin Dougiamas made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            Martin Dougiamas made changes -
            Workflow jira [ 31358 ] MDL Workflow [ 62242 ]
            Martin Dougiamas made changes -
            Workflow MDL Workflow [ 62242 ] MDL Full Workflow [ 91446 ]


              • Votes:
                0 Vote for this issue
                7 Start watching this issue


                • Created: