Android HttpClient performance

后端 未结 2 1293
梦如初夏
梦如初夏 2021-02-02 02:44

I developing android app which uses a lot of http requests to web service. At first, I was creating a new HttpClient instance before every request. To increase performance I try

相关标签:
2条回答
  • 2021-02-02 03:31

    It is all very simple. HttpClient per default allows only two concurrent connections to the same target host as required by the HTTP specification. So, effectively your worker threads spend most of their execution time blocked waiting for those two connections to become available.

    You should increase the 'max connections per route' limit to reduce / eliminate worker thread contention.

    You might also want to check out the benchmark used by Apache HttpComponents project to measure performance of HttpClient.

    http://wiki.apache.org/HttpComponents/HttpClient3vsHttpClient4vsHttpCore

    0 讨论(0)
  • 2021-02-02 03:33

    I suspect the context switching is resulting in poor performance with the thread safe manager, and you should stop using it. I suppose you could compare the Apache client with the default Java client, but I don't think you are going to get much of a performance gain.

    Personally, I've found the DOM XML parser to be a bit slow, so if you are using XML reformatiing it may help. Depending on your app you may be able to request items before you need them or use caching to create a better user expierence, but we would need to know more to give you meaningful advice.

    0 讨论(0)
提交回复
热议问题