构建 Node 应用程序应该使用 App Engine 还是 Google Cloud Run?

cam*_*cam 18 google-app-engine node.js google-cloud-platform google-cloud-run

我正在创建一个 Node 应用程序,它具有 Express、swagger 和 Agenda 来运行计划的作业。在 GCP 中部署它的最佳方式是什么?我应该使用 App Engine 还是 Cloud run。

根据我对 Cloud Run 的理解,它将在像 App Engine 的 docker 这样的容器中运行,它只会使用我的应用程序并托管它。请赐教我该怎么办?

干杯,卡姆

Pri*_*dra 32

App Engine 是一种平台即服务。这意味着您只需部署代码,平台就会为您完成其他所有事情。例如,如果您的应用程序非常成功,App Engine 将自动创建更多实例来处理增加的数量。

\n

它自动从 0 扩展到无限个实例(它在底层使用 GCE)。它具有两种风格:标准环境和灵活环境。\n标准环境速度非常快,当没有人使用您的应用程序时,可缩减至 0 个实例,可在几秒钟内扩展和缩减,并具有用于缓存、身份验证等的专用 Google 服务和库标准环境的警告是它非常受限制,因为它在沙箱中运行。最近添加的内容是 Node.js (8.x) 和 Python 3.x。\n灵活环境更加开放,因为它允许您使用自定义运行时,因为它使用 Docker 容器。因此,如果您的运行时在提供的运行时中不可用,您始终可以为执行环境创建自己的 dockerfile。需要注意的是,即使没有人使用您的应用程序,它也需要至少运行 1 个实例,而且扩展和缩减需要几分钟。

\n

阅读有关 App Engine 的更多信息

\n

App Engine 用于部署代码,Cloud Run 用于部署容器,容器是当今\xe2\x80\x99 的要求。Cloud Run 运行容器,因此对于每个版本,您都必须构建一个容器并将其推送到 GCP。

\n

Cloud Run, App Engine Flexible and Newer runtimes of App Engine Standard are designed for portability (you can use open-source libraries or standard libraries and not just Google Libraries). Cloud Run and App Engine Flexible allow for custom runtimes.

\n

Cloud Run gives you the freedom to expand your infrastructure into hybrid and multi-cloud environments.

\n

Read more about Cloud Run

\n

Differences you should consider:

\n
    \n
  • For a low-traffic application, Cloud Run or App Engine Standard which is set to automatic scaling are both cheaper than App Engine Standard which is set to manual/basic scaling or App Engine Flexible. Cloud Run only runs when it is serving requests. App Engine which is set to automatic scaling shuts down when it is not serving requests. This means for both types, you\'re not using resources when your application is not running and Google only bills you for resources that you consume. In addition, App Engine Standard provides a free daily quota of resources so you\'re only billed for consuming resources above the free quota. App Engine Flexible or App Engine Standard set to manual/basic scaling must have at least 1 instance running continuously, which means they run for a full month which in turn means you\'re going to pay more.

    \n
  • \n
  • App Engine responds on average 56 ms faster than Cloud Run. The huge\ncaveat here is that these times vary widely between runs, sometimes\ntripling or quadrupling The total request size from Cloud Run was\nlarger because it doesn\xe2\x80\x99t gzip files by default. The big difference\nbetween the two services is that Cloud Run doesn\xe2\x80\x99t run your container\nunless it\xe2\x80\x99s getting requests. When a request comes in, it does\nthings: [i] boots up the container [ii] serves the request [iii]\nshuts down the container Of course, you also save a lot of money\ndoing it this way, so the tradeoff here is whether you care more\nabout optimizing your speed or your cost.

    \n
  • \n
  • AppEngine can only be deployed to a single region. If you want an\nAppEngine app to be multi-regional then you need one project per\nregion. Cloud run allows you to deploy a service to every region\nwithin a single project making your API truly global, all within a\nsingle project

    \n
  • \n
  • Cloud Run also allows you to set up a static IP address, something\nyou cannot get with AppEngine. This is helpful for situations where\nyou need to relay mail or connect to some other service that\nrestricts access by IP address. Also AppEngine still has some things\nCloud Run doesn\'t (like Identity Aware Proxy) have.

    \n
  • \n
  • The docker image support in Cloud Run is also more versatile than\nwhat you get from AppEngine Standard, and Cloud Run has more robust\noptions to choose from (more ram, cpu, etc).

    \n
  • \n
\n
\n
\n

1https://cloud.google.com/appengine/docs/standard/nodejs/quickstart\n2https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-nodejs-service

\n