Objective
First, reducing latency through persistent connections, near access (such as CDN), optimizing TLS deployments, and other protocol optimization strategies is more important for mobile applications. However, latency and throughput are important for mobile applications. In mobile application development practice, it is necessary to consider how to display content under the restriction of device form, also consider the performance characteristics of radio interface, and the limited power of equipment. There are many factors that affect the mobile application experience, but the transmission delay, time jitter, unreasonable network operation cause the power consumption is too large is the most important. The following describes performance tuning recommendations for wireless and power limits for mobile networks.
1. Save Electricity
The performance of the mobile network is closely related to the battery life time. To conserve power, the physical layer of the wireless interface has been optimized for the following limitations:
- Full power turns on the radio module for a few hours to drain power;
- The demand for radio power increases with the evolution of wireless standards;
- The power consumption of the radio module is second only to the device screen;
- The power consumption process of radio communication is non-linear during data transmission.
So, since the radio module consumes so much power, it is necessary to use as few radio interfaces as possible when developing applications. If there is a data transfer requirement, transmit the data as much as possible when the radio is on, minimizing the number of wake-up radios to transmit data.
Note: Although wireless interfaces are also required for data transfer using Wi-Fi, the underlying mechanism and latency, throughput, and power consumption characteristics of the mobile network and Wi-Fi are different. WiFi standard connection mode is the device can communicate at any time, the corresponding radio module is always on, the power consumption is very large. This problem has an optimization strategy, that is, the wireless access point before sending data to the target device, send a periodic signal frame broadcast Dtim (send data indicating message), the device received Dtim frame after the corresponding preparation, open the radio module to receive data, other times the radio device is dormant. If the device is sending data outward, the general process is reversed. This optimization saves power, but increases the latency.
2. Elimination of periodic and invalid data transfer
As long as the data transfer, regardless of the size of the transmission volume, the Radio module is always in high power state, there is no low demand for electricity. The following optimization rules are available:
- Polling is very expensive and less used in mobile networks;
- Use push and notifications whenever possible;
- Outbound and inbound requests should be consolidated and aggregated;
- Noncritical requests should be deferred until the wireless module is active.
In general, push is better than polling, but there is little difference between pushing and polling with too much frequency. If there is a need for real-time updates, you should consider the following issues:
- How long is the best update interval, and does it meet user expectations?
- In addition to the fixed update interval, can the ground timely?
- Can inbound or outbound requests be set to fewer network calls?
- Can the inbound or outbound request be postponed to a later time?
Note: Native apps can access platform-specific push services, so use them as much as possible, and Web apps can use servers to send events and websocket to reduce latency and protocol consumption, without the use of polling and XHR techniques whenever possible.
eliminate the necessary long connections : Although the status and lifecycle of TCP/UDP connections in a mobile network are independent of the wireless state of the devices, unnecessary long connections can also lead to significant power consumption.
3. Predicting Network latency Limits
In a mobile network, an HTTP request (DNS, TCP, TLS, and so on) can cause a delay of up to hundreds of or even thousands of milliseconds, many of which are unpredictable and vary. For the uncertainty of latency, mobile applications need to do the worst, predicting the maximum value of latency, giving users friendly feedback and user experience.
Latency estimate for an HTTP
Consider RRC State switching
If the mobile device is idle, the first packet will result in an additional RRC delay of hundreds of or even thousands of milliseconds. Experience has shown that 4G networks or increased 100ms,3.5g+ networks increase 150ms-500ms, while 3G networks increase the control surface delay of 500-2500ms.
Although the mobile network will give people a feeling of always-on-line, but its physical layer is constantly connected and disconnected. This delay is considered to affect the user experience.
Decoupling user interaction and network communication
Good application, even if the underlying connection is slow or the request time is long, at the UI level to give users good feedback can also make people feel fast. So, do not connect user interaction with network communication too tightly.
When sending a network request, do not forget to give the user feedback, reduce the user's sense of delay. Due to the uncertainty of delay, it is necessary to predict the maximum value to prepare.
4. Facing the reality of multi-network interface coexistence
Apps that don't run smoothly are not appealing to users, but the worst-case scenario is that the application crashes due to a short network problem. In the development of mobile applications, we need to be prepared for a variety of network problems, such as: Unable to access the host, a sudden decline or rise in throughput, disconnection, and so on. Wired networks generally after the establishment of the connection, the subsequent connection is generally relatively stable, but in the mobile network is a change, the user may move, may also enter the conflict, multi-user or poor signal area, which will affect the network conditions.
In the application design and development process, can not only consider the latest mobile network, but also consider 2G, 3G, 4G, WiFi and other network environment, to these network migration to make corresponding adjustments and preparation. There should be a corresponding estimate and response for the change of communication quality caused by the distance of Signal tower, active users, environment conflict, different time periods and other non-measurable factors.
In any network environment, it is extremely difficult to predict the end-to-end bandwidth and latency, especially for mobile networks. In this case, it should be based on the relevant network belongs to the generation of coarse-grained information adjustment code, although not accurate prediction of network delay, but can be based on network generation to know the first hop delay time, as well as the operator network end-to-end parameter information. In addition to the above factors need to be considered, but also the connection interruption as the norm.
Keep your app running, regardless of network conditions, and respond to request types and specific scenarios:
- Do not cache or attempt to guess network status;
- Dispatching requests, monitoring and diagnosing errors;
- Instantaneous error will always occur, can not be ignored, may take the retry strategy;
- Listen to the connection status, so as to use the best request mode;
- The compensation algorithm is used to retry the request, do not cycle forever;
- When offline, record and request in the future as much as possible;
- Take advantage of HTML5 's AppCache and localstorage for offline applications.
5. Burst transmit data and become idle
Mobile wireless interfaces are optimized for burst transmissions and should be used more. Data each transmission will be the radio interface in high power state, if the data transmission interval time is large, the data volume is very large, then each data transmission will be frequent wake Radio module, limited to the mobile network itself mechanism problems, which caused many in high power state of the time period no data transmission tasks, A huge waste of limited power resources.
In mobile applications, the gradual loading of resources is not a good practice, as this can result in uncertain throughput and latency and more power consumption. As a result, you should try to set the user's possible data in advance to download, so that the device at other times idle. The recommendations are as follows:
- If you need a large audio or video file, consider downloading the entire file in advance, rather than streaming it in bits;
- Pre-acquired application content, using measurement and statistical tools to identify the content that needs to be downloaded in advance;
- Pre-obtain third-party content, such as ads, to display and update their status in advance by applying logic;
- Allow the device to turn off the radio module, keep it idle, and do not forget to optimize and eliminate intermittent transmissions.
6. Transfer the load to a Wi-Fi network
WiFi network rate is more stable, and there is no traffic limit, can save the user mobile traffic usage.
Due to the mechanism of WiFi itself, it is more power-saving and RRC, and the delay is more stable when big data is transmitted. Mobile apps should be able to upload and download data in WiFi scenarios when large amounts of data are needed.
7. Best practices for compliance with protocols and applications
Network is layered design and architecture, the underlying physical network optimization is important, but all considerations are also necessary, such as TCP optimization, UDP optimization, TLS optimization and so on.
Related articles
- Introduction and RRC of mobile network
- Mobile network architecture and data transmission
- Mobile network optimization
Mobile network optimization