Envoy代理在升级至v1.34版本后出现严重性能衰退,根本原因是将默认HTTP/2编码从nghttp2切换到Google的oghttp2[1]。这一改变导致CPU使用率上升20%,同时延迟增加15-25%[1]。
经过深入性能分析,问题根源并非oghttp2的Huffman解码器本身,而在于HTTP头部处理层面的低效率[1]。具体而言,std::string::push_back调用在HttpHeaderBlock层处理中占用了x86主机CPU的13-20%[1]。相比之下,nghttp2采用预计算的有限状态机解码方式,使用仅256字节的状态表存储于L1缓存中,而oghttp2逐字节处理导致大量内存分配检查,严重影响性能[1]。性能测试验证了这一问题在多种微架构上均存在,包括Intel Sapphire Rapids、AMD Zen 4、AWS Graviton4以及Google Axion[1]。
为解决此问题,Envoy在v1.37.0版本将默认编码切回nghttp2[1]。对于仍在使用v1.34至v1.36版本的用户,可通过设置运行时配置'envoy.reloadable_features.http2_use_oghttp2: false'来恢复性能[1]。
Envoy proxy experienced significant performance degradation after upgrading to version 1.34, which switched the default HTTP/2 codec from nghttp2 to Google's oghttp2 [1]. The change resulted in a 20% increase in CPU usage and a 15–25% increase in latency [1].
Performance analysis revealed that the bottleneck was not in oghttp2's Huffman decoder itself, but rather in the header processing layer [1]. Specifically, string operations and memory management within the HttpHeaderBlock layer became the primary performance constraint, with std::string::push_back calls accounting for 13–20% of CPU time on x86 hosts [1]. In contrast, nghttp2 uses a precomputed finite state machine approach with a 256-byte state table that fits in L1 cache, whereas oghttp2 processes bytes individually and triggers numerous memory allocation checks [1]. Testing was conducted across four microarchitectures: Intel Sapphire Rapids, AMD Zen 4, AWS Graviton4, and Google Axion [1].
To address the regression, Envoy reverted to nghttp2 as the default HTTP/2 codec in version 1.37.0 [1]. For users running versions 1.34 through 1.36, performance can be restored by setting the runtime configuration flag envoy.reloadable_features.http2_use_oghttp2: false [1].