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

Node.js - Event loop (handshake and requests ) #1464

Closed
pinkladywithcoco opened this issue Aug 30, 2018 · 8 comments
Closed

Node.js - Event loop (handshake and requests ) #1464

pinkladywithcoco opened this issue Aug 30, 2018 · 8 comments

Comments

@pinkladywithcoco
Copy link

Hi!

I hope someone can confirm whether it's correct understood or not.

Node.js main networking is made inside a single thread ( event loop ), but handshake and requests is sent as task to the thread pool?

So if we create Https server in Node.js the handling of incoming connections is inside a single thread, but the handshake and process of requests is handleded by the thread pool?

or is it only the requests that is sent to the thread pool, but the handshake was already taken care of inside the single thread?

Can you please help me to confirm which is correct flow?

@gireeshpunathil
Copy link
Member

for any transactions including networking, the operations that involve JS object processing is always performed by the main thread. Because Node.js leverages V8 for object management (among other things) that assumes single thread access to the object heap, this work cannot be transferred to another thread.

What gets transferred to the thread-pool is the intermediary work that operates with data in native structures (C, C++). Example: HTTP protocol parsing (networking), disc I/O (file system).

Hope this helps.

@pinkladywithcoco
Copy link
Author

But that handshake don't happen inside the main thread?? only the accept of connection? if the handshake happens in the main thread it will create delay so it should happen inside the thread pool like the HTTP protocol parsing ?? i'm quite confused about this part

@gireeshpunathil
Copy link
Member

when you say handshake, do you mean the TCP handshake? If so, yes, that happens at the main thread (but at the tcp driver + kernel combination so very low overhead)

At HTTP level, there is no handshake if I understand correctly, only parsing of the protocol text. That happens in the worker thread as I mentioned earlier.

@pinkladywithcoco
Copy link
Author

Hi gireeshpunathil

I mean the TLS handshake when we are using Node.js as Https server. Node use OpenSSL after accepting the incomming client

@gireeshpunathil
Copy link
Member

apologies for late response. ok, all TLS handshake happen in the main thread. There were discussions on offloading these to helper threads, but as of now, main thread itself.

@pinkladywithcoco
Copy link
Author

Thank you for your response and confirmation regarding the TLS handshake . Can you please point me to those discussions where to find them ?

@gireeshpunathil
Copy link
Member

nodejs/node#8436 is one I remember. It may have links to other related discussions too.

@gireeshpunathil
Copy link
Member

closing as answered

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

No branches or pull requests

2 participants