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性能优 ...
随机推荐
- Linux下汇编语言学习笔记33 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- hdu - 2660 Accepted Necklace (二维费用的背包问题)
http://acm.hdu.edu.cn/showproblem.php?pid=2660 f[v][u]=max(f[v][u],f[v-1][u-w[i]]+v[i]; 注意中间一层必须逆序循环 ...
- CLR运行机制
CLR编译器会将我们的代码编译成托管模块(中间IL语言和元数据),托管模块是一个标准的PE32执行文件,或者PE32+执行文件.但是CLR实际不和托管模块一起工作,他会将托管模块合并成程序集,程序集是 ...
- 洛谷——P1062 数列
洛谷——P1062 数列 题目描述 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12,1 ...
- Linux系统备份还原工具1(DD)(应用实例)
DD使用教程:http://www.cnblogs.com/EasonJim/p/7442223.html 以下实例没经过大量测试,可能在一些机器上不会有效. 一般围绕以下几点进行设置: 1.dd完后 ...
- jmeter的Classpath即类或者jar包的搜索路径设置
对于master-slave模式,插件和依赖都需要放到slave上才能生效,并且需要重启slave使插件生效 查看配置文件:apache-jmeter-3.1/bin/jmeter.propertie ...
- HDU 1231——最大连续子序列(DP)
最大连续子序列 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- 三分钟迁移Spring boot工程到Serverless
前言 Spring Boot已成为当今最流行的Java后端开发框架,典型的应用方式是在云上购买一台虚拟机,每天24小时在上面运行Java程序,在这种情况下,用户必须维护自己的虚拟机环境,而且按照包月包 ...
- Echarts 如何使用 bmap 的 API
使用 Echarts 在绘制 Binning on map 的图形时(其实也就是 在地图上绘制热力色块图) 解决因为数据量过大,希望在拖拽加载或者缩放加载的时候,根据可视区域的经纬度范围,来请求相应的 ...
- [Java] 监控java对象回收的原理与实现
监控Java对象回收的原理与实现 一.监控Java对象回收的目的 监控Java对象是否回收的目的是:为了实现内存泄露报警. 内存泄露是指程序中对象生命周期(点击查看详情)已经进入不可见阶段,但因为编码 ...