Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping a connection open (java.netHttpURLConnection)  RSS feed

 
Markus Neumaier
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm accessing a WebService with BasicAuthentication from my WebApplication. The Answer from the WebService is a XML-File (but that should not matter, because only the InputStream is needed).
I implemented 2 Versions, one using the "java.net.HttpURLConnection" and the other using "org.apache.http".

The Connection with the java.net package takes about ~100ms and the Connection with the "org.apache.http" package takes about ~500ms. Since I'm requesting 220 different Files from the server, both are too slow for my usage.
I think I could enhance the performance by keeping the connection open and just requesting the next File, but i dont know how to do that.


Since I'm getting my "HttpURLConnection" from my URL i dont know how to request a different file.
For example I request something like: "https://myServer/device1/status" and after that i want to request "https://myServer/device2/status". Is there a way to connect to "https://myServer/" and then change the parameters to "device1/status" etc.?

Thank You

Markus

Edit: I did some followup reading and found out that HttpURLConnection is based on the Socket implementation and therefor "inherits" the keep alive functions, as long the connection is not explicitly closed.
But i still need to increase the speed. The Service prepares data for a WebSite, which currently takes ~25s to load.
 
Luke Leber
Ranch Hand
Posts: 69
2
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I can see three possibilities (not to say there aren't others):

1) Security Management is adding latency (if you are running in a sandbox - this can be SEVERE if a peer doesn't have its rDNS set up properly)
2) You are experiencing unavoidable network latency.
3) Oracle's API isn't fast enough for your work case.

When I get back home Monday, I'll type up a native benchmark to compare against the one you have in Java.
 
Ron McLeod
Saloon Keeper
Posts: 1425
206
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With PoolingHttpClientConnectionManager, CloseableHttpClient, and HttpClients you can both keep the connection alive and perform multiple concurrent downloads (using Threads). That may speed-up things up for you.

I had a project where I had to download 20 resources from a server over a satellite backhaul (around 700ms round-trip delay). Downloading them sequentially took around 30 seconds; 5 at a time took 6.5 seconds, 10 at a time took 3.5 seconds, and all 20 at once was a bit over 2.5 seconds.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!