Skip to content
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

Pure tokio #17

Merged
merged 5 commits into from
Jun 20, 2021
Merged

Pure tokio #17

merged 5 commits into from
Jun 20, 2021

Conversation

JackThomson2
Copy link
Contributor

Here's another proposal which massively reduces the complexity of the project by leveraging Tokio's multi-threaded runtime

Would probably need some benching marking on your machine, for me it appears to be faster.

Jack

@JackThomson2
Copy link
Contributor Author

In my tests this is 2x as fast

@sansyrox
Copy link
Member

Hey @JackThomson2 , Thank you for the contribution! 😄
I will try to run the benchmarks on my machine and will confirm regarding the tokio runtime. But I have also heard that tokio works better than async-std.

However, I do have a question regard this implementation. I created a separate thread for the TCPListener as I am planning to introduce multiple processes as well in the future.
I planned to share the stream object among multiple process(this is just a plan atm) . What according to you will having everything in the main thread change in this process?

@sansyrox
Copy link
Member

In my tests this is 2x as fast

@JackThomson2 , what kind of tests are you using?

@JackThomson2
Copy link
Contributor Author

Hey!

This should work with multiple processes, the tokio spawn will share the load between the different cores, if you where to use this multiple times it should be fine and tokio should just work it all out! For testing I was timing your ping script and simply testing response times on chrome as well. Very crude tests but looked positive. Any questions let me know

@JackThomson2
Copy link
Contributor Author

@sansyrox I've just pushed an update which will stop slow clients, by spawning on recieve.

@sansyrox
Copy link
Member

sansyrox commented Jun 19, 2021

This should work with multiple processes, the tokio spawn will share the load between the different cores, if you where to use this multiple times it should be fine and tokio should just work it all out!

@JackThomson2 Just a clarification, now with tokio added, we won't have to spawn a process(something like this https://doc.rust-lang.org/std/process/struct.Command.html) to spread the request across different cores. Tokio will handle it automatically?
If that is the case, I will try to learn about tokio in more detail.

@sansyrox I've just pushed an update which will stop slow clients, by spawning on receive.

Thank you so much! I just saw it, it looks good! 🚀

@JackThomson2
Copy link
Contributor Author

JackThomson2 commented Jun 19, 2021

@sansyrox Yes exactly! A better explanation can be found here https://docs.rs/tokio/1.7.1/tokio/runtime/index.html#multi-thread-scheduler but basically it uses a work stealing algorithm between cores for scheduling.

@sansyrox
Copy link
Member

@JackThomson2 , this looks really good. Can you change this to a normal PR so we can review it.

  • Can you change src/threadpool.rs to a different name?

@JackThomson2 JackThomson2 changed the title [DRAFT] Pure tokio Pure tokio Jun 20, 2021
@JackThomson2 JackThomson2 marked this pull request as ready for review June 20, 2021 16:25
@sansyrox
Copy link
Member

@JackThomson2 , one last thing before we merge this PR. Can you please fetch the latest changes from the main branch?

@JackThomson2
Copy link
Contributor Author

@sansyrox Won't merging automatically rebase onto main or am I missing something?

@sansyrox
Copy link
Member

@JackThomson2 , I was worried that I was just showing old changes. I'll merge and check.

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀
Amazing work! ✨

@sansyrox sansyrox merged commit 4b2fbc5 into sparckles:main Jun 20, 2021
@JackThomson2
Copy link
Contributor Author

🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants