-
Notifications
You must be signed in to change notification settings - Fork 222
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
expose eventloop to allow timeouts to be set #14
Comments
I won't expose the event loop, but timeouts have been a goal since I started this project. This feature will be implemented. However, I am still grappling with the best way to provide timeouts in the API without forcing users who don't care about them to need to provide a timeout message. I am wondering if this needs to wait until we have associated type defaults: rust-lang/rust#29661. If you have suggestions, or want to implement this yourself, please go right ahead. In the meantime, you can do what you want by adding another component to the system using a separate thread. The pong example shows how to do this. |
Why are you against exposing the event loop? |
TL,DR: I'm following the design implications of the MIO library and the current Rust ecosystem. There are basically three, interrelated reasons why I won't expose the EventLoop to code clients.
However, I do want to allow people to use timeouts. Right now the timeout implementation is In the meantime, I think that a single thread timer won't be any discernible performance penalty for you. In fact, I modified the pong example so that it checks latency every 1 second (instead of every 5), and I left the print the latency calls (which means there is all that overhead related to printing to stdout), and at 10,000 connections sending 10 messages each, the pong example completed in only 3644ms (about twice as long as the raw benchmark, I know, but printing is expensive. FYI, I left the printing in because I didn't want rust to optimize away the unused latency computation.) Anyway, that's still much faster than the last time I benchmarked |
Nice insights! I'm interested (and not that much familiar with sasync io): With es-rs, if I get a request and the processing function is very complex. Will this block all other requests? If so, should I spawn a thread from the on_open function? What are the alternatives? |
Thanks for the detailed answer. I really appreciate it. Since by design the EventLoop is not for reshare that's ok. I didn't dig too much into the implementation details of MIO because through your library this is the first time I am using it. I moved away from websocket-rs because the model there required that I use 3 threads per connection to do what I want and teardown/shutdown became a headache. Not only that but the library was failing with broken pipe after long sessions and that's not good for my application. Adding more threads is sometimes a performance problem but there is a cognitive problem as well. In this case the latter is much larger than the former: you need a thread to run the timer, don't forget to join on it because you will leak and have shared state between them (the latency). If this could be accomplished in a single thread the code would be much less complicated. So back to the original point:
Is there a plan to add Timeout in the near future? If not maybe you can give some insight for someone who might want to implement this functionality? |
I understand, the cognitive burden of threads can be a pain. As far as timeout support, since you are interested, and you have the only active issue on github right now, I feel that I should move this to the top of my todo list. I think I have a plan for how to do timeouts without negatively impacting the current API or requiring associated type defaults. Give me to Friday, and hopefully I will have an implementation of this feature for you to try out. |
That's great! Thanks for taking this on. |
The timeout feature is now in master. If you want, please try out the new pong example to see if the feature is what you were looking for. |
This is great Jason. Thanks for taking a stab at it. What's unfortunate is that |
Rust's borrow checker forbids holding a reference in the |
I can think of a way to make this synchronous but it involves quite a bit of state in the library and I don't like the tradeoffs :-). The name bothers me a bit as too similar to on_timeout. How about on_timeout_scheduled? |
I considered |
I am going to publish the API as is, but I am certainly open to changing the names if it bothers more people. |
Thanks Jason. I am using it already. |
This will make it possibe to run a single client handler that sends periodic pings to a server possible.
The text was updated successfully, but these errors were encountered: