Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling header compression #780

Open
xuorig opened this issue May 18, 2024 · 2 comments
Open

Allow disabling header compression #780

xuorig opened this issue May 18, 2024 · 2 comments

Comments

@xuorig
Copy link

xuorig commented May 18, 2024

Header compression, while very effective in some contexts, does have a CPU overhead on encode and decode. There are other contexts where this overhead is not worth it, for example in scenarios where bandwidth and data-transfer times are non-issues.

Other h2 implementations, like Envoy's for example, allow effectively disabling header compression by setting the HPACK table size to 0.

Right now, it's possible to set a table size on h2's client, and to set it to 0, but it does not necessarily lead to performance gains. This is because entries are simply evicted when max_size is reached. In fact, a table with max_size of 0 would most likely hit the "large header special case" and returned NotIndexed. This means that encode_str is still called (with huffman) through encode_not_indexed.

I'd like to hear your thoughts on how/if it should be possible to disable (similar to envoy) either through a table_size of 0, or even an explicit configuration option. Then, if possible, we should find a way to avoid huffman encoding in those cases and write header bytes without compression.

@seanmonstar
Copy link
Member

I read up again on HPACK encoding, and noticed it says:

The literal representation of a header field name or of a header field value can encode the sequence of octets either directly or using a static Huffman code (see Section 5.2).

I imagine people could want to take advantage of the Huffman compression even if it wouldn't be stored in the dynamic table, if reducing bytes is important. So then, it would seem to me that having the table size and whether compression is used be separate configuration would be more useful to people.

Does that seem right? Or did I miss something somewhere else?

@xuorig
Copy link
Author

xuorig commented May 21, 2024

Yeah that seems right to me too @seanmonstar, we can probably be more explicit if you don't mind the addition a new knob.

In our context both the encoding (majority of it) and table indexing seems to consume cycles that we don't necessarily need. Even table size 0 has some overhead when it comes to table operations it seems, so maybe a "dont compress headers" setting would be best in that scenario.

flamegraph:

Screenshot 2024-05-21 at 11 43 02

Zoomed in:

Screenshot 2024-05-21 at 11 45 57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants