Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Optimizing Java mail client

Posted on 2008-06-12
21
330 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
ID: 21768904
You are using the same Session throughout the loop? How many mails take 5-6hrs?
0
 
LVL 17

Author Comment

by:Dejan Pažin
ID: 21769728
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
ID: 21769784
Creating a new Session in a loop (if that's what's happening) will give you unnecessary overhead
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 17

Author Comment

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

Expert Comment

by:CEHJ
ID: 21771908
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
ID: 21773765
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21776587
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
ID: 21776856
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
ID: 21776884
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
 
LVL 17

Author Comment

by:Dejan Pažin
ID: 21776949
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
ID: 21776992
Have you found where the bottleneck is yet?
0
 
LVL 17

Author Comment

by:Dejan Pažin
ID: 21777100
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
ID: 21777204
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
ID: 21777497
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
ID: 21778069
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
ID: 21778404
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
ID: 21778644
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
ID: 21779321
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
ID: 21780700
Well there's nothing you can do in any layer until you've identified where the bottleneck is.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Math Equation 23 105
Java: The Public Class Main 4 30
how to debug htl and js pages 8 38
WordPress: Debugging from my Windows 10 Desktop 6 25
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.
Article by: Dermot
The life of crime is over for 22 year-old Christian Ian Salvador, a student from Isabela State University in the Philippines.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 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