"Reading notes" iOS network-Optimizing request performance

Source: Internet
Author: User

One, measuring network performance

1, network bandwidth

The most common metric used to describe the performance of a wireless network is bandwidth. In digital wireless communication, the network bandwidth can be described as the number of bits per second that the communication channel between two endpoints can transmit. The theoretical bandwidth that modern wireless networks can provide is high. Keep in mind, however, that the bandwidth numbers cited by operators and network device providers are often the theoretical maximum of the technology, and that the actual bandwidth used by network devices may be a significant deviation from this maximum.

2, network latency.

The 2nd factor in measuring network performance is network latency, which refers to the time it takes for a network packet to round-trip between two endpoints. Wireless carriers rarely mention network latency data, but latency can have a significant impact on the actual performance of the application. As with bandwidth, there are a number of factors that can affect the latency that the application suffers. The main factor is the latency of the wireless network technology itself that is used to connect the device to the outside world.

3, device power.

iOS devices typically run on batteries, and each action taken by the app consumes power. The major consumers of power on iOS devices are:

1) screen display with backlight.

2) Location service.

3) wifi-Radio.

4) WWAN (cellular) radio.

5) Graphics processor

6) CPU

7) Bluetooth Radio

8) Sound processor.

In addition to the screen display, the app can control most of the above.

Second, optimize network operation.

1, reduce the request bandwidth.

1) JSON and XML are common data encoding methods for request and response bodies. The efficiency of the compression mode depends heavily on the data being compressed, although JSON is often a more efficient pattern.

2) Web browser support for request compression is not very good, because the browser does not know that the target server is delayed to support the decompression of the request. If the server is unable to understand the compression mode, the request is discarded and the client application will not be able to respond.

3) As with response compression, clients should not waste CPU time on compressed content such as PDFs, encrypted data, images, audio, and video, however, Base64 data representing pre-compressed data often benefits from request compression. For example, if you want to upload JPEG files in Base64 format, you can compress the BASE64 data and reduce the volume of compressed data by about 30% compared to uncompressed Base64 data.

2, reduce the request delay.

1) Implementation, on iOS devices, we have no way to reduce the latency of a single network request, but there are some techniques to reduce the latency of multiple requests.

2) There are two best practices for reducing Request latency: sending HTTP requests on a single TCP connection and sending HTTP requests as pipelines to optimize the use of full-duplex TCP connections.

3) both Apache and IIS support pipelines without any additional configuration.

3, avoid network requests.

1) with the basic principles of the HTTP caching mechanism, these rules can be used in iOS apps to cache content locally to avoid unnecessary network traffic.

2) HTTP is designed as a communication between the browser and the server, and the caching mechanism is for this usage pattern. iOS provides a mechanism to take advantage of the standard HTTP caching and to act accordingly. Each request made through nsurlrequest goes through the cache component. The component is an instance of Nsurlcache or its subclasses.

3) There is a strange phenomenon in iOS that, in some cases, the system components in the app set the cached memory capacity to 0, which disables caching. One way to resolve an unexplained behavior is to subclass the Nsurlcache by its own implementation. Denies setting the memory cache size to 0.

Third, iOS users want the app to respond to each request immediately. The mobile industry has a principle that the smaller the screen, the less patient the user is. Providing apps that make users happy to use means cherishing the user's time, just as you would cherish your own time. Optimize the bandwidth used by the application by compressing requests and responses, avoiding unnecessary delays through pipelining requests, and even avoiding redundant network requests by caching responses to accelerate applications and improve the user experience.

Reference: "iOS network advanced programming-iphone and ipad Enterprise application Development"

  

"Reading notes" iOS network-Optimizing request performance

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.