Android 性能优化(6)网络优化( 2) Analyzing Network Traffic Data:分析网络数据
Analyzing Network Traffic Data
1.This lesson teaches you to
In the previous section, you tagged your app code with traffic identifiers, ran tests, and collected data. This lesson teaches you how to look at the network traffic data you have collected and directs you to actions for improving your app's networking performance and reducing power consumption.
2.Analyze App Network Traffic
Efficient use of network resources by an app is characterized by significant periods where the network hardware is not in use. On mobile devices, there is a significant cost associated with starting up the radio to send or receive data, and with keeping the mobile radio active for long periods. If your app is accessing the network efficiently, you should see that its communications over the network are tightly grouped together, well spaced with periods where the app is making no connection requests.
Figure 1 shows suboptimal network traffic from app, as measured by the Network Traffic tool. The app is making frequent network requests. This traffic has few periods of rest where the radio could switch to a standby, low-power mode. The network access behavior of this app is likely to keep the radio on for extended periods of time, which is battery-inefficient.
图1是不规范的网络请求,分析截图。

Figure 1. Battery-inefficient network activity measured from an app.
Figure 2 shows an optimal network traffic pattern. The app sends network requests in bursts, separated by long periods of no traffic where the radio can switch to standby. This chart shows the same amount of work being done as Figure 1, but the requests have been shifted and grouped to allow the radio to be in standby most of the time.
规范的网络请求会产生如下的图,它们分组的,这样网络设备就有空余时间。上图那个太频繁。

Figure 2. Battery-efficient network activity measured from an app.
If the network traffic for your app looks similar to the graph in Figure 2, you are in good shape! Congratulations! You may want to pursue further networking efficiency by checking out the techniques described in Optimizing General Network Use
If the network traffic for your app looks more like the graph in Figure 1, it's time to take a harder look at how your app accesses the network. You should start by analyzing what types of network traffic your app is generating.
3.Analyze Network Traffic Types
When you look at the network traffic generated by your app, you need to understand the source of the traffic, so you can optimize it appropriately. Frequent network activity generated by your app may be entirely appropriate if it is responding to user actions, but completely inappropriate if you app is not in the foreground or if the device in a pocket or purse. This section discusses how to analyze the types of network traffic being generated by your app and directs you to actions you can take to improve performance.
In the previous lesson, you tagged your app code for different traffic types and used the Network Traffic tool to collect data on your app and produce a graph of activity, as shown in Figure 3.

Figure 3. Network traffic tagged for the three categories: user, app, and server.
The Network Traffic tool colors traffic based on the tags you created in the previous lesson. The colors are based on the traffic type constants you defined in your app code. Refer back to your app code to confirm which constants represent user, app, or server-initiated traffic.
The following sections discuss how to look at network traffic types and provides recommendations on how to optimize traffic.
3.1 Analyzing user-initiated network traffic
Network activity initiated by the user may be efficiently grouped together while a user is performing a specific activity with your app, or spread out unevenly as the user requests additional information your app needs to get. Your goal in analyzing user-initiated network traffic is to look for patterns of frequent network use over time and attempt to create, or increase the size of, periods where the network is not accessed.
The unpredictability of user requests makes it challenging to optimize this type of network use in your app. In addition, users expect fast responses when they are actively using an app, so delaying requests for efficiency can lead to poor user experiences. In general, you should prioritize a quick response to the user over efficient use of the network while a user is directly interacting with your app.
Here are some approaches for optimizing user-initiated network traffic:
- Pre-fetch Network Data - When the user performs an action in your app, the app anticipates which data may be needed for the next user actions, fetches it in bulk in a single connection, and holds it until the user requests it.
- Check for Connectivity or Listen for Changes - Check for network connectivity or listen for connectivity changes before performing an update.
- Reduce the Number of Connections - Use server APIs that allow data to be downloaded in sets.
Caution: Beware of network activity grouping bias in your user activity test data! If you ran a set of user scenarios with your network testing plan, the graph of user-initiated network access may be unrealistically grouped together, potentially causing you to optimize for user behavior that does not actually occur. Make sure your user network test scenarios reflect realistic use of your app.
3.2 Analyzing app-initiated network traffic
Network activity initiated by your app code is typically an area where you can have a significant impact on the efficient use of network bandwidth. In analyzing the network activity of your app, look for periods of inactivity and determine if they can be increased. If you see patterns of consistent network access from your app, look for ways to space out these accesses to allow the device radio to switch into low power mode.
Here are some approaches for optimizing app-initiated network traffic:
- Batch and Schedule Network Requests - Defer your app's network requests so they can be processed together and at a time which is advantageous for battery life.
- Allow System to Check for Connectivity - Avoid the battery cost of running your app just to check for a network connection when you can let the system run the check while your app sleeps.
3.3 Analyzing server-initiated network traffic
Network activity initiated by servers communicating with your app is also typically an area where you can have a significant impact on the efficient use of network bandwidth. In analyzing the network activity from server connections, look for periods of inactivity and determine if they can be increased. If you see patterns of consistent network activity from servers, look for ways to space out this activity to allow the device radio to switch into low power mode.
Here is an approach for optimizing app-initiated network traffic:
- Use GCM for Server Updates - Consider using the Google Cloud Messaging service for server side updates instead of polling.
Android 性能优化(6)网络优化( 2) Analyzing Network Traffic Data:分析网络数据的更多相关文章
- Android 性能优化(5)网络优化 (1) Collecting Network Traffic Data 用Network Traffic tool :收集传输数据
Collecting Network Traffic Data 1.This lesson teaches you to Tag Network Requests 标记网络类型 Configure a ...
- Android性能优化典范第二季
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitma ...
- Android性能优化典范(二)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- android app性能优化大汇总(google官方Android性能优化典范 - 第2季)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- Android性能优化典范 - 第2季
Google发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的缩放,缓 ...
- Android性能优化问题总结
性能优化这块,分为UI性能优化.内存优化.数据库优化.网络优化.耗电优化等等.可以从1.如何发现问题,2.怎么解决问题,3.解决效果对比,这几个方面去描述.举个简单例子——UI优化,可以从 UI出现什 ...
- Android 性能优化探究
使用ViewStub动态载入布局.避免一些不常常的视图长期握住引用: ViewStub的一些特点: 1. ViewStub仅仅能Inflate一次,之后ViewStub对象被置空:某个被ViewStu ...
- 我把阿里、腾讯、字节跳动、美团等Android性能优化实战整合成了一个PDF文档
安卓开发大军浩浩荡荡,经过近十年的发展,Android技术优化日异月新,如今Android 11.0 已经发布,Android系统性能也已经非常流畅,可以在体验上完全媲美iOS. 但是,到了各大厂商手 ...
- 【腾讯Bugly干货分享】Android性能优化典范——第6季
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/580d91208d80e49771f0a07c 导语 这里是Android性能优 ...
随机推荐
- operamasks-omGrid的使用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="personTab.aspx ...
- mvn打包源码的方法:maven-source-plugin
maven-javadoc-plugin可以打包 dubbo-demo-provider-2.6.1-javadoc.jar maven-jar-plugin 打包插件 dubbo-demo-prov ...
- Application特征
1.位置:服务器内存,执行速度快2.使用范围:整个应用程序3.类型:任意类型4.声明周期:应用程序开始创建到销毁
- linux netlink套接字实现相似ss命令 ,统计套接字以及TCP信息
參考了 ss的源码 以及 netlink相关资料:http://blog.csdn.net/scdxmoe/article/details/27711205 实现结果为: gcc netlink_di ...
- vs2013生成lib
引擎cocos2d-x-3.1.1 一. cocos创建一个项目.随便是lua还是cpp.这里用cpp演示 二.创建完毕之后执行下项目 之后创建两个类.例如以下 TestLib.cpp文件 #incl ...
- 基于MFC的一个简单计算器
写一个简单的计算器并不是什么很难的事,主要目的是要通过这个程序来学习和分析其中的核心算法.这个简易计算器的核心部分就是对输入的表达式的正确性判断与求值,其中包括对表达式的解析.中缀表达式转后缀表达式. ...
- redis 事务 及发布于订阅功能
事务: Redis事务可以一次执行多个命令,事务具有以下特征: 1.隔离操作:事务中的所有命令都会序列化.按顺序地执行,不会被其他命令打扰. 2.原子操作:事务中的命令要么全部被执行,要么全部都不执行 ...
- linux用户进程分析
经过实验3的介绍.我们须要来点实在的.所以将我们理解的流程用于linux系统的分析.换句话说.通过类比的方式去进行描写叙述与理解linux相关的部分. 本节的内容非常详实.并且也分析 ...
- 【C/C++多线程编程之五】pthread线程深入理解
多线程编程之pthread线程深入理解 Pthread是 POSIX threads 的简称,是POSIX的线程标准. 前几篇博客已经能给你初步的多线程概念.在进一步学 ...
- dm385和8127的区别
DM385/DM8127在ITS智能交通中的应用分析德州仪器(TI)自推出DM385和DM8127视频处理器在业界反响很大特别是深圳安博会上展出的1080P60帧高清效果之后很多龙头企业也跃 ...