Make Sitecore EXM faster with "NumberThreads" and "SendMail" pipeline "Sleep" config settings
Posted 6 January 2018 by Marek Musielak
TL;DR Never trust default settings. Try, test and see what works best for you.
Quite recently I learned about 2 settings which helped me to send my Sitecore EXM mail campaigns many times faster. I was using default settings which comes with a fresh EXM installation. And now I learned my lesson: if you want to use a Sitecore module, read all its config files and check if there is anything interesting in them.
Vlad Iobagiu for all his help with my EXM issues and with getting answers which resulted in this article.
I was having some issues with Sitecore EXM (sic!) and I was googling for a solution when I found The EXM pipelines article. I noticed SendEmail Pipeline section and Sleep parameter with description:
Sleep: controls for how long EXM pauses on the current server after sending each email message. Specified in milliseconds (ms).
My first though was "Why would anyone want to send emails slower?!" And then documentation explains:
In a multiserver setup, you can use this processor to balance the load between the servers. For example, if you want the dedicated server to send 4 times as many email messages as the primary CM server, specify the following values on the sleep setting: - 200 on the primary CM server. The server pauses for 200 ms after sending each email message. - 50 on the dedicated server. The server pauses for 50 ms after sending each email message. Then, if you send 1000 email messages, the primary CM server sends approximately 200 email messages (20%) and the dedicated server sends approximately 800 emails (80%).
Ok, makes some sense. Calculation above doesn't take into account time spent on sending emails, it only takes into account sleep time between sending messages. But I want to send my thousands or millions of emails as fast as it's possible. So let's check the configuration. Clean Sitecore Email Experience Manager - Email Processing 3.4.2 rev. 170713 default setting of sleep parameter is 50 ms:
<processor type="Sitecore.EmailCampaign.Cm.Pipelines.SendEmail.Sleep, Sitecore.EmailCampaign.Cm"> <!-- Number of milliseconds to put the thread to sleep for after an email has been sent. --> <param desc="sleep">50</param> </processor>
It is 50 ms for CM server and 50 ms for Dedicated Email Delivery server. For CM server it makes some sense - we don't want to make content authors lifes any harder. But the only role of Dedicated Email Delivery server is to send mails as fast as possible. I don't want it to sleep after every email. I changed sleep value to 0 and scrolled config file a bit more.
The next setting which caught my attention was NumberThreads:
<!-- The number of threads that you can use for sending messages. --> <setting name="NumberThreads" value="1" />
Come on, it's 21st century. 2018. Even the weakest laptops have multiple cores. Multithreading is a must. Let's try some bigger numbers. I started with tests on my laptop and local smtp4dev. Changing the Sleep value and NumberThreads setting resulted in sending the campaign several times faster.
Ok, so what are the numbers I should use in my production environment. Well, I don't think there is a definitive answer to this question. I think the safe values are:
CM server: NumberThreads = 50% of cores and 50ms Sleep DED server: NumberThreads = 75% of cores and 0ms Sleep
That should allow content authors to do their job on CM server when the campain is being sent and it should leave come CPU for other processes on DED server. But as I wrote at the very beginning: Try, test and see what works best for you.
Thank you for reading. I hope you enjoyed. Visit my Sitecore blog for more Sitecore related articles.