-
Notifications
You must be signed in to change notification settings - Fork 132
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
To set nonblocking
-mode on streams or not?
#218
Comments
I'm not an expert, but I was studying this for my current project, so here's my current understanding of it. I'll use an example with the recv operation on a socket, this could be a stream type socket (TCP). Polling or readiness check: If the socket is non-blocking, the kernel checks whether the data is available for reading on the socket. If the data is not available, it registers a callback to be triggered when the data becomes available. The kernel also sets the request to be in the "in-flight" state. In the blocking case, the internal mechanism now must account for the fact that the recv operation in the kernel will block, so the kernel must also handle the blocking behavior. Instead of simply registering a callback and setting the request to be in the "in-flight" state, the kernel may need to set up a wait queue or other synchronization primitives, which will block a kernel thread until the data becomes available. This adds an overhead in terms of kernel resource management and increases the complexity of the operation handling. When data becomes available on the socket, the kernel not only triggers the registered callback (as in the non-blocking case) but also needs to wake up the blocked kernel thread, allowing it to continue processing the request. This wake-up process introduces some additional overhead due to synchronization and signaling. So, I think that the main difference lies in the internal handling by the kernel. Let me know your thoughts on it. |
Could anyone answer me what is the difference in io-uring bahavior between using
non-blocking
andblocking
streams?The text was updated successfully, but these errors were encountered: