0

I am having an issue where my application spends 5-10s between Step 2 and 3 occasionally (Every few days) for 100-200 requests. It is processing about 100 requests per second.

Step 1: S: 220 <SMTP server info>
Step 2: TCP Ack for 220
Step 3: EHLO <Client host name>

I was using Java Mail 1.4.5 and now moved to 1.6.1 but having the same issue.

I am setting these properties while creating the session:

props.setProperty("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", <HOST>);
props.put("mail.smtp.port", <PORT>);
props.put("mail.from", <EMAIL_SENDER>);
props.put("mail.smtp.timeout", <READ_TIMEOUT>);
props.put("mail.smtp.writetimeout", <WRITE_TIMEOUT>);
props.put("mail.smtp.connectiontimeout", <CONN_TIMEOUT>);

I have enabled TCP dump and do not see a DNS resolution going on between step 2 and 3. I know that before sending EHLO, java mail will try to resolve the host name on the client side. The correct host name is getting set on the EHLO.

I am not setting mail.smtp.localhost or mail.smtp.localaddress properties right now.

Any suggestion on what might be going on?

Ray
  • 3,864
  • 7
  • 24
  • 36
  • is it a delay from the remote server replying to ehlo? might need to wireshark the issue... – Any Moose Sep 11 '18 at 18:54
  • Did Wireshark, the response for EHLO comes back immediately. The time is spent between the TCP Ack for 220 (from Client) and the EHLO from client. Both of these are done by the Java Mail implementation. I checked the Java Mail code. The broad steps that are going on there are 1. Read the 220 from server 2. Lookup the host name for localhost 3. Send EHLO – Suvanan Dutta Sep 11 '18 at 18:59
  • If the issue is you're seeing odd problems when querying the local host name, why not do it once yourself and set mail.smtp.localhost? Particularly if you're opening a hundred connections a second. (Although I can't understand why there would be an issue looking that up - it must be cached locally?) – Rup Sep 11 '18 at 19:35
  • I am not opening 100 connection every second. The connection is kept alive for 5 seconds and then re-initialized. I don't know whether issue is due to local host query. I am going to try out setting mail.smtp.localhost. But another application I have with more traffic is not setting mail.smtp.localhost and not showing this behavior. So asking for pointers if anyone can think of anything else which may cause this. – Suvanan Dutta Sep 11 '18 at 20:37
  • Try setting [`mail.host` and `mail.smtp.from`](https://stackoverflow.com/questions/44435457/mimemessage-savechanges-is-really-slow/44438011#44438011) in addition to `mail.smtp.host` and `mail.from`. – jmehrens Sep 11 '18 at 21:21
  • Thanks, will try the suggestions. – Suvanan Dutta Sep 12 '18 at 20:28
  • These delays are often due to slowness looking up host names using your name service (DNS, whatever). Most of the results should be cached by the JDK so if it doesn't only happen the first time, perhaps the cache is timing out? – Bill Shannon Sep 15 '18 at 01:10
  • Using Azul JVM, will look that up. Thanks for the suggestion. – Suvanan Dutta Sep 17 '18 at 23:36

0 Answers0