@enfyra/kernel

中文文档
2.1.6发布于 2026/11/04Elastic-2.0TypeScriptCommonJS近 30 天下载 3016

Closed-distribution Enfyra kernel runtime

原始使用文档
文档目录3 节
  1. Dynamic context
  2. Use
  3. Executor capacity

@enfyra/kernel

Enfyra kernel runtime package.

Dynamic context

The isolated executor snapshots cloneable $ctx keys into the sandbox automatically. Runtime platforms can expose new data fields from their own context factory without changing the kernel, while protected runtime capabilities such as $helpers, $cache, $repos, $socket, $throw, $trigger, $logs, $req, and $res stay kernel-managed. $env is readable inside the sandbox when provided by the host application, but sandbox mutations to $env are not merged back to the host context.

Use

import { createEnfyraKernel } from '@enfyra/kernel';

const kernel = createEnfyraKernel({
  knexService,
  mongoService,
  databaseConfigService,
  runtimeMetricsCollectorService,
  lazyRef,
  getPackageCacheService: () => packageCacheService,
  getPackageCdnLoaderService: () => packageCdnLoaderService,
});

container.register({
  queryBuilderService: asValue(kernel.queryBuilderService),
  isolatedExecutorService: asValue(kernel.isolatedExecutorService),
  executorEngineService: asValue(kernel.executorEngineService),
});

Executor capacity

Each runner process executes multiple independent task-owned ivm.Isolate instances, up to isolatesPerWorker. Each execution creates its own isolate and context directly on dispatch, without an idle isolate reserve pool. Completion or cancellation disposes only that task's isolate; other tasks in the worker keep running. A batch's hooks and handler share that batch's isolate. There is no shared lane or multi-task heap.

Tuning selects up to two runner processes using effective CPU and container memory. Admission capacity and isolate heap limits are independent policies. Admission uses a 25% memory planning budget, a 40–128 MiB planning unit, CPU baseline/flexible unit counts, and six independent execution slots per unit. This is capacity arithmetic, not a shared isolate or lane: each admitted task still owns its isolate. Below 2 GiB, admission uses one unit per runner; larger profiles are bounded at 128 units per runner. A 14 CPU / 36 GiB profile admits 216 task isolates per worker, or 432 total.

Each isolate's native heap limit is effective memory divided by 32, with a 40 MiB minimum and no fixed MB ceiling. Limits are not preallocated RAM, and their sum may exceed physical memory. The parent applies RSS backpressure; runner, package-child, IPC and host memory remain outside isolate heap limits. Large simultaneous tasks can still exhaust real memory, so benchmark the expected payload and concurrency on the target hardware.

computeEngineTuning({ logicalCpuCount, totalMemoryBytes, maxIsolatesPerWorker }) can lower the per-worker capacity for a host-owned profile. A custom executor tuning contains maxConcurrentWorkers, isolatesPerWorker, and isolateMemoryLimitMb. Queued tasks start only after prior tasks release their isolate capacity. $body and the exact $req.rawBody remain available.

Run yarn test:executor-isolates for capacity and failure containment. Never automatically replay a task after ambiguous isolate or runner loss.

版本与发布记录

@enfyra/kernel 共发布 110 个版本,首次发布于 2026/04/30;过去 12 个月发布了 110 个版本。

版本发布日期距今
2.1.6latest2026/11/049 天前
2.1.52026/11/0113 天前
2.1.42026/10/2717 天前
2.1.32026/10/2717 天前
2.1.22026/10/2717 天前
2.1.12026/10/2717 天前

关于 @enfyra/kernel 的常见问题

@enfyra/kernel 是什么?

Closed-distribution Enfyra kernel runtime

如何安装 @enfyra/kernel?

在项目目录运行 npm install @enfyra/kernel,或使用 pnpm add / yarn add / bun add。

@enfyra/kernel 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@enfyra/kernel 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@enfyra/kernel 可以商用吗?

@enfyra/kernel 使用 Elastic-2.0 许可。声明的许可为 Elastic-2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@enfyra/kernel 的下载量有多少?

根据 npm 官方下载统计,@enfyra/kernel 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,016 次,日均约 101 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@enfyra/kernel 还在维护吗?

最新版本 2.1.6 发布于 2026/11/04(9 天前);至今共发布 110 个版本,其中过去 12 个月发布了 110 个;首次发布于 2026/04/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。