Link to home
Start Free TrialLog in
Avatar of pallosp
pallosp

asked on

slow socket connection

I would like to create a TCP/IP connection to a scales in the local network.
In Java 1.5 it takes 4-5 seconds while telnet can build up the connection immediately.
What can be wrong?

My code is the following:

long time = System.currentTimeMillis();
InetAddress addr = InetAddress.getByName("192.168.0.20");
System.out.println(System.currentTimeMillis() - time);
// running time: 90 ms

time = System.currentTimeMillis();
Socket socket = new Socket(addr, 8000);
System.out.println(System.currentTimeMillis() - time);
// running time: 4617 ms

How can it be made faster?

Thanks, Peter
Avatar of Ajay-Singh
Ajay-Singh

looks like some systematic issue, can you post the strace result on the java program.

If you are running your program like this:

java Client

to capture system call trace, run as

strace java Client
and post the results.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pallosp

ASKER

Is it a Linux command? I don't find it in jdk 1.5.0_09.
I'm currently developing in Windows XP although finally the application will be deployed on a Linux server.
No, it is a property that you pass dynamically in the JVM.

java -Djava.net.preferIPv4Stack=true <your application>
Avatar of pallosp

ASKER

I thought of strace. While I was writing my comment Ajay-Singh's was the only answer.
I think he probably meant trace.
I mean strace  - unix commands that prints system calls made by the application and their timings.
Avatar of pallosp

ASKER

Finally I could localize the error. The socket connection is slow only in JRockit JVM. After updating to BEA JRockit(R) JDK 5.0 Update 6 (R26.3.0-32) its speed became tolerable, although DNS name resolution is still 4 times, and building up the connection is 2 times slower than in Sun JVM. The -Djava.net.preferIPv4Stack=true option doesn't have effect on speed.

I uploaded the strace.log at http://www.novekdm.hu/strace.log if you're interested in.
> I uploaded the strace.log at http://www.novekdm.hu/strace.log if you're interested in.

I am not able to access this site.
Avatar of pallosp

ASKER

I don't know why you can't download the log, anyway here is another copy:
http://pallosp.fw.hu/strace.log