Replies: 4 comments 4 replies
-
|
TLDR: are there use cases for the multi_requests function other than the baidu engine? A note about async HTTP client and the multi_requests function As its name says, the function sends multiple requests at the same time. The function returns all the responses at once. All other HTTP requests can run in the sync world: there is no parallelism in the engine code. However, in the master branch, all outgoing HTTP requests are sent through async HTTP clients. There are bridges from sync to async and vice versa. There was at a time when SearX(NG) was supposed to switch async entirely: https://github.com/searx/searx/wiki/Milestones#milestone-12---async Async is (nearly|for sure) an anti-pattern in a Flask application: if we need parallelism, the way to go is thread. Also, async makes the HTTP streaming complex. After each change, I ask someone on the team (usually Paul) to deploy it on a public instance and monitor for memory leaks. So #2685 drops all async code and relies only sync HTTP client ... and the multi_requests is dropped too: this function is not used (the Bing engine used it, but not anymore). The only potential use case for the
So my question is: Are there other use cases for the |
Beta Was this translation helpful? Give feedback.
-
|
One significant improvement in terms of latency and reliability can be achieved by sending multiple requests at once, while waiting for the first answer. This is easily done using asyncio. Works like charm with tor, which is otherwise slow and blocked many times by downstream engines. |
Beta Was this translation helpful? Give feedback.
-
From my understanding, async is not the same as parallel. Even if its one task, not blocking on an HTTP request gives back resources so other threads can run for the same application.
Sync will definitely be faster on instances that aren't handling many requests, but high volume instances I'd expect Async will allow better sharing of resources. If it was an anti-pattern in flask, seems very strange to have async docs. What they state is also aligned with my understanding of async as well.
With this, I believe SearXNG actually falls in this category - the whole job is to make outbound IO requests to third party search engines for most requests. However, there is a disclaimer from their docs regarding async code being less performant though...
What would be interesting is to see how we can propagate
With the above, some things I think may be interesting to investigate
|
Beta Was this translation helpful? Give feedback.
-
Disclaimer:
My main concern about full async (web framework, HTTP client, engines) : if one engine is slow, everything else slows down. I ended up with some weird things like this to improve the response time. With a single thread to handle async code (by design in Python), we have to be very careful everywhere (also related to my comment on httpx below). Few years ago I though about this architecture:
... this does not fit with the concept of HTTP server for Python app that take control of the app (like uwsgi and all others). Web frameworkQuart prototypeComments to take with pinch of salt, from what I remember:
I know this is not quantitative... Starlette:There is no proper support for babel: Kludex/starlette#279 Clienthttpxhttpx is a good example of well written code and carefully tested, however the async code has a lot of 4 years ago, I tried to benchmark httpx : https://github.com/dalf/pyhttp-benchmark/blob/master/results/output.md Without success, I've tried various things to improve the speed:
I've seen that homeassistant use zlib-ng, perhaps this can help. pycurlpycurl is a binding to the system libcurl, and there are a lot of different version of libcurl. I've stopped the POC when I encountered a segfault using HTTP/2 on Ubuntu 18.04. That was a six years ago, perhaps things has changed since then. aiohttpThere is no support for HTTP/2 which really help to avoid CAPTCHA for some engines (I don't remember which one, @unixfox has a better knowledge on this topic). Actually we could use this for the image proxy. HTTP serverRelated, more or less out of topic: perhaps, a good replacement for uwsgi is granian which support WSGI or ASGI apps. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There is WIP / unfinish PR about the network stack, see #2685
I open the discussion to collect ideas about possible improvement on the network stack ?
What would like to be able to do regarding the network?
What bother you in the current implementation?
Beta Was this translation helpful? Give feedback.
All reactions