TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Node.js: details and best practices (a server side guy's analysis)

72 点作者 rpwilcox超过 13 年前

6 条评论

blago超过 13 年前
"Useful Javascript stuff I can NOT use (because it implicitly blocks): Underscore.js"<p>Huh? So what are we going to hear next: "Don't use prototype inheritance because chain traversal implicitly blocks"? Idiotic advise.<p>How about: Don't hold the event loop for too long. The faster you return, the faster you can serve.
评论 #3174161 未加载
jeromeparadis超过 13 年前
It is hinted in the article that node.js is better for some use cases than others.  One thing node.js is good at is realtime apps and socket.io and the evented model make these easier.<p>However, as a server developer guy too, I must point out that if scalability ( or premature optimization ) is dear to you, I would look further than cluster to run multiple node processes. A good solution I found for a few projects is to use Redis pub sub to encapsulate socket.io messages to connected clients to make it easy, non-blocking and performant to scale to multiple nodes. For a project where I have some potential CPU bound code, I further split these operations in another process (let's say a game state machine with calculations) with which I exchange pub sub messages. In such realtime apps, the worst that can happen is that some process intensive functions may take a bit more time to dispatch information to the clients but the core communications node processes won't be blocked and will be screaming fast and horizontally scalable.<p>I've found that Redis pub sub is awesome for simple and fast interprocess communications.
davidhollander超过 13 年前
&#62; <i>Underscore.js for Iterations: each implicitly blocks</i><p>???? Blocking refers to IO system calls. underscore is not an IO library. Does a 15 year programmer with C++ experience not know what an O_NONBLOCK system call is? Blocking or non blocking is about how you are performing IO with the external world. It has nothing to do with the world internal to your program: callbacks are merely correlated with nonblocking io, continuation passing style does not constitute nonblocking in an of itself. You do not have to use continuation passing style and lambdas for code that does not perform IO for it to be "nonblocking".
评论 #3173361 未加载
评论 #3173930 未加载
twog超过 13 年前
Great information, horrible website. I dont expect every whitepaper, website, or blog to have world class design, but this is information is horribly displayed. There is no reason for a website in 2011 to look this way.
评论 #3173246 未加载
Androsynth超过 13 年前
One of the things I did was write a defer function (ie process.nextTick) and just threw it anywhere I thought some operation could potentially be blocking. This requires an analysis of latency vs bandwidth for your application (for me, extra latency was acceptable and bandwidth was at a premium). This also allows use of underscore libraries, albeit with extra defer calls everywhere.<p>Unfortunately I could not convince my old company to use node.js in production because I was very curious to see how the extra function call overhead compared against the extra bandwidth.<p>On another note, I was surprised that the eventEmitter callbacks are not executed asynchronously. I assumed each one was run on the next tick. That always struck me as inconsistent with the rest of the API.
bilalhusain超过 13 年前
[disagreement with a select terminology eg. <i>research</i>, <i>whitepaper</i>; agreement with <i>analysis</i>, <i>best practices</i>]