• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Keeping a connection open (java.netHttpURLConnection)

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 69
2
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic