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

frontend: avoid being starved by CPU-intensive tasks #9019

Closed
BugenZhao opened this issue Apr 6, 2023 · 4 comments
Closed

frontend: avoid being starved by CPU-intensive tasks #9019

BugenZhao opened this issue Apr 6, 2023 · 4 comments
Assignees
Labels
component/frontend Protocol, parsing, binder. needs-investigation no-issue-activity type/enhancement Improvements to existing implementation.

Comments

@BugenZhao
Copy link
Member

More severely, constant-folding this expression causes the frontend unable to establish new connections for further requests, since tokio tends to move the IO scheduler to the same worker thread with this session, and an infinite loop starves the IO scheduler so that the main thread listening to the connection cannot be woken again! 😨

Although we should definitely fix this issue, it's also possible that the optimizer becomes more complicated and CPU-intensive. This might be relieved by using a separate runtime for frontend sessions (like #4756), but the stuck is inevitable when worker threads are exhausted (note that CPU-intensive tasks cannot be canceled). Or, we need spawn_blocking or block_in_place in every possible blocking code.

cc @liurenjie1024 @wangrunji0408

Originally posted by @BugenZhao in #8949 (comment)

@github-actions github-actions bot added this to the release-0.19 milestone Apr 6, 2023
@BugenZhao BugenZhao added type/enhancement Improvements to existing implementation. component/frontend Protocol, parsing, binder. labels Apr 6, 2023
@liurenjie1024
Copy link
Contributor

I think we should have different runtime for different tasks, e.g. IO bound runtime and CPU bound runtime.

@BugenZhao
Copy link
Member Author

I believe the core problem is that there's no way to cancel a user-mode coroutine that is busy executing synchronous code unless it's associated with a dedicated thread. But this is the opposite of our using coroutine to achieve more efficient I/O and concurrency, especially for the frontend.

@BugenZhao BugenZhao removed this from the release-0.20 milestone Jun 12, 2023
@wangrunji0408
Copy link
Contributor

unless it's associated with a dedicated thread.

Even if the task is running on a dedicated thread, it is not safe to kill the thread via system call, which can lead to resource leaks and undefined behavior. As evidence, there is no such API in the std library. The only way to exit a thread safely is to notify the thread and wait for its self-exit. This is the same as coroutines.

@github-actions
Copy link
Contributor

This issue has been open for 60 days with no activity. Could you please update the status? Feel free to continue discussion or close as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/frontend Protocol, parsing, binder. needs-investigation no-issue-activity type/enhancement Improvements to existing implementation.
Projects
None yet
Development

No branches or pull requests

4 participants