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

Improve processing of scheduled and adhoc tasks

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Unzip the attached zipfile
      2. Purge caches
      3. Login as admin
      4. Navigate to Site administration -> Server -> Tasks -> Task processing
        1. Set "Scheduled task concurrency limit" to 1
        2. Set "Scheduled task runner lifetime" to 10 minutes
        3. Set "Adhoc task concurrency limit" to 10
        4. Set "Adhoc task runner lifetime" to 10 minutes
      5. Open 4 new consoles and run the following in each of them – preferably do so at the same time, or as close to one another as possible:

        php admin/cli/cron.php
        

        1. Confirm that only one of these actually ran scheduled tasks
        2. Confirm that the other three reported that they skipped the scheduled tasks because of the concurrency limit
      6. Wait 1 minute
      7. Navigate to Site administration -> Server -> Tasks -> Task processing
        1. Set "Scheduled task concurrency limit" to 2
      8. Open those consoles again. and run the comand in all of them again (at the same time if possible):

        php admin/cli/cron.php
        

        1. Confirm that two of these actually ran scheduled tasks this time
        2. Confirm that the other two reported that they skipped the scheduled tasks because of the concurrency limit

          # Wait 1 minute
          # Open those consoles again. and run this slightly different comand in all of them (at the same time if possible):
          while true; do php admin/cli/cron.php; sleep 30; done
          

      9. Open a console and run the test script:

        php test_64347.php
        

      10. Refer to the four cron runners:
        1. Confirm that each of the four cron runs (eventually) process the adhoc task and start printing dots
        2. Confirm that they all keep running until a total of 10 have been run
        3. Don't close the windows - leave them running for now
      11. Navigate to Site administration -> Server -> Tasks -> Task processing
        1. Set the max concurrent to 2
        2. Set the lifetime to 30 seconds
      12. Re-queue the adhoc tasks using the test script again:

        php test_64347.php --count=4
        

      13. View the consoles
        1. Confirm that only two of the console windows run the task
        2. Confirm that the other two state:

          Skipping processing of adhoc tasks. Concurrency limit reached.
          

        3. Confirm that the two consoles which were running tasks only run the task once and that once they have finished processing the task they show:

          Stopping processing of adhoc tasks as time limit has been reached.
          

          Note: 4 tasks were queued - the remaining 2 may happen in any of the four consoles.

      Show
      Unzip the attached zipfile Purge caches Login as admin Navigate to Site administration -> Server -> Tasks -> Task processing Set "Scheduled task concurrency limit" to 1 Set "Scheduled task runner lifetime" to 10 minutes Set "Adhoc task concurrency limit" to 10 Set "Adhoc task runner lifetime" to 10 minutes Open 4 new consoles and run the following in each of them – preferably do so at the same time, or as close to one another as possible: php admin/cli/cron.php Confirm that only one of these actually ran scheduled tasks Confirm that the other three reported that they skipped the scheduled tasks because of the concurrency limit Wait 1 minute Navigate to Site administration -> Server -> Tasks -> Task processing Set "Scheduled task concurrency limit" to 2 Open those consoles again. and run the comand in all of them again (at the same time if possible): php admin/cli/cron.php Confirm that two of these actually ran scheduled tasks this time Confirm that the other two reported that they skipped the scheduled tasks because of the concurrency limit # Wait 1 minute # Open those consoles again. and run this slightly different comand in all of them (at the same time if possible): while true; do php admin/cli/cron.php; sleep 30; done Open a console and run the test script: php test_64347.php Refer to the four cron runners: Confirm that each of the four cron runs (eventually) process the adhoc task and start printing dots Confirm that they all keep running until a total of 10 have been run Don't close the windows - leave them running for now Navigate to Site administration -> Server -> Tasks -> Task processing Set the max concurrent to 2 Set the lifetime to 30 seconds Re-queue the adhoc tasks using the test script again: php test_64347.php --count=4 View the consoles Confirm that only two of the console windows run the task Confirm that the other two state: Skipping processing of adhoc tasks. Concurrency limit reached. Confirm that the two consoles which were running tasks only run the task once and that once they have finished processing the task they show: Stopping processing of adhoc tasks as time limit has been reached. Note: 4 tasks were queued - the remaining 2 may happen in any of the four consoles.
    • Affected Branches:
      MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE
    • Pull Master Branch:
      MDL-64347-master

      Description

      There are a couple of areas which are proving problematic when dealing with large numbers of adhoc tasks.

      Firstly there is nothing to stop lots of cron runs all running adhoc tasks and thereby blocking processing of non-adhoc tasks. This also typically overloads the box.

      Secondly there is not limit to the number of adhoc tasks performed at any one time. If a box it configured to only allow 1 (or some other limit) cron runner at a time, this will also prevent regular tasks from running.

      I'd suggest we improve the case for both of these by:

      1. adding a new config setting for max parallel adhoc tasks (default of 2 or 3)
      2. adding a limit so that, at most, only X adhoc tasks, or Y seconds of adhoc tasks are performed at once. Once complete the task will exit, and thus allow a new runner to start.

        Attachments

        1. 2vs2.png
          2vs2.png
          348 kB
        2. 64347.zip
          2 kB
        3. image-2019-01-17-14-59-53-962.png
          image-2019-01-17-14-59-53-962.png
          236 kB
        4. image-2019-01-17-15-04-42-504.png
          image-2019-01-17-15-04-42-504.png
          284 kB
        5. image-2019-01-17-15-55-26-973.png
          image-2019-01-17-15-55-26-973.png
          268 kB

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  20/May/19