Home » Java » http – What are factors that influence network performance in JAVA (use case HttpURLConnection)-Exceptionshub

http – What are factors that influence network performance in JAVA (use case HttpURLConnection)-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am developing an applicant which essentially need network high optimization and especially HTTP connections (I am using JAVA’ HttpUrlConnection), for this I want to know what are the must use practices. I have some precise questions anyway :

  • Connection persistence : I am setting (System properties) ‘http.maxConnections:21’ and ‘sun.net.http.errorstream.bufferSize:10240’, does increasing these values improve performances? (The application perform many requests to the same website, it can reach 30 active connections (threaded) at the same time)

  • Connection persistence : does persistence mean usage of previous headers? or just the established TCP channel?

  • can I adapt HttpURLConnection to use Http/2? Does this improve performances? (I read that Http/2 uses multiplexing which seem to be a better mechanism)

  • Does connection persistence work also over proxies? (I suppose from app->proxy YES, but from proxy->server it depends on proxy support of connection persistence)

And lastly I would like to know what are other technics/http headers/tools I can use to improve network usage (my goal is to connect & send/receive data to server as faster as possible);

What I did try :

  • Use the application from in an RDP close to the target server (to reduce geo. distance and thus routage/switching points);

  • Use parallel connection by sending the same request many times for each threads, but I believe it is not a good practice;

  • Reduce size (number) of headers (user agent length as well) and data sent to server;
  • Use other APIs : HttpClient (which performance is clearly lower than HttpUrlConnection) and Jsoup which performance was better than HUC (weird! I did post a thread on SO about that) even it is backed by an HUC, but I deceided to not use it cause it is backed by HUC and there must be other explanation for the speed difference;
  • using the IP directly to avoid DNS lookup, but it is beneficial in just the first request;
  • Tried a high bandwidth connection (Amazon instance with up to 15Gb network instance), maybe fiber network would be a better choice?? I shall test that;
  • The reason why I want to find the best way to optimize network is that even with a JAVA application connection to the website (so there is no XHR request, JS execution or css/img/js files fetching performed) there is no very remarkable difference with a browser connection (with xhr,js,css….), especially when many clients are connecting to the server, in this case the browser load faster than browser in most cases! (but I didn’t test it with connection persisting yet, but without it the browser is better!)

nb. I mainly communicate with two types of servers : Microsoft-IIS/8.5 and Apache behind Amazon Load Balancer, so if you have recommendations proper to these two types it would help me as a general recommendations would do.

Thanks in advance!

How to&Answers: