diff options
author | Alexandre Flament <alex@al-f.net> | 2023-08-25 14:06:40 +0000 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2023-08-27 11:49:40 +0200 |
commit | 97b1df162983834423fdb6ae2863728fce4fe009 (patch) | |
tree | 6689aca24e0ac90156cf2286b3e454c69cb7dac4 /searx/network | |
parent | e16c007c220b405484dccc8e285b67bcd7c2b3bf (diff) | |
download | searxng-97b1df162983834423fdb6ae2863728fce4fe009.tar.gz searxng-97b1df162983834423fdb6ae2863728fce4fe009.zip |
[mod] searx.network: memory optimization
Avoid to create a SSLContext in AsyncHTTPTransportNoHttp
See:
* https://github.com/encode/httpx/blob/0f61aa58d66680c239ce43c8cdd453e7dc532bfc/httpx/_transports/default.py#L271
* https://github.com/encode/httpx/issues/2298
Diffstat (limited to 'searx/network')
-rw-r--r-- | searx/network/client.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/searx/network/client.py b/searx/network/client.py index ed1796515..23826c75d 100644 --- a/searx/network/client.py +++ b/searx/network/client.py @@ -61,11 +61,40 @@ def get_sslcontexts(proxy_url=None, cert=None, verify=True, trust_env=True, http class AsyncHTTPTransportNoHttp(httpx.AsyncHTTPTransport): - """Block HTTP request""" + """Block HTTP request + + The constructor is blank because httpx.AsyncHTTPTransport.__init__ creates an SSLContext unconditionally: + https://github.com/encode/httpx/blob/0f61aa58d66680c239ce43c8cdd453e7dc532bfc/httpx/_transports/default.py#L271 + + Each SSLContext consumes more than 500kb of memory, since there is about one network per engine. + + In consequence, this class overrides all public methods + + For reference: https://github.com/encode/httpx/issues/2298 + """ + + def __init__(self, *args, **kwargs): + # pylint: disable=super-init-not-called + # this on purpose if the base class is not called + pass async def handle_async_request(self, request): raise httpx.UnsupportedProtocol('HTTP protocol is disabled') + async def aclose(self) -> None: + pass + + async def __aenter__(self): + return self + + async def __aexit__( + self, + exc_type=None, + exc_value=None, + traceback=None, + ) -> None: + pass + class AsyncProxyTransportFixed(AsyncProxyTransport): """Fix httpx_socks.AsyncProxyTransport |