Moodle
  1. Moodle
  2. MDL-16709

Statistics generation does not run at the right time

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.9.2
    • Fix Version/s: 1.9.3
    • Component/s: Performance
    • Labels:
      None
    • Environment:
      Linux
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE
    • Rank:
      24274

      Description

      I have been fighting performance problems on a fairly large installation which I have narrowed down to the stats generation query "INSERT INTO mdl_stats_daily (stattype, timeend, courseid, roleid, stat1, stat2) SELECT 'enrolments', timeend, courseid, roleid, COUNT(DISTINCT...." that is run by the stats generation routines. According to the admin UI, it should be running at 2AM, but I am finding it running in the early evenings (6-8PM) during out peak usage times and it brings the system grinding to a halt. If I kill the query, performance returns to normal. I don't know yet if it's not honoring the schedule at all and is running everytime the cron job runs, or if it's just offset incorrectly. As I discover more I will update this report.

      For the time being, I've disabled statistics gathering on this system in the hopes that it will stop running and the system will remain usable. We'll see if that is the case tonight.

      A discussion on this has been opened in the forums here: http://moodle.org/mod/forum/post.php?reply=458555

        Activity

        Hide
        Eloy Lafuente (stronk7) added a comment -

        Hi Quentin,

        thanks for the report. We've detected one problem in stats calculation (when gathering old stats results), that can lead to the problem of running and running and running on each cron invocation after the configured time.

        So, we are going to:

        • Prevent executions of stats out of time. They'll be executed only once per day.
        • Add a new setting that allows to specify the number of days to process, when gathering old statistics. Currently that's harcoded to "31" (non-updateable). We are going to default to those "31" but allowing admins to specify a different number of days, depending of how their server is performing.

        Ciao

        Show
        Eloy Lafuente (stronk7) added a comment - Hi Quentin, thanks for the report. We've detected one problem in stats calculation (when gathering old stats results), that can lead to the problem of running and running and running on each cron invocation after the configured time. So, we are going to: Prevent executions of stats out of time. They'll be executed only once per day. Add a new setting that allows to specify the number of days to process, when gathering old statistics. Currently that's harcoded to "31" (non-updateable). We are going to default to those "31" but allowing admins to specify a different number of days, depending of how their server is performing. Ciao
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Proposed wording for current (modified) and new setting:

        statsmaxruntime: Stats processing can be quite intensive, specify maximum time allowed for gathering of one day of statistics. Maximum number of days processed in one cron can be defined below.

        statsruntimedays: Max number of days to process by each execution of statistics (while gathering and calculating old ones). Note that, when stats are up to date, only 1 day will be processed. Adjust this value depending of your server load, reducing it if you need shorter cron executions.

        Please fix it. Going to commit in hours. Ciao

        Show
        Eloy Lafuente (stronk7) added a comment - Proposed wording for current (modified) and new setting: statsmaxruntime: Stats processing can be quite intensive, specify maximum time allowed for gathering of one day of statistics. Maximum number of days processed in one cron can be defined below. statsruntimedays: Max number of days to process by each execution of statistics (while gathering and calculating old ones). Note that, when stats are up to date, only 1 day will be processed. Adjust this value depending of your server load, reducing it if you need shorter cron executions. Please fix it. Going to commit in hours. Ciao
        Hide
        Helen Foster added a comment - - edited

        Hi Eloy,

        Here's my suggested wording:

        statsmaxruntime: Specify the maximum time allowed to calculate the statistics for one day, bearing in mind that stats processing can put a big load on the server. The maximum number of days processed in one cron can be specified below.

        statsruntimedays: Specify the maximum number of days processed in each stats execution. When stats are up-to-date, only one day will be processed, so adjust this value depending of your server load, reducing it if shorter cron executions are needed.

        Show
        Helen Foster added a comment - - edited Hi Eloy, Here's my suggested wording: statsmaxruntime: Specify the maximum time allowed to calculate the statistics for one day, bearing in mind that stats processing can put a big load on the server. The maximum number of days processed in one cron can be specified below. statsruntimedays: Specify the maximum number of days processed in each stats execution. When stats are up-to-date, only one day will be processed, so adjust this value depending of your server load, reducing it if shorter cron executions are needed.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Thanks Helen,

        applying your wording to the strings! B-)

        Show
        Eloy Lafuente (stronk7) added a comment - Thanks Helen, applying your wording to the strings! B-)
        Hide
        Eloy Lafuente (stronk7) added a comment -

        First part of the bug applied to 19_STABLE and HEAD. Now there is a new setting to control the number of days to calculate stats per cron execution.

        Going to commit the fix for "continuous executions" now. Ciao

        Show
        Eloy Lafuente (stronk7) added a comment - First part of the bug applied to 19_STABLE and HEAD. Now there is a new setting to control the number of days to calculate stats per cron execution. Going to commit the fix for "continuous executions" now. Ciao
        Hide
        Eloy Lafuente (stronk7) added a comment -

        And second part applied.

        Improve scheduling of stats. They only will run if:

        • 20 hours have passed since last execution.
        • We are in a 4 hours time window since last scheduled time.

        Should work for 99.99% of sites (running cron in < 4h intervals)

        Resolving as fixed, please test!

        Show
        Eloy Lafuente (stronk7) added a comment - And second part applied. Improve scheduling of stats. They only will run if: 20 hours have passed since last execution. We are in a 4 hours time window since last scheduled time. Should work for 99.99% of sites (running cron in < 4h intervals) Resolving as fixed, please test!
        Hide
        Dongsheng Cai added a comment -

        Closing, thanks

        Show
        Dongsheng Cai added a comment - Closing, thanks

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: