Monday, July 12, 2010

Sending Multiple Emails

Weather Message's email routines send email sequentially using a background worker thread.  When an alarm matches a received product, a task is created for each email group associated with the alarm.  These tasks are added to the email queue for processing.

The email processor will generally work through the queue in short order.  If the email group has a large number of email addresses, it does take some time to send each email address to the smtp server.  While all of that is taking place the other email tasks are waiting.

I have completed the code to create a pool of threads.  This pool could be used to spawn multiple threads that will take a task from the email queue and start sending it to the smtp server.  The question for now is whether this will make the overall sending faster.   If the smtp server is throttled per connection, having multiple connections could make sending emails faster. 

I ran into a situation with a SNPP server that was slow per connection.  In this case, using multiple threads could have made that faster.

Now that the code is complete, I will be running some tests to see how this will work.  If the smtp server allows for multiple connects from one user, we might be able to deliver emails faster.  For users that only have a few groups, this would not have any affect.  For users that have bunches of email groups that are activated often, this may make delivery faster.

Note:  If the limiting factor is the internet pipe speed, there is nothing that we can do to make it faster.

I will report further as testing starts later this week.

No comments: