Neo-reGeorg icon indicating copy to clipboard operation
Neo-reGeorg copied to clipboard

请求使用httpx替代requests,使用http2的多路复用

Open ilpl opened this issue 3 years ago • 2 comments
trafficstars

httpx 支持http2, pip3 install httpx pip3 install 'httpx[http2]' requests.Session() 替换成 httpx.Client(http2=True)

使用http2的多路复用减少握手.

ilpl avatar Jan 07 '22 22:01 ilpl

httpx.Client(http2=True) 会向下兼容 http1.0 http1.1 等吗?

L-codes avatar Jan 08 '22 02:01 L-codes

感谢你的建议,由于下面的几点分析,这个性能效果并不会很明显,由于目前项目追求稳定性,暂不会加入,但后续测试http2能够稳定运行后加入支持~

  1. requests http1.1时,支持Keep-Alive的方式减少tcp握手,所以http2的多路复用并不会给 neoreg 减少握手。
  2. http2 的 header 压缩可以减少一点上下行宽带,但是效果不大。
  3. http2 的多路复用,支持异步的请求方式,但是 neoreg write/read 行为是顺序的,或许能提高 write/read 的实时性。

L-codes avatar Jan 08 '22 02:01 L-codes