-
Notifications
You must be signed in to change notification settings - Fork 141
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
Consider making some sv1_api::IsServer
trait methods into async
#1358
Comments
cause otherwise the library would be very very impractical to use without an async runtime. The idea is that you don't block in the handler. Having them not async allow the handlers to be called from an async context and and from outside an async context. for me concept nack |
Hi, @ Fi3 I believe all code should be async, especially authentication flow. For example, we need to implement an HTTP request in this handler to get info miner is authenticated or no. If we implement it synchronously it will not work with high load as there will be thread blocking. |
Does this mean approximately this, or something else?
|
yea |
Can your words be interpreted as meaning there are no significant architectural obstacles to making the fn handle_authorize asynchronous? I'm referring to any potential pitfalls not immediately apparent from a superficial code review, but which could make such refactoring quite labor-intensive. |
It will not work properly when you connect 10k workers immediately |
I would not interpret it that way. Please keep in mind that all SRI low-level libs (under
by forcing them to be overall I tend to agree with @Fi3 that it doesn't seem to make sense to impose and if implemented correctly, |
isn't this something that could be handled at infrastructure level? |
Yes, that would be good, but fn handle_authorize is already called within the Tokio runtime, and any attempts to make it asynchronous result in an error. Using block_in_place, as Oleg mentioned, severely limits the system's ability to handle many concurrent connections (over 1,000). Oddly enough, the most stable result currently comes from using std::thread::spawn within fn handle_authorize to interact with the external authorization server. However, this seems to consume significantly more resources than an asynchronous approach would. In summary, for the time being, it still looks like we need to make fn handle_authorize and its related functions asynchronous. |
Why is it a problem that |
as @GitGab19 pointed out in a chat, one potential middle ground could be to expand perhaps a new trait called this way, we wouldn't force every consumer of the crate to use an async runtime, they could still use |
I did a quick experiment which consisted of:
the compiler built the code, but gave the following warning:
after googling for the waning message, the following resources come up: |
I made some extra progress on the experiment described above. I continued with the strategy of adding a new I kindly ask @mlgodskz and @AkulovOleg to do some validation. Please change your |
Currently, we're interacting with the external authorization server like this:
All other options either don't work because this function is already called within the Tokio runtime, or perform worse, such as using block_in_place(). Besides refactoring to async/await, what other optimizations could be applied here? |
@plebhash adding the async trait or an async method under a flage seems a good option. @mlgodskz In the meantime you can do something like the below, assuming that you have an IsServer for each dowstream, otherwise you can use almost the same logic (you hold on messages from a specific downstream not all messages). fn handle_authorize(&self, request: &client_to_server::Authorize) -> bool {
self.on_hold = true; // you put this dowstream on hold no processing new messages
self.authorize.send(request); // you send the message to a task that handle you authorization logic^1
false
} ^1 task will need to have |
If this is running in a tokio runtime, I would let tokio handle the threading. So using Maybe running |
an adopter asked why the Sv1 handlers are syncrhonous
more specifically, they reported that they are building an authentication flow that would be better if
sv1_api::IsServer::handle_authorize
were asyncThe text was updated successfully, but these errors were encountered: