[ 
https://issues.apache.org/jira/browse/EMAIL-211?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17935360#comment-17935360
 ] 

Hiran Chaudhuri commented on EMAIL-211:
---------------------------------------

There is a smtp connection pool project out there. It shows off architecture, 
usage and complete example implementation:
{panel:title=https://github.com/simple-java-mail/smtp-connection-pool}
h4. Essential performance boost of using a connection pool
[|https://github.com/simple-java-mail/smtp-connection-pool#essential-performance-boost-of-using-a-connection-pool]
A very common scenario is to have a single connection being reused over many 
email-sending threads and usually this is enough. This can be achieved by 
having 1 cluster with 1 pool of size 1. This already gives a real boost over 
not using a connection pool, since threads using the same transport but each 
establishing a new connection each takes half of the time of sending the email 
itself.
h4. Scale up performance with multple concurrent connections
[|https://github.com/simple-java-mail/smtp-connection-pool#scale-up-performance-with-multple-concurrent-connections]
The next solution satisfies most performance needs by far: having 1 cluster 
with 1 pool, but multiple connections. This takes the above approach to the 
next level by allowing multiple concurrent connections to your mail server. If 
your server can handle it, you really scale up on performance. Try benchmarking 
your server with test emails with different pool sizes to see when performance 
starts to degrade.
h4. Take on the world with a cluster of mail servers
[|https://github.com/simple-java-mail/smtp-connection-pool#take-on-the-world-with-a-cluster-of-mail-servers]
Finally, the next solution satisfies if you really need to send _a lot_ of 
emails in a reasonable time. Define a cluster of several mail servers to which 
you can have one or multiple concurrent connections. You rarely need this kind 
of performance, but sending news letters or world wide updates become can 
benefit greatly from this.
{panel}
 

Plus it is used in this client:

[https://github.com/bbottema/simple-java-mail]

 

> Add connection pooling
> ----------------------
>
>                 Key: EMAIL-211
>                 URL: https://issues.apache.org/jira/browse/EMAIL-211
>             Project: Commons Email
>          Issue Type: New Feature
>            Reporter: Hiran Chaudhuri
>            Priority: Major
>
> Congratulations for an easy to use straightforward client library.
> However the application I created spends most of it's time connecting to the 
> mailserver. How come?
>  
> Apparently the examples on 
> [https://commons.apache.org/proper/commons-email/userguide.html] follow this 
> pattern:
>  
> {code:java}
> Email email = new SimpleEmail();
> ...
> email.addTo("[email protected]"); email.send();
> {code}
> As an effect, in the background it creates a JavaMail Session and Transport, 
> uses it to send the email and then forgets about it again. In my environment 
> building a connection requires to get an authentication token, then using 
> that for secure SMTP. Establishing such a connection takes a few seconds, 
> which limits the throughput of sending emails.
>  
> Please add a feature (or document how to do if already possible) to reuse 
> connections for sending several mails. Also the solution should be thread 
> safe so a multithreaded application can send emails in parallel.
>  
> I guess this should be easily doable by combining commons-pool and 
> commons-email. However my attempts failed miserably, making me want to switch 
> to other mail client libraries altogether.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to