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

Networking: fold websocket and http tokio runtime into one. #31648

Closed
gterzian opened this issue Mar 13, 2024 · 9 comments · Fixed by #31771
Closed

Networking: fold websocket and http tokio runtime into one. #31648

gterzian opened this issue Mar 13, 2024 · 9 comments · Fixed by #31771
Assignees

Comments

@gterzian
Copy link
Member

gterzian commented Mar 13, 2024

We use two separate Tokio runtimes:

One for HTTP requests:

pub static ref HANDLE: Mutex<Option<Runtime>> = Mutex::new(Some(Runtime::new().unwrap()));

And another one for Websockets:

pub static ref HANDLE: Mutex<Option<Runtime>> = Mutex::new(Some(Runtime::new().unwrap()));

The rationale is:

// Websockets get their own tokio runtime that's independent of the one used for
// HTTP connections, otherwise a large number of websockets could occupy all workers
// and starve other network traffic.

I think it's doubtful that a large amount of websockets could really starve HTTP request, since the whole point of tokio is to run a large amount a tasks onto a single runtime.

We should investigate using one runtime for all networking tasks.

@wusyong
Copy link
Contributor

wusyong commented Mar 14, 2024

I saw your comment in zulip mentioned there's another PR dealing with thread spawning too. But it seems it created even more threads. I'm wondering if we could make whole net crate to share the same tokio runtime without manually spawning threads and thread pool.

@gterzian
Copy link
Member Author

But it seems it #31517 (comment) even more threads.

Yes that's correct, it uses a threadpool which will see threads created upfront, instead of spawning one thread for each image that is decoded.

I'm wondering if we could make whole net crate to share the same tokio runtime without manually spawning threads and thread pool.

We can use a single runtime for all async task, and a single core resource threadpool for the other non-async bacground work.

@wusyong
Copy link
Contributor

wusyong commented Mar 16, 2024

@gterzian Could you add some good-first-issue or E-candidate-for-mentoring label?
This issue seems like a good chance for anyone who want to contribute.

@tannal
Copy link
Contributor

tannal commented Mar 16, 2024

I would like to take this up.

@MunishMummadi
Copy link
Contributor

Hey @tannal what is your status with the issue. Can I join

@tannal
Copy link
Contributor

tannal commented Mar 19, 2024

@MunishMummadi Yes you can.
The quick fix for this issue is done.

We can use a single runtime for all async task, and a single core resource threadpool for the other non-async bacground work.

You can open another pr to do this part if you are interested in this issue.

tannal added a commit to tannal/servo that referenced this issue Mar 19, 2024
@gterzian
Copy link
Member Author

a single core resource threadpool for the other non-async bacground work.

Yes indeed, this part would be good for a new PR @MunishMummadi

The idea is to use a single CoreResourceThreadPool in components/net, see for guidance this issue, which added a second one. You could make changes to have a single pool used where now two are used.

@MunishMummadi
Copy link
Contributor

Yes I would love to work on it @gterzian @tannal . Can I ask the bot to "assign me"!!!

@gterzian
Copy link
Member Author

Actually, because the image cache runs in the script thread, not in the core resource thread, this is quite complicated and perhaps not a good idea. I withdraw my earlier conclusion.

github-merge-queue bot pushed a commit that referenced this issue Mar 21, 2024
* net: use the same tokio runtime in websocket loader

#31648

* readability

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

Successfully merging a pull request may close this issue.

4 participants