Neo-reGeorg
Neo-reGeorg copied to clipboard
请求使用httpx替代requests,使用http2的多路复用
trafficstars
httpx 支持http2, pip3 install httpx pip3 install 'httpx[http2]' requests.Session() 替换成 httpx.Client(http2=True)
使用http2的多路复用减少握手.
httpx.Client(http2=True) 会向下兼容 http1.0 http1.1 等吗?
感谢你的建议,由于下面的几点分析,这个性能效果并不会很明显,由于目前项目追求稳定性,暂不会加入,但后续测试http2能够稳定运行后加入支持~
- requests http1.1时,支持
Keep-Alive的方式减少tcp握手,所以http2的多路复用并不会给 neoreg 减少握手。 - http2 的 header 压缩可以减少一点上下行宽带,但是效果不大。
- http2 的多路复用,支持异步的请求方式,但是 neoreg write/read 行为是顺序的,或许能提高 write/read 的实时性。