@fantasticfour/world-cloudflare (英语)
边源工作流程后端使用 Cloudflare 持久对象并带有 SQLite 存储和全局子- 10ms 延迟 。 向Cloudflare的全球网络部署工作流程,以达到最大性能.
为什么使用此软件包
- 边缘第一: 在Cloudflare的网络上全球运行
- 低纬度: 全世界次-10ms响应时间
- SQLite 存储: 每个持久对象中的 SQL 查询
- 自动缩放: 自动地域分配
- 实时: 基于 WebSocket 的流线
- 供应商整合: 原生云浮工人生态系统
适用于需要全球低纬度工作流程执行的应用程序,特别是已经使用Cloudflare基础设施的应用程序.
安装
pnpm add @fantasticfour/world-cloudflare
先决条件
- 云浮账户- 耐用物品所需的工人付费计划
- 瑞格勒CLI(英语::用于部署(
pnpm add -D wrangler(中文(简体) )
使用量
世界通过下列途径讨论其持久目标: WORKFLOW_DB 财务报告和审定财务报表
WORKFLOW_STREAMS 绑定,所以不能为您注册这些类:
你的工人入境点可以。 从您的入境点或 wrangler deploy 失败 Your Worker depends on the following Durable Objects, which are not exported in your entrypoint file。 。 。 .
import { createCloudflareWorld } from '@fantasticfour/world-cloudflare';
// Required: wrangler binds these to the classes named in wrangler.toml.
export { StreamDO, WorkflowRunDO } from '@fantasticfour/world-cloudflare/worker';
// In your Cloudflare Worker
export default {
async fetch(request, env) {
const world = createCloudflareWorld({ env });
// Create a workflow run
const run = await world.runs.create({
runId: ulid(),
workflowName: 'my-workflow',
status: 'pending',
input: ['arg1', 'arg2'],
deploymentId: 'production',
executionContext: {},
createdAt: new Date(),
updatedAt: new Date(),
});
return new Response(JSON.stringify(run));
},
};
建筑
- 存储: 有 SQLite 的持久对象( 工作流程- 运行隔离)
- 队列: 有自动重试的 Cloudflare 队列
- 流线: 通过持久对象进行基于 WebSocket 的实时活动
- 索引编制:全球工作流程查询的工人 KV
- 身份证: 基于可分类标识符的 ULID
配置
配置在 wrangler.toml数字 :
要求所有四个装订,并固定装订名称: createCloudflareWorld
读出来 env 以名为相.
name = "my-workflow-app"
main = "src/index.ts" # the entrypoint that re-exports StreamDO and WorkflowRunDO
compatibility_date = "2024-11-27"
compatibility_flags = ["nodejs_compat"]
[[durable_objects.bindings]]
name = "WORKFLOW_DB"
class_name = "WorkflowRunDO"
[[durable_objects.bindings]]
name = "WORKFLOW_STREAMS"
class_name = "StreamDO"
# Both classes use DO SQLite storage, so they must be introduced as
# new_sqlite_classes. Without this migration the bindings resolve but every
# storage call fails at runtime.
[[migrations]]
tag = "v1"
new_sqlite_classes = ["WorkflowRunDO", "StreamDO"]
[[queues.producers]]
queue = "workflow-queue"
binding = "WORKFLOW_QUEUE"
[[kv_namespaces]]
binding = "WORKFLOW_INDEX"
id = "your-kv-namespace-id"
测试范围
该一揽子计划包括全面测试:
- 存储. test.ts: CRUD操作,持久对象集成,状态过渡
- 光谱测试: @ workflow/ world 接口达标
- 持久对象. test.ts: DO 孤立、状态持续、 KV 索引、同步更新
总计:1 350行试验范围确保生产可靠性.
费用估计数
云花盘定价:
- 持久目标: 15万美元的请求
- 问题:40万美元/百万美元
- 工人:50万
- 工人:包括带薪计划(5美元/月)
每月估计费用:
- 使用率低 (100K工作流程/月):5-10美元
- 中等使用量 (1M工作流程/月):10-20美元
- 高使用率 (10M工作流程/月):50-100美元
注:要求工人支付工资计划(最低每月5美元).
地方发展
使用Wrangler进行本地开发:
# Install wrangler
pnpm add -D wrangler
# Run locally with Miniflare
pnpm wrangler dev
# Deploy to Cloudflare
pnpm wrangler deploy
何时选择此软件包
当 :
- 需要全球次- 10毫分延迟
- 已经使用 Cloudflare 工人
- 所需边际计算效益
- WebSocket 流线重要
- 供应商可以锁定
在下列情况下考虑其他办法:
- 需要多云策略 - > 使用@ fantasticfour/ world-upstash
- 偏好的传统基础设施 - > 使用@ fantasticfour/world-postgres-redis
- 成本优化优先级 - > 使用@ fantasticfour/ world-redis
- AWS 生态系统 - > 使用@ fantasticfour/ world-damodb-sqs
性能特征
- 延迟: < 10ms全球(对接部署)
- 寒冷的开始: 最小值(耐用物体为~1-5ms)
- 吞吐量: 随流量自动缩放
- 地理分布: 通过 Cloudflare 网络自动
许可证
Apache 许可证