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

Improve core_courseformat_get_state performance

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_403_STABLE, MOODLE_404_STABLE
    •  MDL-81610_403_STABLE
    •  MDL-81610_404_STABLE
    •  MDL-81610_main
    • Hide
      • Ensure you have XHProf configured on your server to enable Profiling.
      • Go to Site Administration > Development > Make Test Course and create an M-sized test course.
      • Site Administration > Development > Profiling
        • Check "Enable profiling"
        • Set "Profile these" to "/lib/ajax/service.php"
        • Save changes
      • Load the test course you created. This will trigger a call to core_courseformat_get_state via /lib/ajax/service.php
      • Go to Site Administration > Development > Profiling Runs
      • Select the profile of /lib/ajax/service.php with the most function calls. This should be the profile of core_courseformat_get_state. Make sure to click the link in the "Date" column, not the "URL" column.
      • Follow "View profiling details"
      • Confirm "core_courseformat\external\get_state::execute" exists in the "Function Name" column. If not, you are looking at the wrong profile.
      • Click "display all" at the bottom of the page to list all profiled functions.
      • Find the row with "completion_info::is_tracked_user" in the "Function name" column (Press Ctrl+F and type "is_tracked").
      • Confirm the value in the "Calls" column is 1
        • Before fix: The value is around 300.
      Show
      Ensure you have XHProf configured on your server to enable Profiling . Go to Site Administration > Development > Make Test Course and create an M-sized test course. Site Administration > Development > Profiling Check "Enable profiling" Set "Profile these" to "/lib/ajax/service.php" Save changes Load the test course you created. This will trigger a call to core_courseformat_get_state via /lib/ajax/service.php Go to Site Administration > Development > Profiling Runs Select the profile of /lib/ajax/service.php with the most function calls. This should be the profile of core_courseformat_get_state. Make sure to click the link in the "Date" column, not the "URL" column. Follow "View profiling details" Confirm "core_courseformat\external\get_state::execute" exists in the "Function Name" column. If not, you are looking at the wrong profile. Click "display all" at the bottom of the page to list all profiled functions. Find the row with "completion_info::is_tracked_user" in the "Function name" column (Press Ctrl+F and type "is_tracked"). Confirm the value in the "Calls" column is 1 Before fix : The value is around 300.

      The core_courseformat_get_state web service is slow on large sites, due to core_courseformat\output\local\state\cm::export_for_template() calling is_tracked_user() for every course module on the course. As it is being called for the same user and course, the result will always be the same. The query called within this function only takes around 0.01s, but on a course with several hundred course modules that adds up. This request holds a session lock, so it should be made a fast as possible.

      cm::export_for_template should be rewritten so is_tracked_user() is only called once.

        1. 403 - confirm 1.png
          403 - confirm 1.png
          53 kB
        2. 403 - confirm 2.png
          403 - confirm 2.png
          22 kB
        3. 404 - confirm 1.png
          404 - confirm 1.png
          52 kB
        4. 404 - confirm 2.png
          404 - confirm 2.png
          25 kB
        5. main - confirm 1.png
          main - confirm 1.png
          85 kB
        6. main - confirm 2.png
          main - confirm 2.png
          31 kB
        7. result_1.png
          result_1.png
          171 kB
        8. result_2.png
          result_2.png
          129 kB

            marxjohnson Mark Johnson
            marxjohnson Mark Johnson
            vladaskidanovas vladaskidanovas
            Huong Nguyen Huong Nguyen
            Stevani Andolo Stevani Andolo
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 5 minutes
                1d 5m

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