涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

性能包括2部分

每秒并发请求数(Number of concurrent requests per second)
每秒请求负载(Request latency in seconds: min/average/max time to complete a request)

Architecture: Worker processes

由于python的全局锁(GIL),程序只能运行在单核上,为增加并发处理能力,一个解决方案是分布在多个工作进程

Stream limits

aiohttp使用set_writer_buffer_limits(0)方法以支持反压力(backpressure),实现缓存(buffer)

TCP_NODELAY

3.6版本开始,asyncio在新建socket的同时,可以设置TCP_NODELAY选项,在发送合并(coalescing)的时候禁用Nagle算法 

Nagle算法
以他的发明人John Nagle的名字命名的,它用于自动连接许多的小缓冲器消息;这一过程(称为nagling)通过减少必须发送包的个数来增加网络软件系统的效率

TCP_QUICKACK

TCP_QUICKACK(TCP延迟确认机制),用于让本端立即发送ACK,而不进行延迟确认。asyncio默认不使用这个选项

Tune the Linux kernel

/proc/sys/net/ipv4/tcp_mem

/proc/sys/net/core/rmem_default and /proc/sys/net/core/rmem_max: 
The default and maximum amount for the receive socket memory

/proc/sys/net/core/wmem_default and /proc/sys/net/core/wmem_max: 
The default and maximum amount for the send socket memory

/proc/sys/net/core/optmem_max: 
The maximum amount of option memory buffers

net.ipv4.tcp_no_metrics_save

net.core.netdev_max_backlog: 
Set maximum number of packets, queued on the INPUT side, when the interface receives packets faster than kernel can process them.
posted on 2018-03-19 12:06  北京涛子  阅读(293)  评论(0编辑  收藏  举报