Skip to content

建议:聚合 checkLocationWorkerRoute 请求以减少 worker 请求数及使用 Cloudflare D1 存储数据 #46

Open
@Tsuk1ko

Description

@Tsuk1ko

看了下目前的实现,每个 checkLocationWorkerRoute 都会发出独立的请求来请求自身,这相当于每个此设置都会增加1440请求/天

这在一般情况下也许无关紧要,但当设置此项的节点数较多,并且用户也部署了其他请求消耗不低的服务的情况下,这个请求量也许不能忽视

是否可以进行改进,将相同 checkLocationWorkerRoute 的请求聚合,例如

const groupedCheckLocationWorkerRoute = new Map<string, string[]>();

workerConfig.monitors.forEach(({ id, checkLocationWorkerRoute }) => {
  const targets = groupedCheckLocationWorkerRoute.get(checkLocationWorkerRoute) || [];
  if (!groupedCheckLocationWorkerRoute.has(checkLocationWorkerRoute)) {
    groupedCheckLocationWorkerRoute.set(checkLocationWorkerRoute, targets);
  }
  targets.push(id);
});

for (const [checkLocationWorkerRoute, targets] of groupedCheckLocationWorkerRoute) {
  const resp = await fetch(checkLocationWorkerRoute, {
    method: 'POST',
    body: JSON.stringify({
      targets,
    }),
  }).json<{ location: string; status: Array<{ id: string; ping: number; up: boolean; err: string }> }>();
}

然后修改 fetch handler 以支持批量 getStatus

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions