同一个dyno 运行 可以多进程吗?

Can the same dyno run multiple processes?

我正在创建小型应用 运行宁多个微服务。我想让这个应用程序 24/7 全天候可用,所以免费的 dyno 时间对我来说是不够的。如果我升级到 hobby 套餐,我会得到 10 Process Types

我可以 运行 每个进程(web)上的另一个微服务吗,或者 Heroku 是否允许我只为每个 dyno 安装一个 web 进程,而另一个 10 process types 用于扩展我的应用程序?换句话说,如果我需要 6 个微服务 运行ning 24/7 我应该买 6 个 hobby dynos 吗?

您只能有 1 种网络进程类型。您可以在多个测功机 ("horizontal scalability") 上将您的 Web 进程水平扩展到 运行,但是您至少需要升级到标准 1x 测功机类型才能做到这一点(即您只能 运行 1 个网络测功机实例(如果您使用的是免费或业余测功机类型)。

但是,除了 Web 进程之外,您还可以实例化多个其他进程类型(例如 "worker" 进程)。这些将无法侦听来自您的客户的 HTTP/S 请求,但可用于从您的网络进程中卸载长期 运行 宁的作业。

因此,如果您将 4-6 个微服务中的每一个都映射到您的 Procfile 中的不同进程类型,并且如果您的微服务本身不是 Web 服务器,您也许可以使用 hobby dynos。

Heroku 的默认模型是将进程类型映射到它自己的 dyno:https://devcenter.heroku.com/articles/procfile states

"Every dyno in your application will belong to one of the process types, and will begin executing by running the command associated with that process type."

例如heroku ps:scale worker=1 对于 worker.

类型

其他人已经写过关于 how to use foreman or Honcho to run multiple python processes in a single dyno, which utilize a secondary Procfile and possibly other slug setup in a post_compile step. Presumably you could do something similar depending on your chosen language and its buildpack; the official buildpack API doesn't list this step though :/. That said, given Heroku's base Ubuntu stacks 的文章,您可以 web: script.sh 进行任何设置和执行流程。

要在 Docker 容器中分组多个进程,您可以查看 https://runnable.com/docker/rails/run-multiple-processes-in-a-container, which relies again on a custom CMD [ "/start.sh" ]. Note that it's contrary to Docker's single-­process-­per-­container philosophy, and can give you more headaches e.g. around forwarding signals to child processes, an ugly Dockerfile to setup all microservices, etc. (If you do decide to use multiple containers, Heroku has a writeup on using Docker Compose for local dev。)

还有,别忘了你是 bounded by the performance of your dyno and the process/thread limits

当然,对于非玩具生产或长期开发维护,通常不建议给定测功机中的多个进程。 ;)

RUNIT buildpack 这使得在单个测功机中组合多个进程变得容易 - 只要它们都符合您的测功机内存限制(对于业余测功机为 512M)。

每个 Heroku 应用程序仍然只有一个 HTTP 端点,这意味着您的微服务将需要通过队列、pub/sub 或某些 RPC 集线器(如 deepstream.io)进行通信。