Tuesday 17 March 2015

Slow Network Connection Setup on Linux

Background

This is really a last resort article, when you've tried everything else, try this.

I'm running Fedora Linux 20 on my dev machine, and experienced slow JDBC connection setup from my application as well as from my Eclipse IDE. Applications like JBoss started up unusually slow. My colleagues running Windows did not have the same problem, so I was assuming it was a Linux issue. It turns out it was just a small configuration issue.

Symptoms


1. Connection to an HP Tandem SQLMX database was slow.
2. JBOSS Startup was very slow, it used to hang at something like "15:10:00,555 INFO  [Server] Core system initialized" and I used to wait for about 20 seconds before it continued.
3. My Corba application which also made use of these connections was painfully slow at startup.

Attempted Solutions


I tried switching off the IPV6 stack but this didn't help.
Decreased the number of connections in my application's connection pool, which did help but stuff was still slow.


 Solution

 Eventually it turned out that the localhost entry in my /etc/hosts entry was incomplete.

Before

              127.0.0.1    localhost                                  

After

127.0.0.1    localhost.localdomain localhost

The localhost.localdomain is the fully-qualified domain name (FQDN). It looks like this is supposedly prevent DNS lookups. On a production server, I would think that this is an important setting to have as well.

Conclusion


After adding this, my system was back to normal! This may seem a trivial fix, however this took a lot of time to find the solution, which isn't that obvious.