RoR Email Sending Performance

If you need to send a lot of emails from Ruby on Rails you may run into problems. Out of the box I was getting about 1 email/second through smtp from our low end server.

There’s an easy fix however!

put this in your environment.rb

ActionMailer::Base.delivery_method = :thread_smtp
module ActionMailer
class Base
def perform_delivery_thread_smtp(mail)
thread = Thread.new do
perform_delivery_smtp(mail)
end
thread.run
end
end
end

Doing this I was able to get smtp up to 13 emails/second with ruby’s smtp (there were a few DB calls as well for each email send). We use msmtp to send secure email, this has a similar configuration change. Using that I got up to 16 emails/second. I guess most things are faster than ruby.

Please do not use this technology for creating a spam engine, world domination, or evil.

Advertisements

One Response to RoR Email Sending Performance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: