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

事件循环处理的自身代码在哪个线程上执行? #8

Open
lookforit opened this issue Jun 21, 2016 · 11 comments
Open

事件循环处理的自身代码在哪个线程上执行? #8

lookforit opened this issue Jun 21, 2016 · 11 comments

Comments

@lookforit
Copy link

题目中 自身代码 指的是,创建主循环,从观察者中取请求对象等操作。
按我的理解,不可能在IO线程池中,是在js主线程还是node的其他线程?
另外,callback肯定在js主线程上执行,那么时间循环应该不包括callback的执行吧。

请教了。

@JacksonTian
Copy link
Owner

主线程。JS代码和事件循环都是在主线程之行。

@lookforit
Copy link
Author

谢谢!
答案有点意外。
比如,如果callback费时,岂不是会影响事件循环,对某些观察者无法响应?

在 2016/6/21 15:06, Jackson Tian 写道:

主线程。JS代码和事件循环都是在主线程之行。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#8 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABzgbnJkD34aT283qx1LZsXeVCPxmkjcks5qN416gaJpZM4I6a4q.

@JacksonTian
Copy link
Owner

嗯。

关于费时的定义,可以参见: https://gist.github.com/jboner/2841832

@lookforit
Copy link
Author

好的。
另外一个建议,关于数据库异步操作原理,书中提及的不多,能否指点一二?

在 2016/6/21 15:17, Rila 写道:

谢谢!
答案有点意外。
比如,如果callback费时,岂不是会影响事件循环,对某些观察者无法响应?

在 2016/6/21 15:06, Jackson Tian 写道:

主线程。JS代码和事件循环都是在主线程之行。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#8 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABzgbnJkD34aT283qx1LZsXeVCPxmkjcks5qN416gaJpZM4I6a4q.

@JacksonTian
Copy link
Owner

JacksonTian commented Jun 21, 2016

数据库异步操作本质是网络异步操作,在TCP上根据协议封装操作而已。对调用方来说 没有什么特别的地方。

客户端实现上倒是有些细节比较有意思。

我会在第二版中加入这方面的内容。

@lookforit
Copy link
Author

ok。
客户端数据库异步操作是否需要单独实现数据库的观察者,以便通知事件循环操作
完成?
另外,此时数据库的操作还是在IO线程池中进行吗?

在 2016/6/21 17:01, Jackson Tian 写道:

数据库异步操作本质是网络异步操作,在TCP上根据协议封装操作而已。对调用
方来说 没有什么特别的地方。

客户端实现上倒是有些细节比较有意思。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#8 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABzgbkhGrLuBMpt4cHJq9e3FKP0KzRsJks5qN6hpgaJpZM4I6a4q.

@JacksonTian
Copy link
Owner

TCP。不用IO线程池。

@lookforit
Copy link
Author

感谢您耐心的回复,打扰到您了。
但我真的有点糊涂,如您所述,网络IO是不需要进入IO线程池的吗?

我注意到《libuv doc》上的一段话:
“The libuv filesystem operations are different from socket operations.
Socket operations use the non-blocking
operations provided by the operating system. Filesystem operations use
blocking functions internally, but invoke these
functions in a thread pool and notify watchers registered with the event
loop when application interaction is required

上面指出socket操作确实有别于磁盘io,由于其非阻塞特性。
该如何理解网络IO与主线程的交互?

在 2016/6/21 17:52, Jackson Tian 写道:

TCP。不用IO线程池。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#8 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABzgbpUy1K_DIWZ3oBWBnfiFlYTcsnFYks5qN7RzgaJpZM4I6a4q.

@JacksonTian
Copy link
Owner

socket操作使用epoll/kqueue,就在主线程上操作。

@lookforit
Copy link
Author

如您所讲,epoll和IO线程池没有直接关系,前者由内核提供,负责多路IO复用,
后者由libuv实现,承载IO具体执行工作。

在 2016/6/22 14:07, Jackson Tian 写道:

socket操作使用epoll/kqueue,就在主线程上操作。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#8 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABzgbhB6Zv6MfBw-9s4RyWdf4XoOUP41ks5qONESgaJpZM4I6a4q.

@happyshrm
Copy link

之前有看过netty的实现思路,感觉跟这里的磁盘IO的处理机制差不多,虽然他处理的是网络IO操作,事件的操作只能在单线程中操作。

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

3 participants