I believe that you confuse TCP keep-alive with HTTP support (persistent connections). These are not related concepts. From your question, you probably mean HTTP persistent connections.
In HTTP / 1.1, persistent connections are standard and are used by NSURLSession and almost every HTTP / 1.1 client. You must ask them to turn off. You can check Connection: close in the HTTP header or on the server side, you can check the Close field in http.Request . But I'm sure you get persistent connections. This means that you do not need to re-examine the TLS tunnel (or at least the tripartite TCP handshake) for each request. (Although if you are doing concurrent requests, there will still be several connections that you need to negotiate. HTTP / 1.1 can only handle one thing at a time, and NSURLSession will try to use the connection pool to improve response time.)
TCP keep-alives is a completely different thing. It sends a periodic ping to the other side to make sure it is still available. There are many ways to lose a network connection and not know it until the next time you try to communicate, and the normal symptom is that the connection just hangs and you need its time. Theoretically, TCP keep-alive is just a tool to detect this, but I almost never found it practical. Difficult to set up correctly (especially in Cocoa). You will almost always need to create higher-level ping functionality for your application, rather than relying on it.
But leading it to your problem, HTTP / 1.1 is probably right for you as it is, but you will need to carefully manage your responses. If you make a new request for each letter and send a massive response, then this will work poorly. You will keep all of your connection pools busy by loading things that you are about to throw away. First you need to focus on good algorithms. At a minimum, you probably only want to submit multiple results at a time and provide a “swap” approach in your API to get more results for the same search.
Rob napier
source share