Google App Engine - 第一个请求很慢
Google App Engine - First Request is slow
我有一个关于 Google App Engine 的问题。我知道第一个请求将比第二个请求花费更长的时间,因为实例是如何缩放的。但就我而言,差异非常大。我没有手动缩放,只有标准的自动缩放,我想就我应该做什么提出一些建议。
这是我的情况:
我有一个电子商务网站的 AMP 项目(https://amp.dev/)。所以我没有任何静态 URL 可以设置 Google App Engine 推荐的预热请求。 url 是这样的:amp.store/product/{productname}
,所以 {productname}
是动态的,我有超过 1000 种产品,无法向那些 url 发送请求只是为了让我的实例保持活动状态时间。
app.yaml:
runtime: php55
api_version: 1
service: amp-page
handlers:
- url: .*
script: main.php
skip_files:....
当我尝试 Google 中的 PageSpeed Insights
时,我在第一次尝试时遇到此错误:
Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse could
not reliably load the requested page. Check that you are testing the
correct URL and that the server is responding properly to all
requests. (Status code: 500)
现在,当我在经常收到 84/100(移动) 99/100(桌面) 后再次尝试时。
这是一个巨大的差异,这就是我问的原因。它会解决手动缩放的问题,还是有任何其他方法可以让我的实例或请求像第二次尝试一样更快?
谢谢!
一种选择是通过您的 cron.yaml 文件创建一个 cron 作业,该作业每隔 X 分钟请求一个已知页面,以确保您始终有一个实例 运行。
在您的应用程序中创建一个处理程序来执行 php 脚本和 returns 某种输出。不是数据库繁重的东西。可以像回声一样简单 "ok";
要保留至少一个实例运行(即使没有流量)你要设置 min_instances app.yaml
scaling element 到 1
:
min_instances
Optional. The minimum number of instances for App Engine to create for
this module version. These instances serve traffic when requests
arrive, and continue to serve traffic even when additional instances
are started up as required to handle traffic.
Specify a value from 0 to 1000. You can set the parameter to the value
0 to allow scaling to 0 instances to lower costs when no requests are
being served. Note that you are charged for the number of instances
specified whether they are receiving traffic or not.
Important: If you use appcfg from the App Engine SDK for PHP to deploy, you cannot use this parameter in your app.yaml. Instead,
set the parameter as described in Setting Autoscaling Parameters in
the API Explorer, or by using the App Engine Admin API.
否则自动缩放将关闭您的空闲实例,使下一个请求成为(长)加载请求。
旁注:您还可以 configure warmup requests(创建他们的 URL 是其中的一部分,它不是任意静态 URL)以进一步减少用户请求成为加载请求。您无法完全消除它们——实例不会永远存在,预热请求也不是 100% 有效,它们只是尽力而为的解决方案。
我有一个关于 Google App Engine 的问题。我知道第一个请求将比第二个请求花费更长的时间,因为实例是如何缩放的。但就我而言,差异非常大。我没有手动缩放,只有标准的自动缩放,我想就我应该做什么提出一些建议。
这是我的情况:
我有一个电子商务网站的 AMP 项目(https://amp.dev/)。所以我没有任何静态 URL 可以设置 Google App Engine 推荐的预热请求。 url 是这样的:amp.store/product/{productname}
,所以 {productname}
是动态的,我有超过 1000 种产品,无法向那些 url 发送请求只是为了让我的实例保持活动状态时间。
app.yaml:
runtime: php55
api_version: 1
service: amp-page
handlers:
- url: .*
script: main.php
skip_files:....
当我尝试 Google 中的 PageSpeed Insights
时,我在第一次尝试时遇到此错误:
Lighthouse returned error: ERRORED_DOCUMENT_REQUEST. Lighthouse could not reliably load the requested page. Check that you are testing the correct URL and that the server is responding properly to all requests. (Status code: 500)
现在,当我在经常收到 84/100(移动) 99/100(桌面) 后再次尝试时。
这是一个巨大的差异,这就是我问的原因。它会解决手动缩放的问题,还是有任何其他方法可以让我的实例或请求像第二次尝试一样更快?
谢谢!
一种选择是通过您的 cron.yaml 文件创建一个 cron 作业,该作业每隔 X 分钟请求一个已知页面,以确保您始终有一个实例 运行。
在您的应用程序中创建一个处理程序来执行 php 脚本和 returns 某种输出。不是数据库繁重的东西。可以像回声一样简单 "ok";
要保留至少一个实例运行(即使没有流量)你要设置 min_instances app.yaml
scaling element 到 1
:
min_instances
Optional. The minimum number of instances for App Engine to create for this module version. These instances serve traffic when requests arrive, and continue to serve traffic even when additional instances are started up as required to handle traffic.
Specify a value from 0 to 1000. You can set the parameter to the value 0 to allow scaling to 0 instances to lower costs when no requests are being served. Note that you are charged for the number of instances specified whether they are receiving traffic or not.
Important: If you use appcfg from the App Engine SDK for PHP to deploy, you cannot use this parameter in your app.yaml. Instead, set the parameter as described in Setting Autoscaling Parameters in the API Explorer, or by using the App Engine Admin API.
否则自动缩放将关闭您的空闲实例,使下一个请求成为(长)加载请求。
旁注:您还可以 configure warmup requests(创建他们的 URL 是其中的一部分,它不是任意静态 URL)以进一步减少用户请求成为加载请求。您无法完全消除它们——实例不会永远存在,预热请求也不是 100% 有效,它们只是尽力而为的解决方案。