Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Proof of concept: Quart #1724

Closed
wants to merge 4 commits into from
Closed

Proof of concept: Quart #1724

wants to merge 4 commits into from

Conversation

dalf
Copy link
Contributor

@dalf dalf commented Oct 16, 2019

asyncio demo / proof of concept:

what is not working:

related to #904 (comment)
whatever benchmark results are:

  • P2P idea #792 (or a similar idea) requires most probably persistent connections. asyncio would avoid numerous threads.
  • (compare to uwsgi) one process would help to have more accurate statistics (instead of getting the stats for one uwsgi process).
  • (compare to uwsgi) one process makes embed searx-checker implementation easier (avoid file / whatever synchronization to avoid multiple checks, one per process).
  • if the image proxy is fast enough, morty could be used only when the admin wants to provide a html proxy. Not sure if httpx (or aiohttp) could be as fast as valyala/fasthttp

@dalf
Copy link
Contributor Author

dalf commented Nov 15, 2019

See https://github.com/dalf/searx/tree/quart_aiohttp for a try of quart + aiohttp as a client.
It seems slower that quart + httpx.

Quart

Notes about quart:

Dirty workaround idea about the last point: monkey patch quart.templating._render to render the template in a ThreadPool using asyncio.loop.run_in_executor

httpx

httpx is based on h11 and h2. Both use the bring-your-own-I/O principle.
README.md says:

This project should be considered as an "alpha" release. It is substantially API complete, but there are still some areas that need more work.

HTTP/1.1 and HTTP/2

I agree, after doing some requests:

  • HTTP/2 supports seems cause issue here and there (it is possible to disable it)
  • HTTP/1 has also issues too to deal with broken servers (requests, pycurl works not httpx on some requests).
  • But to send requests to wikipedia, duckduckgo, etc... it is okay (without HTTP/2).

Proxy and connection reuse

After we receive the 2XX response from the proxy that our tunnel is open we switch the connection's origin to the original so the tunnel can be re-used.

aiohttp

aiohttp uses C to provide an server and a client.
See https://github.com/aio-libs/aiohttp/tree/master/aiohttp
The library declares itself as "5 - Production/Stable".

HTTP/2

The HTTP client doesn't support HTTP/2 : aio-libs/aiohttp#863 (comment)

Anyway it seems as fast as pycurl, see https://github.com/dalf/searx/blob/pycurl-2nd-edition/misc/httpclient_bench.py

Proxy and connection reuse

Many HTTP proxies has buggy keepalive support. Let's not reuse connection but close it after processing every response.

Which path ?

I think a full aiohttp searx version should be tried:

This was referenced Jan 31, 2020
@nfk
Copy link
Contributor

nfk commented Feb 3, 2020

Hi @dalf, I had tested aiohttp few months ago. I had abandoned the idea because I did want to move apart from upstream.

You can see my work here after removing python2 support

Whatever moving to ASGI is a really good idea. Starting with quart is probably a reasonable choice to move the project toward asyncio.

@dalf dalf mentioned this pull request Jun 20, 2020
@dalf
Copy link
Contributor Author

dalf commented Dec 3, 2020

See #2313

@dalf dalf closed this Dec 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants