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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Detecting Node Event Loop Blockers

85 点作者 Ben-G大约 3 年前

5 条评论

naugtur大约 3 年前
Hi, blocked-at author here.<p>Get in touch over email if you want to explore further.<p>Some quick comments:<p>- I didn&#x27;t notice the node version or you didn&#x27;t state it. The impact from async hooks is _vastly_ different between node versions<p>- I need to update the package a bit, I&#x27;ve got a known perf improvement to add AFAIR.<p>- your implementation is likely to produce false positives. The trick to prevent (some) false positives is the most valuable part of the lib.<p>Also, take a look at the event loop utilization metric introduced last year <a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=WetXnEPraYM&amp;list=PL0CdgOSSGlBalMPxFFycq7OIqQF8cJS28&amp;index=13" rel="nofollow">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=WetXnEPraYM&amp;list=PL0CdgOSSGlBa...</a><p>And for more of my diagnostics experiments see debugging-aid package <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;debugging-aid" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;debugging-aid</a>
评论 #30716674 未加载
jerf大约 3 年前
This is ultimately what killed cooperative scheduling in the 90s and the early 2000s. It works at first, then it keeps working, and indeed, it keeps working for a long time. If you&#x27;ve got a problem below that threshold, you&#x27;re probably be fine. But eventually, as you scale up, you <i>will</i> eventually hit the problem that you&#x27;ve got things that sometimes run longer than you thought, sometimes a <i>lot</i> longer than you thought, and it locks the whole system up. You can maybe fix the first few, as the article does here, but the problem just gets larger and larger and eventually you run out of optimization juice if your system has to keep getting bigger.<p>MacOS prior to X was cooperatively scheduled across the whole OS, and it was definitely breaking down and why Apple needed such a radical change. Likely you aren&#x27;t cooperatively scaling on this scale, which is why it continues to work with many programs.<p>In some sense, the problem is that every line of code you write is essentially an event loop blocker. Sooner or later, as you roll the dice, one of them is going to end up taking longer than you thought. It&#x27;s the same basic forces that make it so that nobody, no matter how experienced, really <i>knows</i> how their code is going to run until they put it under a profiler. There&#x27;s just too much stuff going on nowadays for anyone to keep track of it all and know in advance.<p>But it is just one of those things you need to look at when first sitting down to decide what to implement your new system in. If you run the math and you need the n&#x27;th degree of performance and memory control, don&#x27;t pick Python, for instance. If the profile of tasks you need to run is going to be very irregular and consume lots of the CPU and doesn&#x27;t have easy ways to break it apart (or it would be too much developer effort to keep manually breaking these tasks apart), don&#x27;t pick a cooperatively-scheduled language.<p>Fortunately, it&#x27;s a lot easier than it used to be to try to take these particular tasks out and move them to another language and another process, while not having to rewrite the entire code base to get those bits out.
评论 #30714241 未加载
评论 #30714392 未加载
评论 #30714724 未加载
mfbx9da4大约 3 年前
This is excellent and an answer to my deleted question on stackoverflow! <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;69886637&#x2F;measure-time-taken-serializing-onto-the-javascript-thread" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;69886637&#x2F;measure-time-ta...</a>
评论 #30715091 未加载
lmarcos大约 3 年前
When working in a green field project, does Node.js provide any advantages over, let&#x27;s say, Go? In medium to big size teams, I find tricky to keep the event loop free of blockers. In this regard, Go&#x27;s goroutines model make it easier to not block the whole app due to silly mistakes.
评论 #30716940 未加载
评论 #30717774 未加载
des429大约 3 年前
fyi to anyone seriously considering using these: neither is going to work as expected if something blocks the loop indefinitely. In other words, you won&#x27;t know how long something blocked the loop until that thing has finished blocking. Timeouts for async code or limits on loop statements are still relevant.
评论 #30716444 未加载