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

Seemingly unnecessary sleep() in messaging code

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9.9
    • Fix Version/s: 1.9.10
    • Component/s: Messages
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      Hi,

      This line sleeps for 3 seconds for every user you are messaging:

      message/lib.php:1002: sleep(3);

      eg. messaging 200 students = 10 min wait.

      This is a common use case and has problems with load balancers which can be configured to cut off idle connections after a set time.

      From looking through the commit history, there is no clear reason why the sleep was introduced. It also looks like the 2.0 email plugin doesn't have the sleep.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            skodak Petr Skoda added a comment -
            Show
            skodak Petr Skoda added a comment - Introduced by Martin, see: http://cvs.moodle.org/moodle/message/lib.php?r1=1.59&r2=1.60
            Hide
            ashleyholman Ashley Holman added a comment -

            I have committed this to 19_STABLE. The problem is non-existant in HEAD.

            Show
            ashleyholman Ashley Holman added a comment - I have committed this to 19_STABLE. The problem is non-existant in HEAD.
            Hide
            digitalmess Aaron Cowell added a comment -

            Just off the wall, but when you mass email to cell phones, sometimes you need a delay. If a carrier detects more than X amount of messages coming from one address in X amount of time, all messages will be dropped.

            Is it possible to call a background plugin that does the mail processing so the page doesn't timeout and then sends status information to the original sender?

            Show
            digitalmess Aaron Cowell added a comment - Just off the wall, but when you mass email to cell phones, sometimes you need a delay. If a carrier detects more than X amount of messages coming from one address in X amount of time, all messages will be dropped. Is it possible to call a background plugin that does the mail processing so the page doesn't timeout and then sends status information to the original sender?
            Hide
            mudrd8mz David Mudrák added a comment -

            Well IMHO Martin had some reason for this. May I just guess that the delay was there to prevent SMTP server queue floods? I can imagine that some SMTP daemons are not happy when dozens of requests to send a single message come in one moment. Just a comment...

            Show
            mudrd8mz David Mudrák added a comment - Well IMHO Martin had some reason for this. May I just guess that the delay was there to prevent SMTP server queue floods? I can imagine that some SMTP daemons are not happy when dozens of requests to send a single message come in one moment. Just a comment...
            Hide
            ashleyholman Ashley Holman added a comment -

            I guess we will have to check with Martin - I saw it as debugging. Note that the forum digest process can send 10000 messages at once and there's no problem. Also I tested a bulk message to 300 users and it was ok. If the delay is really needed then it should be taken away from the front-end because otherwise the script runs for too long.

            Generally you would have an MTA running on your Moodle server / cluster which relays via your outbound mail server, so if you need to implement throttling you could do it at that level.

            Show
            ashleyholman Ashley Holman added a comment - I guess we will have to check with Martin - I saw it as debugging. Note that the forum digest process can send 10000 messages at once and there's no problem. Also I tested a bulk message to 300 users and it was ok. If the delay is really needed then it should be taken away from the front-end because otherwise the script runs for too long. Generally you would have an MTA running on your Moodle server / cluster which relays via your outbound mail server, so if you need to implement throttling you could do it at that level.
            Hide
            dougiamas Martin Dougiamas added a comment -

            I wish I could help but I can't remember any reason for it.

            Show
            dougiamas Martin Dougiamas added a comment - I wish I could help but I can't remember any reason for it.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  25/Oct/10