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

Backups: Improve behaviour of ajax calls

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.7.1
    • Fix Version/s: 3.7.2
    • Component/s: Backup
    • Labels:
    • Database:
      Any
    • Testing Instructions:
      Hide

      Prerequisite

      1. Use Chrome as your browser.
      2. Log in as an admin.
      3. Visit 'Site Administration' > 'Courses' > 'Backups' > 'Asynchronous backup/restore'.
      4. Check 'Enable asynchronous backups'.
      5. Click 'Save changes'
      6. Visit 'Site administration' > 'Development' > 'Make test course'
      7. Create a small course.
      8. Visit the course homepage.
      9. Click on the Cog in the top-right and select 'Backup'.

      3.7

      1. Open up your developer console and visit the network tab.
      2. Click on the 'Jump to final step' button.
      3. Confirm you are presented with the backup process pending indication and text.
      4. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests.
      5. Click on the 'restore page' link.
      6. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests.

      Master

      1. Edit the file backup/externallib.php and add sleep(5) to the function get_async_backup_progress eg.

        ....
         
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
         
        // Release session lock.
        \core\session\manager::write_close();
         
        sleep(5);
         
        ...
        

      2. Open up your developer console and visit the network tab.
      3. Click on the 'Jump to final step' button.
      4. Confirm you are presented with the the backup process pending indication and text.
      5. Confirm the following calls are made to 'core_backup_get_async_backup_progress' (use the 'Timing' tab when you click on a request).
        1. ~15 seconds after the first request to 'core_fetch_notifications'.
        2. ~22.5 seconds after the previous request.
        3. ~33.75 seconds after the previous request.
        4. ~50.6 seconds after the previous request.
      6. Now, remove the change you made to externallib.php and save the file. Keep checking the network traffic in the open browser. Don't refresh.
      7. Confirm that you see the network requests fall back into a 15 second pattern. I.e. one every 15 seconds or so. The first one might take a minute or so, so be patient.
      8. Now, add the sleep back as per step 1, making sure to save the file.
      9. Click on the 'restore page' link.
      10. Confirm the following calls are made to 'core_backup_get_async_backup_progress' (use the 'Timing' tab when you click on a request).
        1. ~15 seconds after the first request to 'core_fetch_notifications'.
        2. ~22.5 seconds after the previous request.
        3. ~33.75 seconds after the previous request.
        4. ~50.6 seconds after the previous request.
      11. Visit the course home page.
      12. Run php admin/cli/cron.php
      13. Remove the code you added to backup/externallib.php.
      14. Click on the Cog in the top-right and select 'Backup'.
      15. Click on the 'Jump to final step' button.
      16. Confirm you are presented with the backup process pending indication and text.
      17. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests.
      18. Click on the 'restore page' link.
      19. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests.
      Show
      Prerequisite Use Chrome as your browser. Log in as an admin. Visit 'Site Administration' > 'Courses' > 'Backups' > 'Asynchronous backup/restore'. Check 'Enable asynchronous backups'. Click 'Save changes' Visit 'Site administration' > 'Development' > 'Make test course' Create a small course. Visit the course homepage. Click on the Cog in the top-right and select 'Backup'. 3.7 Open up your developer console and visit the network tab. Click on the 'Jump to final step' button. Confirm you are presented with the backup process pending indication and text. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests. Click on the 'restore page' link. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests. Master Edit the file backup/externallib.php and add sleep(5) to the function get_async_backup_progress eg. ....   require_once ( $CFG ->dirroot . '/backup/util/includes/backup_includes.php' ); require_once ( $CFG ->dirroot . '/backup/util/includes/restore_includes.php' );   // Release session lock. \core\session\manager::write_close();   sleep(5);   ... Open up your developer console and visit the network tab. Click on the 'Jump to final step' button. Confirm you are presented with the the backup process pending indication and text. Confirm the following calls are made to 'core_backup_get_async_backup_progress' (use the 'Timing' tab when you click on a request). ~15 seconds after the first request to 'core_fetch_notifications'. ~22.5 seconds after the previous request. ~33.75 seconds after the previous request. ~50.6 seconds after the previous request. Now, remove the change you made to externallib.php and save the file. Keep checking the network traffic in the open browser. Don't refresh. Confirm that you see the network requests fall back into a 15 second pattern. I.e. one every 15 seconds or so. The first one might take a minute or so, so be patient. Now, add the sleep back as per step 1, making sure to save the file. Click on the 'restore page' link. Confirm the following calls are made to 'core_backup_get_async_backup_progress' (use the 'Timing' tab when you click on a request). ~15 seconds after the first request to 'core_fetch_notifications'. ~22.5 seconds after the previous request. ~33.75 seconds after the previous request. ~50.6 seconds after the previous request. Visit the course home page. Run php admin/cli/cron.php Remove the code you added to backup/externallib.php . Click on the Cog in the top-right and select 'Backup'. Click on the 'Jump to final step' button. Confirm you are presented with the backup process pending indication and text. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests. Click on the 'restore page' link. Confirm a call is made to 'core_backup_get_async_backup_progress' every 15 seconds (you can check the 'Response headers' and compare the 'Date' value between requests). You just need to confirm this for a few requests.
    • Affected Branches:
      MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE
    • Pull from Repository:
    • Pull 3.7 Branch:
    • Pull Master Branch:
      MDL-65858_master

      Description

      The asynchronous backup and restore functionality introduced in Moodle 3.7 make several ajax calls to get status updates on the operation progress from the server.

      Currently these calls are every 5 seconds and also hold a session lock. This has led to undesirable behavior when another page holds the session lock.

      When a backup (or restore is in progress) and the user has another tab open that is taking time to generate and also holding the session lock. For example while a backup is in progress the user is also running a report. A condition arises where multiple ajax calls from the backup page are "queued" because the long running report is holding the session lock. When the long running page releases the lock, the queued ajax requests complete.  However, as the ajax requests also have the lock this can block other requests until they clear.

      All in all this is not great for the infrastructure or the user.

      The proposal to make things better is to:

      • Make the ajax calls made for status updates have a short timeout and exponential backup so if the server is not returning results in a timely manner try less often. So not to queue too many requests.
      • Make the ajax calls not hold the session lock

        Attachments

        1. MDL-65858_37.jpg
          MDL-65858_37.jpg
          59 kB
        2. MDL-65858_37 (2).jpg
          MDL-65858_37 (2).jpg
          44 kB
        3. MDL-65858_master.jpg
          MDL-65858_master.jpg
          53 kB
        4. MDL-65858_master (2).jpg
          MDL-65858_master (2).jpg
          75 kB
        5. MDL-65858_master (3).jpg
          MDL-65858_master (3).jpg
          79 kB

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  9/Sep/19

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 5 hours, 44 minutes
                  5h 44m