• Post Reply Bookmark Topic Watch Topic
  • New Topic

URLConnection connect() too slow

 
Mike Broadbear
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a java app that uses an HttpUrlConnection to make an https call to a server. The connect() method takes exactly 21-22 seconds each time. The amount of data is small and the same url with http executes very fast.

SSLSession, etc... is all implemented, and it looks like the delay is before any network communication (handshaking) takes place.

Can someone give some pointers about what could be causing the delay? Is there any way I can look inside the connect method to see what is taking so long?

...Mike
 
Mike Broadbear
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a way to enable debugging:

http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/ReadDebug.html
You can add -D-Djavax.net.debug=all to the command line.

A list of options can be found here:

http://www.itworld.com/nl/java_sec/01122001/

...Mike
 
Mike Broadbear
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I can see the app is pausing after seeding the random number generator:



Can anyone tell me what is happening during this time period?

...Mike
 
Mike Broadbear
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have put some sysouts in the code, and found that a majority amount of time is spent on the method:



I don't mind this method taking so long, as long as I am able to reduce the number of calls to only one, and still be able to use the connection repeatedly. I am experimenting with this, however, I am getting an IOException when trying to write to the stream a second time (after reading input).

Is there anyway to reuse this connection?

...Mike
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Broadbear:

...Mike


You mean: URL.getConnection() ?

I have had the best luck working this type of issue by getting the entire sources for whatever JDK version one is using and carefully reading through the entire matter several times.

I have not been effective at reading the sources for the JVM, but often the sources for the Java class one is using contain remarkable clarity in the comments, as is stated in the goals for Java.


Nick
[ April 26, 2007: Message edited by: Nicholas Jordan ]
 
Mike Broadbear
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I meant ...

I found that using fixes the problem I was having. Now latency is down to 1-3s. There may be an attempt to use a proxy in another piece of the app that I did not design. I got the idea from an issue reported on sun's bug site saying may try to use a proxy even though you tell it not to.

...Mike
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Broadbear:
Sorry, I meant ...
...Mike

I'm a wombat as far as remarks about sorry and so on,...but WOW !!!
we made progress !

Open fora rules !

saying may try to use a proxy even though you tell it not to.

Now I know where to look to solve my problem. (manner of speaking to acheive clarity through brevity)

The only dumb question is one you should have asked and didn't.
[ April 27, 2007: Message edited by: Nicholas Jordan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!