Volley: http requests slow
Asked Answered
C

2

6

If I make two HTTP requests to the same URL, one with only HttpClient and the other with Volley, the Volley requests takes much longer.

For example, in my test environment:

  • using HttpClient directly to request google.com averages about 250ms
  • using Volley to request google.com averages about 750ms

here's a log dump of a sample Volley request:

11:44:14.766: D/Volley(863): [1] MarkerLog.finish: (773  ms) [ ] http://google.com 0xa46e044c NORMAL 1
11:44:14.766: D/Volley(863): [1] MarkerLog.finish: (+0   ) [ 1] add-to-queue
11:44:14.786: D/Volley(863): [1] MarkerLog.finish: (+0   ) [93] cache-queue-take
11:44:14.786: D/Volley(863): [1] MarkerLog.finish: (+7   ) [93] cache-hit-expired
11:44:14.796: D/Volley(863): [1] MarkerLog.finish: (+1   ) [97] network-queue-take
11:44:14.806: D/Volley(863): [1] MarkerLog.finish: (+722 ) [97] network-http-complete
11:44:14.806: D/Volley(863): [1] MarkerLog.finish: (+20  ) [97] network-parse-complete
11:44:14.816: D/Volley(863): [1] MarkerLog.finish: (+16  ) [97] network-cache-written
11:44:14.826: D/Volley(863): [1] MarkerLog.finish: (+0   ) [97] post-response
11:44:14.836: D/Volley(863): [1] MarkerLog.finish: (+7   ) [ 1] done

as you can see, the bottleneck is in the actual HTTP request. Why is it so much slower?

Confirmation answered 7/6, 2013 at 18:51 Comment(0)
S
1

Looks like Volley is caching your response. Using HttpClient directly does not cache anything.

Squeteague answered 11/6, 2013 at 19:7 Comment(3)
Surely caching should make Volley faster not slower.Alicaalicante
It's slower only for the first time. Next retries it will use response from cache rather than initiating another http transaction.Squeteague
In the Volley log, it shows that the cache response is not being reused (cache-hit-expired) and it only takes about 7ms to check this. But the actual http request takes 722ms. Writing the cache takes 16ms. So I don't think caching is the problem.Alicaalicante
O
0

Volley usually caches the network responses which make it slower. If you still want to use volley you can clear the cache to make it faster eventually.

AppController.getInstance().getRequestQueue().getCache().remove(key);

You can create a handler event to run this automatically every 2 minutes or so. Hope that helps:))

Oporto answered 30/5, 2020 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.