如何扩展重型视频渲染服务器?

How to scale a heavy video rendering server?

我正在 Node.js 开发视频渲染服务器。它生成多个无头 chrome 并使用 puppeteer 库捕获屏幕截图并将它们提供给 ffmpeg。稍后它会通过一些 post 处理来连接所有部分。

现在我想将其移至生产环境,但它的运行效率不高。 尝试了无服务器架构和 cloudrun 等,但仍然无法实现。他们还明确提到这些不适用于繁重且漫长的 运行 任务。视频渲染时间过长,甚至比我的笔记本电脑花费的时间还要长。

我尝试使用 GCE,结果令人满意,但现在我很难扩展它。实际上,服务器一次只能有效地处理一个请求。如何水平扩展并确保每个人一次只收到一个请求?

提前致谢。

要增加相同实例的数量,您可以使用 Managed Instance Groups. Have a look at the autoscaling documentation 来更好地理解它是如何工作的,但基本上它说:

You can autoscale based on one or more of the following metrics that reflect the load of the instance group:

  • Average CPU utilization.
  • HTTP load balancing serving capacity, which can be based on either utilization or requests per second.
  • Cloud Monitoring metrics.

如果您要根据 CPI 使用率自动缩放,那么在创建新的实例组时 enable autoscaling and set it up

下面是执行此操作的示例 gcloud 命令:

gcloud compute instance-groups managed set-autoscaling example-managed-instance-group \
    --max-num-replicas 20 \
    --target-cpu-utilization 0.60 \
    --cool-down-period 90

您还可以使用任何可用的 metric to scale up your group or even create a new custom metric 来触发您的组的扩展;

You can create custom metrics using Cloud Monitoring and write your own monitoring data to the Monitoring service. This gives you side-by-side access to standard Google Cloud data and your custom monitoring data, with a familiar data structure and consistent query syntax. If you have a custom metric, you can choose to scale based on the data from these metrics.

最后 - 我找到了 example use case that scales up group of VM's based on pub/sub queue 这可能是您正在寻找的解决方案。