Forum email notifications fail for large subscriber lists

Bug #716812 reported by Richard Mansfield
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Low
Richard Mansfield

Bug Description

When there are lots of subscribers to a forum or topic, some posts are
not being sent out by email because the cron script runs out of
memory. This has become a problem on mahara.org where most users on
the site are subscribed to the news forum.

The cron script sends email out to some subscribers before failing.
Something in dml, adodb, or the postgres drivers eats memory on every
query, so scripts that perform a lot of queries will hit the php
memory limit eventually, even when the list of subscribers to be
notified fits in memory okay.

As a stopgap I'm going to make the following changes to reduce peak
memory usage a bit:

- When retrieving the list of subscribers, don't pre-generate email
content for the whole subscriber list; instead leave generation until
the point at which a single user is notified.

- Remove each user object from the list as it's notified.

- Make email_user skip the mail disabled query whenever the
maildisabled property is set in the user object. In the
activity_get_users query, pull the maildisabled preference from every
user at the same time we get the list of users.

- Remove an unused artefact_internal_profile_email query from
email_user.

- Only do the mailssent update in email_user when bounces_handle is
configured.

Even if we do all that, and fix the memory leak, we'll soon get to the
stage where the subscriber list won't fit in memory, so we'll need to
change the way it all works, possibly pull subscribers out in chunks
that fit in memory, and push individual notifications for each of them
back on to the activity queue to be handled by a later cron run.

Changed in mahara:
assignee: nobody → Richard Mansfield (richard-mansfield)
Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

Patch to make maildisabled & mailssent queries optional in email_user

Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

Patch to free a bit of memory for long lists of notifications

Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

Patch to delay email content generation closer to the time the email is sent.

Revision history for this message
Ruslan Kabalin (rkabalin) wrote :

>Even if we do all that, and fix the memory leak, we'll soon get to the stage
>where the subscriber list won't fit in memory, so we'll need to change the
>way it all works.

The option could be to limit the number of notifications processed per cron iteration, then on each cron run the ones that have not been notified yet will be notified.

Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

Yeah, exactly, but at the moment the forum post is just a single activity_queue record, which is processed once and notifies all subscribers, so first we need to change the forum post cron job so that it actually just creates more records in activity_queue, either one for each subscriber or maybe one for each conveniently sized chunk of the subscriber list.

Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

Patches above are now applied to master; leaving this open as I still hope to get a chance to tackle the underlying problem before the release.

Changed in mahara:
importance: Medium → Low
Revision history for this message
Richard Mansfield (richard-mansfield) wrote :

Closing this bug and moving the remaining work to https://bugs.launchpad.net/mahara/+bug/778254

Changed in mahara:
status: In Progress → Fix Committed
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.