iOS doesn't to use http keep-alive. Very high latency

大兔子大兔子 提交于 2019-12-12 03:38:05

问题


I wanted to test latency for my server, so I sent a rest request. Using a rest api client, i got around 500 ms latency from desktop, but when i do the same request on iOS Simulator (using AFNetworking) , I am getting latency of 1.8 seconds.

My server sends keep alive headers, and I noticed that the first request from my PC is of a similar latency as IOS. How do I make iOS honour keep alive , or reduce latency ? Since I am making a realtime app , it is a must that I have low latency. From the same computer , my rest client is about 3x faster than iOS. How may I fix this issue ?

Edit:: I noticed that upon disabling https support from my server, the latency becomes 1 second. To me it is quite obvious that there is some problem with iOS not using keep alive.

I monitored network activity using wireshark. Below is a picture of two http requests made at around 1 second intervals:

It can be seen that encrypted handshake is being done twice.

Using my rest client, this is it what the same http requests at 2 second interval looks like:


回答1:


Without seeing any code, it's hard to say for sure what's happening, but make sure:

  • The requests are in the same session. Each session uses separate underlying connections, so if the session goes away, so do the connections.
  • The requests use the same authentication credentials (if applicable).

Additionally, try enabling HTTPShouldUsePipelining. If there are multiple requests in flight for the same server, the connection won't be closed until (at least) the last one arrives, so that might sometimes help even when the OS is aggressively managing power.



来源:https://stackoverflow.com/questions/38773688/ios-doesnt-to-use-http-keep-alive-very-high-latency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!