基础
字节序
小端:将低序字节存储在低地址 (0x01020304, 04存在低地址)
大端:将高序字节存储在低地址
(0x01020304, 01存在低地址)
网络字节序是大端字节序
dns优化
cache, multiple IPs
tcp优化
Delay-ack(200ms), ack with data send or timeout, TCP_QUICKACK(每次recv之后需要重设) 关闭之,
Nagle, collect and send on ack or timeout, TCP_NODELAY 关闭之
当TCP_CORK选项被设置时,TCP链接不会发送任何的小包,即只有当数据量达到MSS时,才会被发送。
tcp_defer_accept, 接收到SYN马上accept连接
tcp fast open, 第一次三次握手,后续直接在syn/syn-ack中带应用数据,为防止DOS,通过tcp-cookie进行验证。
![](https://i-blog.csdnimg.cn/blog_migrate/5c0c8ce368fc9f2935caaed767541eff.png)
SSL
tcp/ssl连接优化:重用连接,近距离代理
http优化
http2
http1.0 to http1.1
![](https://i-blog.csdnimg.cn/blog_migrate/10e4577b34df9545f726dc8921b09582.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f34c388672b01bace183c2747ec9ad92.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2b546b13d2e5668a3c066175883f5069.png)
http1.0/http1.1/SPDY/http2.0 (http2.0基于SPDY开发)
http1.0, one request
http 1.1, pipeline,
head-of-line blocking??
http2.0
wifi
![](https://i-blog.csdnimg.cn/blog_migrate/34cf0aa36cfbc62b8817832c609ccff2.png)
运营商网络
![](https://i-blog.csdnimg.cn/blog_migrate/7696a4efa0cb24b3108889d860ce852d.png)
![](https://i-blog.csdnimg.cn/blog_migrate/8507745a900f2999d92659f26ecde4d0.png)
![](https://i-blog.csdnimg.cn/blog_migrate/97a0bb7d5d0014b69a0f29d24b39dae2.png)
2G to 3G
![](https://i-blog.csdnimg.cn/blog_migrate/c816c733c5d4bd2955f18baf08ff5958.png)
![](https://i-blog.csdnimg.cn/blog_migrate/cc54c43844ece273832263b9aa77dc1b.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b6bd9d45d84c14056d9017114f0bcd68.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c0289997d4b3857c3621a57485ecf11e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a992625dc10acce28995121050e290a2.png)
full power/low power/standby
Returning to full power from the low state takes around 1.5 seconds, while moving from idle to full can take over 2 seconds.
![](https://i-blog.csdnimg.cn/blog_migrate/3486fbb913f2c2224ead1c63f7a78ca1.png)
So for a typical 3G device, every data transfer session will cause the radio to draw energy for almost 20 seconds.
When connected over a wireless radio, higher bandwidth generally comes at the price of higher battery cost. Meaning that LTE typically consumes more energy than 3G, which is in turn more expensive than 2G.
LTE architecture
![](https://i-blog.csdnimg.cn/blog_migrate/7c8935f6d5a573c6f7c9803f334d68a2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/22a4eff91cbb5054bd4e93dfef538c27.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2043473b043ede539ce5e61ad491e75f.png)
![](https://i-blog.csdnimg.cn/blog_migrate/bd4edd50ff4cb94845252feebd937429.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fccc48bd85c8cfca9980ce52330b082c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fff624af0c437d2c6b62c088fc8a82af.png)
![](https://i-blog.csdnimg.cn/blog_migrate/35dd51c91e6d5b55f308f011e673b524.png)
![](https://i-blog.csdnimg.cn/blog_migrate/37491e4a764c971f38b7199ad1c48ef5.png)
The Radio State Machine
另外一个概念是tcp连接时间
运营商网关保持internal-ip, 国内5/10min
application
Use urlconnection to support gzip by default.
image resize
GCM
port:5228,5229
/*
* packet(from server) format:
* header + playload
*
* header format:
* cmd + payload_len
*
* payload format:
* protobuf packet
*
* attention:
* the first byte from server doesn't belong to the first packet, need to remove it
* this byte could be the version or sth. else
*/
gcm heartbeat interval:
28mins -- mobile
15mins -- wifi
dynamic
WeChat
heartbeats every 4 ~ 5 minutes with 16 bytes
工具:
DDMS - Network Traffic Tool
tcpdump
ss
![](https://i-blog.csdnimg.cn/blog_migrate/4107afcf6cff3bbe082062a0aca6fcd0.png)
netstat
![](https://i-blog.csdnimg.cn/blog_migrate/9ead76004f76df19b82a6fade6faf8d9.png)
traceroute
![](https://i-blog.csdnimg.cn/blog_migrate/7c4c82003df1abd45100d770e6f4d763.png)
MobiPerf
Application Resource Optimizer by AT&T
![](https://i-blog.csdnimg.cn/blog_migrate/9fd8e80aeaf697af726eb573e3ef94c9.png)
参考:
<High Performance Browser Networking.pdf>
<Profiling Resource Usage for Mobile Application>
![](https://i-blog.csdnimg.cn/blog_migrate/a8d32876342052a364f128c2c0edb1bc.png)