如果我向同一个 URL 发出两个 HTTP 请求,一个只使用 HttpClient,另一个使用 Volley,Volley 请求需要更长的时间。
例如,在我的测试环境中:
- 直接使用 HttpClient 请求 google.com 平均大约 250ms
- 使用 Volley 请求 google.com 平均大约 750 毫秒
这是一个示例 Volley 请求的日志转储:
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
如您所见,瓶颈在于实际的 HTTP 请求。为什么这么慢?