NODEJS事件循环回调限制限制

发布于 2025-02-11 09:21:46 字数 495 浏览 0 评论 0原文

Nodejs事件循环的每个周期同步清除每个阶段排队的最大回调数。

来自Nodejs网站:

当事件循环进入给定阶段时,它将执行特定于该阶段的操作,然后在该阶段队列中执行回调,直到排队用尽或最大回调数量为止。

事件循环阶段:计时器 - >等待回调 - >闲置,准备 - >民意调查 - >检查 - >关闭回调

例如,在民意测验阶段,限制由libuv设置:

为了防止轮询阶段饿死事件循环,libuv(实现Node.js事件循环的C库和平台的所有异步行为)在停止轮询之前也具有硬最大值(系统依赖)有关更多事件。

我的问题是:

  • 我在哪里可以找到每个阶段/迭代的硬限制?
  • 奖励:是否有一种程序化方法可以获取每个阶段队列的当前大小?

Every cycle of the NodeJS event loop synchronously clears a maximum number of callbacks queued for each phase.

From NodeJS website:

when the event loop enters a given phase, it will perform any operations specific to that phase, then execute callbacks in that phase's queue until the queue has been exhausted or the maximum number of callbacks has executed.

Event loop phases: timers --> pending callbacks --> idle, prepare --> poll --> check --> close callbacks

For example in the poll phase the limit is set by libuv:

To prevent the poll phase from starving the event loop, libuv (the C library that implements the Node.js event loop and all of the asynchronous behaviors of the platform) also has a hard maximum (system dependent) before it stops polling for more events.

My question is:

  • Where can I find these hard limits per phase/iteration?
  • Bonus: Is there a programmatic way to get the current size of each phase's queue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文