Solved

Optimizing Java mail client

Posted on 2008-06-12
21
323 Views
Last Modified: 2013-11-13
I have an (Java) application that daily sends thousands of emails.
Usually it's one email per few 1K users.
In order to make it more 'personal', each of the users gets the email via "To" field, with only him being the single "To" recipient.
But this sending email in a for-loop takes ages, usually 5-6h.

So, I'm looking if there is some better/faster way to do this.
Some better Java mail client, than the usual JDK stuff.
I'm thinking (out-loud) of the following things:
 - instructing smtp server to lay off on the strict checks since he'll receive few 1K emails from trusted source
 - instructing server to do 'batch' processing, at the beginning only receiving emails, and after 'commit' sending them
 - perhaps server could have option to receive email with all recipients, but sending the email then one-by-one
 - ...

The solution that I see here is to have some client that knows to adjust to server type.
To execute some custom operations that speed things up.

Any ideas / such clients out there?
0
Comment
Question by:Dejan Pažin
  • 10
  • 9
21 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You are using the same Session throughout the loop? How many mails take 5-6hrs?
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
I'm using this class:
 - http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/mail/javamail/JavaMailSenderImpl.html
Where I only set host.
The code in this class uses single session, created at instantiation:
      private Session session = Session.getInstance(new Properties(), null);

Around 4-5K emails take 5-6h.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Creating a new Session in a loop (if that's what's happening) will give you unnecessary overhead
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
No, this class is a singleton in my app.
Hence single Session instance.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
I think i'd need to see how you're using that class. From the doc, the safest way of using it in accord with what i've said is to supply it with your own Session and use only the one
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
OK.

a. Create a Session, s
b. Create JavaMailSenderImpl, jmsi
c. Call jmsi.setSession(s)
d. Now send in a loop
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
Why?
That's exactly what getSession does - creates a single instance for the whole JMSI usage.

153       public synchronized Session getSession() {
154             if (this.session == null) {
155                   this.session = Session.getInstance(this.javaMailProperties);
156             }
157             return this.session;
158       }

And I only have one JMSI instance.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Oh OK - i haven't studied their code. If it's only using one Session for the lifetime of your loop then you're OK on that front
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
Sure, but that's not what I'm looking for.
This one was obvious. ;-)

My question is more of 'is there some API that does this better'?
Or even, is there some smtp extension that does that?
Or, is there some server that does that, and it has a complementary Java client to 'communicate'.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Have you found where the bottleneck is yet?
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
No, what exactly should I look for?

The issue here is, that this performance downgrade is at customer's site,
where I don't have good access to monitor things.
And I don't see usefulness in testing my own env with different smtp server.
Where I also doubt they would allow/open customer's smtp server for my 'spam' tests.

I would resort to this as the last option - running my own tests against my own smtp server.
That's why I'm asking if somebody has encountered similar issue before. :-)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You could turn up logging to debug in all components and get them to send you the logs
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
This must be classical Java Mail issue.
 - http://java.sun.com/products/javamail/
I don't think debugging that will do me any good.
Unless there is something specific (in that lib) you have in mind?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Well it's not 'debugging' but logging. You should particularly look at logging around timings in the transport classes
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
OK, even if I do see where the bottleneck is, what can I do then?
It's Java Mail, no way it's gonna change anytime soon.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
If it's in the network/transport layer then you can look into that independently of the Java.
0
 
LVL 17

Author Comment

by:Dejan Pažin
Comment Utility
No idea what I could do then.
So I'm only interested in Java part of this optimization.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Well there's nothing you can do in any layer until you've identified where the bottleneck is.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Are you using email marketing software? If not, you're missing out on effortless marketing and the reaching of desired conversion rates through email marketing software.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The purpose of this video is to demonstrate how to use PicMonkey software to customize images for a Mailchimp campaign. Picmonkey is free and simple online software which can be used by users who don’t have robust editing software such as Photoshop,…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now