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

Add compression strategy parameter to enable_compression method #5909

Closed
1 task done
shootkin opened this issue Jul 22, 2021 · 0 comments
Closed
1 task done

Add compression strategy parameter to enable_compression method #5909

shootkin opened this issue Jul 22, 2021 · 0 comments

Comments

@shootkin
Copy link
Contributor

Is your feature request related to a problem?

We use aiohttp server and StreamResponse.enable_compression() method for compression such data like images.
And under high load (when we downloading a lot of data by multiple clients) response.write() hangs with 100% CPU load.
After changing this line of code: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/http_writer.py#L66
from self._compress = zlib.compressobj(wbits=zlib_mode) to self._compress = zlib.compressobj(wbits=zlib_mode, strategy=zlib.Z_HUFFMAN_ONLY) the problem disappeared, CPU load decreased and response.write() didn't hang.

Describe the solution you'd like

Change this method from:

    def enable_compression(self, encoding: str = "deflate") -> None:
        zlib_mode = 16 + zlib.MAX_WBITS if encoding == "gzip" else zlib.MAX_WBITS
        self._compress = zlib.compressobj(wbits=zlib_mode)

to kind of that

    def enable_compression(self, encoding: str = "deflate", compression_strategy: str = "Z_DEFAULT_STRATEGY") -> None:
        zlib_mode = 16 + zlib.MAX_WBITS if encoding == "gzip" else zlib.MAX_WBITS
        self._compress = zlib.compressobj(wbits=zlib_mode, strategy=eval(f"zlib.{compression_strategy}"))

Describe alternatives you've considered

Have no idea about alternatives

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants