-
Notifications
You must be signed in to change notification settings - Fork 49
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
[vsock] refactor VhostUserVsockThread worker #450
Conversation
325897a
to
8b5c07f
Compare
@@ -126,7 +136,39 @@ impl VhostUserVsockThread { | |||
), | |||
); | |||
} | |||
|
|||
let (sender, receiver) = mpsc::channel::<EventData>(); | |||
thread::spawn(move || loop { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It might be worth factoring this closure out to be its own function that explicitly takes the captured parameters by value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. is it what you want?
@ikicha thanks for the PR. Here some comments. Does this change also improve performance? I like that we reduce dependencies, but I honestly found the previous implementation easier to read. The only thing I didn't like was the duplication of code, which we could fix anyway. Now with this change IIUC, each device creates a new thread that manages the packets. Going back with the previous implementation, since we now support multiple devices at the same time, could we think about having a single ThreadPool for the entire application with a view to reducing resource consumption? (Of course we could have a new option to allow the user to decide the size of the pool.) |
TBH, I think it is almost the same. (might be slightly better because we don't uses thread pool executor's state management logic...)
I think the count of threads is the same.
Maybe we can use a single thread to handle every event in the entire application, but I am hesitated about multiple thread because IIUC the order of the packet is important, isn't it? And also, with regard to thread pool impl(and if we decide to use thread pool), I think tokio looks good over futures-executor because it's more popular, and efficient, and support epoll event(we can replace epoll listener with that). But it might be big change, so we might do that in the future if there is a performance issue. |
If you can run some performance test will be great.
Yep, I agree on that. It was a premise for the next paragraph :-)
How the order will be impacted in that case?
Got it, thanks for the details. |
Guest: I don't see difference between them.(it's around 450MB/s for now)
It's okay with current impl. But, I was talking about a global thread pool of which size is more than 1. In this case, it could be multiple thread handles packets which comes from the same device, and without additional lock mechanism, the order might be the problem.
|
d2ca2dd
to
72fde45
Compare
We usually try to avoid in the same PR to add code in one commit and modify it in subsequent ones unless strictly necessary for bisectability or other reasons. In this case I think you can merge everything into one commit. |
For now, VhostUserVsockThread uses thread pool executor from futures, but it doesn't need to use thread pool executor and futures because we just need background worker thread, and a way to let it work. So I removed unnecessary external dependency and made the logic simpler by using just thread and channel Signed-off-by: Jeongik Cha <jeongik@google.com>
72fde45
to
40b1fad
Compare
Squashed the commits into just one commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM!
@vireshk , can you review this PR? It looks like it needs 2 approvals to merge this. |
Summary of the PR
For now, VhostUserVsockThread uses thread pool executor from futures, but it doesn't need to use thread pool executor and futures because we just need background worker thread, and a way to let it work.
So I removed unnecessary external dependency and made the logic simpler by using just thread and channel
Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s
), and the commitmessage has max 60 characters for the summary and max 75 characters for each
description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafe
code is properly documented.