Three second https connection times on 3G networks
Ping to the server on the 3G network is 80ms, about the same as on Wifi (60ms), yet the time to set up an SSL connection is 3.5 seconds on 3G, 0.5 on Wifi. This is the same using both a laptop and an iPhone as the client.
The 3G tower is not busy. The internet connection is basically idle.
If I run the phone in Wifi, with a 70ms ping to the server, the connection handshake time is 6 times faster - about half a second, which is roughly all I can hope for, given the ssl handshake details.
Is this normal? I have only tested it on one server, at AWS in Virginia (heroku), which is about a 50ms ping on Wifi from my office. In all cases the server builds and responds with the 10kB of data in about 40 ms or so.
Is 3G really that much slower? Or is there some tweak I can do to NSURLConnection, etc to get things to handshake faster?
Is this a the 3G radio sleeping between requests? - I dont think so, as even if I keep the 3g radio on with pings, (say) the same thing happens.
I am actually not 100% sure this is the answer.
The GSM cellular radio on the phone is off for as much time as possible to save batteries. When you launch an app, the radio will turn on as soon as you ask for a web resource. It takes about a second? (not sure about this) to boot the radio.
So its hard to improve. About the only thing I have found so far is to use an NSURLConnection in main.m - no delegate is set. This sped things up by about 0.3 seconds for me - the time it takes to get to the point in the code where I actually want to go online.
Please note that this will waste batteries if you actually don't need to go on line!
// warm up the radio ASAP. It seems to take over a second for the radio to turn on. // This saves about a quarter of a second or so. 404 is typically a fast easy response for a server. NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://yoursite.com/wedonthavethis/"]]; [NSURLConnection connectionWithRequest:request delegate:nil];