使用长阻塞同步操作将暂停在Node.js的所有用户? [英] Using a blocking long sync operation will pause all users in Node.js?
问题描述
如果我有一个SMTP服务器(如 haraka )或Web服务器(如的防爆preSS ),使用Node.js的,我必须使用不能转换同步功能是异步,会发生什么?
If I have an SMTP server (like haraka) or a web server (like Express) that uses Node.js and I have to use a sync function that could not convert to be Async what would happen?
如果我必须作出一个syncronous方式,直到HTTP请求完成后服务器将被绞死给所有用户或仅被处以绞刑,以当前用户/电子邮件HTTP请求?将所有用户的处理被暂停?
If I have to make an HTTP Request in a syncronous way the server will be hanged to all users until the http request is finished or be hanged only to the current user/email? Will the processing of all users be paused?
推荐答案
要了解回答你的问题,你真的需要了解的node.js的事件循环。我强烈建议您访问该链接SO及以下几个环节存在的。
To understand the answer to your question, you really need to understand the node.js event loop. I highly recommend visiting that SO link and following a few of the links there.
如果您必须执行同步操作时,要注意的是,同步调用将阻塞在是过程中的所有其他请求。如果你想多个客户机/遥控器可以同时兼任,那么你肯定会想使用集群模块的烤成的node.js产卵并发进程。
If you must perform a synchronous operation, be aware that yes, a synchronous call will block all other requests on that process. If you want more than one client/remote to be served concurrently, then you'll definitely want to use the cluster module baked into node.js to spawn concurrent processes.
另外,如果您的同步操作是缓慢的,足以影响您的服务质量,那么这将会是一个非常聪明的主意,熟悉 process.nextTick
和$ P $从在等待同步操作来完成完全被停滞pvent你的流程。
Also, if your synchronous operation is slow enough to impact your QoS, then it'd be a very smart idea to get familiar with process.nextTick
and prevent your processes from being completely stalled while waiting for a sync operation to complete.
这篇关于使用长阻塞同步操作将暂停在Node.js的所有用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!