IOS performance: HTTP2.0 and ioshttp2.0

Source: Internet
Author: User

IOS performance: HTTP2.0 and ioshttp2.0

Today, as mobile Internet is booming, APP performance has become a major concern of major companies. This series of articles focuses on several aspects of iOS performance.

  • What is HTTP2.0?

It is easy to find articles on the concept of HTTP2.0 on the Internet.

Apple has supported HTTP2.0 since iOS9. for iOS developers, that is, iOS9, NSURLSession can support http2.0.

Because Apple has already planned to discard NSURLConnection, NSURLConnection cannot support HTTP2.0.

UIWebView does not support HTTP2.0 either. (Of course, if you use UIWebView, then use NSURLProtocol, and use NSURLSession in NSURLProtocol, this also supports HTTP2.0.) WKWebView is fine.

  • What are the advantages of HTTP2.0 over HTTP1.1?

There are several main points:

1. the same Host occupies a TCP Link

2. Request priority can be set

3. Use the binary protocol instead of the previous text protocol.

4. multiplexing

5. Header Compression

 

Among these advantages, I personally think that the most important thing isMultiplexingAndHeader CompressionThese two advantages greatly improve the request performance.

  • Multiplexing

What is multiplexing? In the era of HTTP1.1, a TCP link can send multiple requests, but it must be queued and sent one by one (following the FIFO principle ), this can easily lead to blocking (the legendary head-of-line blocking), such:

 

As you can see, multiple requests in the same connectionId are serial (Timeline-Start time column). Therefore, once a request is blocked, all subsequent requests cannot proceed.

In HTTP2.0, requests do not need to be queued in a TCP link, but are sent by polling, for example:

 

Almost all requests in the same connectionid are initiated at the same time (as a single CPU or multi-thread CPU polling mechanism). This greatly improves the performance.

  • Header Compression

This concept is easy to understand, and the requirements of apps are becoming more and more complex, resulting in more and more request header information (cookies, request parameters, etc.), more than 1 k, 2 k, performance is greatly affected. HTTP2.0 compresses the request header and response header to improve request performance.

  • What is a TCP link?

As mentioned above, HTTP2.0 occupies a TCP link for a Host. here we need to briefly introduce the TCP link.

From bottom to height:

IP protocol: corresponds to the network layer

TCP protocol: corresponding to the transport layer

HTTP protocol: corresponds to the Application Layer

 

TCP requires three handshakes when establishing a link. HTTP is built on TCP, but HTTP is a short link. Once the request ends, the link will be released, however, although the HTTP link is released, however, the underlying TCP link is still running (you can use wireshark to capture packets ).

However, TCP connections are not infinite. The NSURLSession of iOS is allocated with four TCP connections and the MAC is six.

 

Here are two comprehensive HTTP2.0 articles:

Https://medium.com/apps-and-networking/http-2-makes-media-loading-3-15-times-faster-on-mobile-a455c3e68135#.kxd9z7eq4

 

Http://www.floriangoessler.de/ios/2015/08/30/HTTP2-on-iOS.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.