Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make work HttpResponse faster?

I am working on a project in which "I have to get 4096 bytes of data to server" from "server" every "between 1-millisecond to 10-millisecond".But it's "taking too much time" i.e "around 300ms - 700ms" which causes my application to lose data.

I am using below snippet

HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost("http://192.168.1.40/ping");
HttpResponse response = client.execute(request);

The HttpResponse is only taking too much time i.e around 300ms - 700ms.

How I can get response faster ?

Instead of this what else I can use to get a response from sever faster then this?

Please let me know any solution or way to solve it.

I have done google, gone through other ways like DataOutputStream and ByteOutputStream but no use of this, it also taking too much time then HttpResponse.

Help will be appreciated.

like image 522
Rahul Baradia Avatar asked Nov 30 '12 04:11

Rahul Baradia


2 Answers

Before you can make the responses faster, you are going to need to investigate and understand why they are currently taking a long time. Roughly speaking, it could be:

  • the client side taking a long time to create the request and/or preocess the result (seems unlikely ...)
  • a slow android network protocol stack
  • a problem with your local networking (e.g. WiFi) or your telecoms provider
  • a congested / overloaded server or server-side network, or
  • something pessimal in the server implementation.

Do things like:

  • try the request from a web browser on a conventional PC and use the browser's web-developer stuff to try to tease out whether/why the request is taking a long time ...
  • look in the server-side logs and/or monitoring for request load and timing information
  • other suggestions please

Implementing SPDY might help, but it is unlikely to change response times in the order of 500ms to a couple of tens of milliseconds. The problem seems more fundamental than "HTTP is old and slow". And the same reasoning applies to all of the other suggestions that people have made.

like image 165
Stephen C Avatar answered Oct 28 '22 13:10

Stephen C


This is not possible. You are recreating a connection every time.

You need to hold a persistent connection with the server. Try creating a persistent http connection.

If that doesn't work you can try sending raw udp packets (or anything else). It will be harder but it will take less time.

like image 43
Bishnu Avatar answered Oct 28 '22 13:10

Bishnu