Moodle
  1. Moodle
  2. MDL-23755

Seemingly unnecessary sleep() in messaging code

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor 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
    • Rank:
      36079

      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.

        Activity

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

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

        Show
        Ashley Holman added a comment - I have committed this to 19_STABLE. The problem is non-existant in HEAD.
        Hide
        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
        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
        David Mudrak 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
        David Mudrak 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
        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
        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
        Martin Dougiamas added a comment -

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

        Show
        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: