Notice

The forum is in read only mode.

Support Forum

Welcome! Support Forums have been reactivated
Welcome the Technical Support section. Help us in assisting you by providing us with a concise and descriptive elaboration of your issues. Be specific and if possible, provide us with a step-by-step instruction in replicating your problem.

sending emails with cron - incorrect status in queue on large sites / purge

9 years 2 months ago
Licenses:
JomSocial Active iSEO Expired Socialize Expired

I discovered a similar issue as described in this post, but think I figured out why behind the scenes http://www.jomsocial.com/forum/technical-issues/23385-purging-the-mail-queue

The problem started when the queue gets large (over 10,000 records) and hasn’t been purged. In theory, a similar issue could also happen if your ‘totalemailpercron’ is set to be to high in your default.ini settings. The frustrating part about this issue is that you may never realize there is a problem as the email queue in backend reports everything as OK; when in reality your messages may not have been sent.

I can’t give you guys an easy way to replicate this because I have since purged my queue, and in addition the only way I knew there was a problem was when I didn’t get an email in my inbox. As mentioned, the queue said things were fine; and I don’t want too accidently send my users a million test messages debugging this

So since I can’t really show you the problem on my site (because of what I describe above) but I can show you the problem in the code. Are you guys hiring lol? I have now discovered and provided fixes to a few bugs at my own expense here ☺

When examining the cron task, there is function that called _sendEmails which does what it sounds like. This file calls a send function located here:
/components/com_community/libraries/mailq.php
The send function is located on line 19, and the problematic function call is located on line 23:

    public function send($total = 100) {
        $app         = JFactory::getApplication();
        $mailqModel  = CFactory::getModel('mailq');
        $userModel   = CFactory::getModel('user');
        $mails       = $mailqModel->get($total, true);
The problem arises in this call: $mails = $mailqModel->get($total,true). The second argument here refers to MarkedAsSent and is set to true. Therefore, as soon as any amount of messages are fetched from queue they are immediately marked as sent in the model. This happens regardless of whether the becomes blocked, or the script fails, times out etc…

So behind the scenes my cron task was timing out, but I would have never known because the emails were being marked as sent; everything seemed fine.

To fix this I would recommend setting that argument to false, and marking the items in the queue as sent after the "foreach" code when everything is processed. The interesting (or silly thing is) is that they are being marked as sent at the bottom of the function after everything goes through on line 107:
            if (!$validate) { //email is blocked by user settings
                $mailqModel->markEmailStatus($row->id, 2);
            } else {
                $mailqModel->markSent($row->id);
            }
So things are already being marked as sent in the appropriate spot once the messages have actually processed; so why do it at the top of the function on line 19? On line 19 we don't know if it sent successfully. Why not just let it set the status on line 107 alone? (doing same thing twice probably creates even more overhead).

I haven’t really discovered why it timed out, but probably just because the DB table was so big. I think that trying to send fewer emails at once will help. Fetching all the template content for each email is server intensive. It looks like this happened to someone else (post in first sentence) so doubt i'm the only one... it meant that many of our members didn't get notifications for almost a month which is unacceptable.

If the status is left alone until the email actually sends, at least people know there could be a problem. Next time the cron job goes it will try again where it left of when it timed out.

I can fix it on my end, however any changes I make may get wiped out with an upgrade, so this is why I’m suggesting it here (so maybe it gets changed in the core).

9 years 2 months ago
  • Dimas Tekad Santosa's Avatar
  • Dimas Tekad Santosa
  • Visitor
  • Thank you received: 0
Licenses:

Hi John,

I will try to discuss this issue with our developer, maybe they will apply it on our core code or maybe will have another solution.

thank you

9 years 2 months ago
Licenses:
JomSocial Active iSEO Expired Socialize Expired

OK thanks for the consideration. Hopefully my posts aren't to long and confusing, but was a tricky issue to explain. Might be a nice improvement for version 4.

9 years 2 months ago
Licenses:
JomSocial Active iSEO Expired Socialize Expired

Upon further investigation I discovered what really slows my cron job down is the call to this function:

$this->_removeDeletedUserFolder(JPATH_ROOT . '/images');
I have a site with about 2300 users, so to go through every folder takes a while. On my staging environment it was taking almost 25 seconds. Our server has a hard timeout of 60 seconds; unfortunately something I cannot change or override this. So after that finished it left only about 35 seconds left to send 150 emails (which is the default value in default.ini).

Also on investigation I found that the 150 emails per cron was way to high given function above and overhead it takes to create an email. Without even sending the generated message (I disabled final send call so I didn't email 150 people for a test), I found it takes about around 3 seconds to render the HTML content for 20 emails. All the template calls, and getAvatarImage etc on lines 56 - 100 of /com_community/libraries/mailq.php really add up. At that rate sending 150 emails will take at least 22 seconds on top of all the other calls. A few of my groups have 500 members so if someone posts, 150 emails go into my queue with no problem.

Hope this is helpful; I know with larger communities there could be some growing pains expected, but in reality I don't think my community is all that big in the grand scheme of things. The cron job in my instance was just trying to do too much; If others ahve larger communities I think that some might hit these limits no matter how fast their server.

9 years 2 months ago
Licenses:
JomSocial Active iSEO Expired Socialize Expired

My server stats for reference (will be upgraded in a half year):

Front-end web servers
3 x Sun v40z AMD Opteron servers
2 x AMD Opteron 870 Dual core CPUs
8GB (4x1GB, 2x2GB) ECC RAM
2 x 73GB 10K RPM Ultra320 SCSI local disks
2 x gigabit ethernet adapters
redundant power supplies

MySQL/NFS server
Sun Fire V490 server
2 x 1.5GHz UltraSPARC UltraSPARC IV+ processors
8GB (16x512MB) ECC RAM
2 x 146GB FC-AL disks
2 x gigabit ethernet adapters
2 x fibre-channel adapters
redundant power supplies

Moderators: Piotr Garasiński
Powered by Kunena Forum

Join 180,000 websites creating Amazing communities

JomSocial is the most complete, easy-to-use addon that turns Joomla CMS into a
full -fledged, social networking site

TRY NOW BUY NOW