1

Hi All,

My application is required to find the time elapsed for downloading a small sized file by using HttpClient (HTTP GET) on Android.

I captured the nanoTime before and after the HttpClient.execute in order to find out the elapsed time. At the same time, I collected the TCP dump to find out the elapsed time between HTTP GET and response 200.

i found that there is the difference of nanoTime is 30% to 50% higher than the elapsed time from TCP dump.

Is there any suggestion to minimize such difference ? Using Httpurlconnection ?

Best regards,

Henry Fok

SkyEagle888
  • 1,009
  • 2
  • 18
  • 42
  • It is strange. After having a closer look on the tcp dump, I found that ... my application sent 6 HTTP GET (one by one after each 200 response) and before each HTTP GET, the TCP is required to SYNC and ACK again. That's consume time ... Anyone has insight about Android httpclient ? How can my application keep the TCP connection alive ? – SkyEagle888 Feb 21 '14 at 04:25
  • Does it set `Connection: keep-alive` header? I'd suggest you give HttpURLConnection a try. For simple GETs it's not too much work. Otherwise have a look at [DavidWebb](http://hgoebl.github.io/DavidWebb/). I suppose you won't be able to measure a difference in performance compared to HttpURLConnection, but it has a nice interface. (Compared to HttpURLConnection all interfaces are nice.) And have a look at http://stackoverflow.com/questions/13677261/how-to-keep-httpclient-connection-keep-alive maybe your server or some proxy refuses to keep the connection alive – hgoebl Feb 21 '14 at 06:51
  • I have tried ... httpurlconnection and httpclient too. We have iOS application to do the same task. According to TCP dump of iOS application, SYN only happens before the start of 1st HTTP GET. Therefore, the remote server should be ok. But Android application cannot re-use the connection ... – SkyEagle888 Feb 21 '14 at 07:10

2 Answers2

2

If it simple GET (without authorization etc) I would go with Socket and implement simply GET method.

https://developer.android.com/reference/java/net/Socket.html

bluszcz
  • 4,054
  • 4
  • 33
  • 52
0

Google recommends using HttpURLConnection. Maybe you can boost speed using SPDY, e.g. with OkHttp, but this must be supported by the web-server.

BTW how did you get TCP dump? On Android device? Rooted? Or on your web-server. If web-server, then your measuring latency, not HttpClient overhead. (Of course you haven't done this, silly question.)

hgoebl
  • 12,637
  • 9
  • 49
  • 72