Alex Rivera | Logout

Multi-threading to speed up an email-sending application

Asked 2012-01-01T23:08:58.397
8

I have built an application to send email mailers for a website through Amazon SES. It is coded in C#.

Each email takes .3 seconds to send via the Amazon SES API. That means, using a single-threaded application, I can only send 3 emails per second.

I have implemented a producer/consumer, multi-threaded application with 1 producer to query customize the emails for each customer, and 25 consumers to pull from the queue and send the emails.

My multi-threaded application sends 12 emails per second (a quadruple speed increase). I would have expected a greater speed increase from a 25-thread application.

My question is: How much can I really speed up the sending of a mailer on a single-processor machine? Do my gains seem reasonable, or is my speed problem more likely due to coding than to the computer's inability to process the emails mroe quickly?

Thanks in advance!

UPDATE: In case others are facing the same issue.... connecting to AWS in order to send the email takes up a lot of time. The following thread on AWS Developer forums gives some insight (You may need to scroll down to get to the more useful posts).

https://forums.aws.amazon.com/thread.jspa?threadID=78737

Edit
Report

1 Answer

1

producer consumer with only one queue doesnt scale well. The queue becomes the bottleneck as you add more consumers or producers.

if you have multiprocessor architecture, you can use multiple processes to send emails. You can still use your producer consumer multithreaded version, but now it will be one foreach process; this will speed things up a bit (as Tudor explained) but the problem remains.

however, you might have, for the entire system, only one network manager or similar entity which sends the messages (say htttp messages) and one network card. Now the bottleneck could be this network manager. Id like to know more about the architecture of the system :)

answered 2012-01-01T23:23:17.737

Your Answer