为什么在Google App Engine中始终只有第一次请求才会出现11秒的延迟?

时间:2022-12-05 22:57:48

I am deploying my Nodejs sample app to Google App Engine Flexible env and when I am using google app engine URL which is in the form appspot.com to hit my API, it is taking around 11 secs to send response from my mobile data, but other APIs are sending response in milisecs.

我正在将我的Nodejs示例应用程序部署到Google App Engine Flexible env,当我使用appspot.com形式的谷歌应用引擎URL来点击我的API时,从我的移动数据发送响应需要大约11秒,但是其他API以milisecs发送响应。

Also, the time delay is only happening when I am opening my android app and sending request to the server after that all requests are taking normal time, and again delay is coming when I again open the app and send request to the server.

此外,时间延迟只发生在我打开我的Android应用程序并在所有请求正常时间之后向服务器发送请求时,再次延迟即将到来,当我再次打开应用程序并向服务器发送请求时。

Edit - I found that

编辑 - 我发现了

This can be a caused when your application is still booting up or warming up instances to serve the request and can be called as loading latency. To avoid such scenarios you can implement health check handler like readiness check so that your application will only receive traffic when its ready

这可能是您的应用程序仍在启动或预热实例以服务请求时引起的,并且可以称为加载延迟。为了避免这种情况,您可以实现运行状况检查处理程序,如准备检查,以便您的应用程序只在准备就绪时才会收到流量

That's why I checked in my Logs that readiness check is performed sometimes around 1 sec and sometimes around 200 ms

这就是为什么我在我的日志中检查了有时执行准备检查的时间大约是1秒,有时大约是200毫秒

为什么在Google App Engine中始终只有第一次请求才会出现11秒的延迟?

Can anyone please tell me is there anything wrong in warming up my instances because I don't think cold boot time is causing this problem.

任何人都可以告诉我在预热实例时有什么不对,因为我不认为冷启动时间会导致这个问题。

Edit 2

I have also tried to set min_num_instances: 2 so that once loaded atleast my 2 instances will again not get boot up, but the thing is delay is again same.

我也尝试设置min_num_instances:2,这样一旦加载至少我的2个实例将再次无法启动,但事情是延迟再次相同。

Edit 3

runtime: nodejs
#vm: true
env: flex

automatic_scaling:
  min_num_instances: 2
  max_num_instances: 3

Edit 4

I am noticing a strange behaviour that when I am using this app Packet Capture to capture traffic, then all https requests (if I am not enabling SSL Proxying) and all Http requests are executing in milisecs whereas without using this app all Http/Https requests are taking 11-16 secs of delay.

我注意到一个奇怪的行为,当我使用此应用程序Packet Capture捕获流量,然后所有https请求(如果我没有启用SSL代理)和所有Http请求正在milisecs执行而不使用此应用程序所有Http / Https请求正在延迟11-16秒。

I don't know how but is there any certificate kind of issue here?

我不知道怎么样,但这里有什么证书问题?

Edit 5

Below I have attached Network Profiler where delay is coming 15 secs

下面我已经连接了Network Profiler,延迟时间是15秒

为什么在Google App Engine中始终只有第一次请求才会出现11秒的延迟?

Please Help

2 个解决方案

#1


2  

Depends on which App Engine you are using and how you setup the scaling, there's always a loading time if you don't have a ready instance to serve a request. But if you have readiness check to ensure your instance is ready (and not cold started for the request), then there shouldn't be a problem.

取决于您使用的App Engine以及如何设置缩放,如果您没有准备好的实例来提供请求,则始终会有加载时间。但是,如果您已准备好检查以确保您的实例已准备好(并且没有为请求冷启动),那么应该没有问题。

Can you find a loading request or any corresponding slow request in your logs? If not, then it's likely an issue with the app. If possible, instead of calling this API on your app, do it from two apps (one is already open, one is not). So you make calls from both apps and if you notice that the one that's already open is getting a response faster than the other one, that means that's a problem with the app itself. App Engine can't determine whether or not your app is pre-opened so any difference would be client side.

您能在日志中找到加载请求或任何相应的慢速请求吗?如果没有,那么它可能是应用程序的问题。如果可能的话,不要在你的应用程序上调用此API,而是从两个应用程序中执行此操作(一个已经打开,一个不是)。因此,您可以从两个应用程序进行调用,如果您发现已经打开的应用程序的响应速度比另一个更快,则表示应用程序本身存在问题。 App Engine无法确定您的应用是否已预先打开,因此任何差异都将是客户端。

=== Additional information ===

===其他信息===

In the your logs, there's no delay at all. The request enter Google and was processed within a few milliseconds. I am sure there's something application-side. Maybe your app is constructing the request URL (first request) from some other source that results in the delay? App Engine has no knowledge of whether or not your app is opened or not or whether it's sending a first request after being opened, it cannot act differently based on it. As long as your App Engine instance is ready and available, it will treat your request the same way regardless of whether or not it's your first request after the app is opened.

在您的日志中,根本没有延迟。请求进入Google并在几毫秒内处理完毕。我确信应用程序方面有一些东西。也许你的应用正在构建来自其他来源的请求URL(第一个请求)导致延迟? App Engine不知道您的应用程序是否被打开,或者它是否在打开后发送第一个请求,它不能基于它采取不同的行动。只要您的App Engine实例准备就绪并且可用,它将以相同的方式处理您的请求,无论它是否是您在应用程序打开后的第一个请求。

#2


0  

Last time I checked I remember having to put a warmup request handler so that Google would know that the instance is up and running and can be used to answer calls. Keep in mind that code has to be EXACTLY under the endpoint you specify in the handler under the yaml file. (Wouldn't be the first time someone forgets that)

上次我检查时,我记得必须放置一个预热请求处理程序,以便Google知道该实例已启动并正在运行并可用于接听电话。请记住,代码必须完全位于您在yaml文件下的处理程序中指定的端点下。 (这不是第一次有人忘记了)

Here are the docs https://cloud.google.com/appengine/docs/standard/python/configuring-warmup-requests this is python specific, but you can also check other languages like Go, Java, and such in the docs.

以下是文档https://cloud.google.com/appengine/docs/standard/python/configuring-warmup-requests这是特定于python的,但您也可以在文档中查看其他语言,如Go,Java等。

If the problem is client dependant (each time a new clients spawns and makes a call it gets the latency) then it is most likely, either a problem with the client app itself or with initialization, registration or DNS resolution.

如果问题是客户端依赖的(每次新客户端生成并进行调用都会产生延迟),那么很可能是客户端应用程序本身的问题,或者是初始化,注册或DNS解析。

You could also try to reproduce the requests with CURL or similar, and see if also with those you see the mentioned delay.

您也可以尝试使用CURL或类似方法重现请求,并查看是否还有那些您看到上述延迟的请求。

#1


2  

Depends on which App Engine you are using and how you setup the scaling, there's always a loading time if you don't have a ready instance to serve a request. But if you have readiness check to ensure your instance is ready (and not cold started for the request), then there shouldn't be a problem.

取决于您使用的App Engine以及如何设置缩放,如果您没有准备好的实例来提供请求,则始终会有加载时间。但是,如果您已准备好检查以确保您的实例已准备好(并且没有为请求冷启动),那么应该没有问题。

Can you find a loading request or any corresponding slow request in your logs? If not, then it's likely an issue with the app. If possible, instead of calling this API on your app, do it from two apps (one is already open, one is not). So you make calls from both apps and if you notice that the one that's already open is getting a response faster than the other one, that means that's a problem with the app itself. App Engine can't determine whether or not your app is pre-opened so any difference would be client side.

您能在日志中找到加载请求或任何相应的慢速请求吗?如果没有,那么它可能是应用程序的问题。如果可能的话,不要在你的应用程序上调用此API,而是从两个应用程序中执行此操作(一个已经打开,一个不是)。因此,您可以从两个应用程序进行调用,如果您发现已经打开的应用程序的响应速度比另一个更快,则表示应用程序本身存在问题。 App Engine无法确定您的应用是否已预先打开,因此任何差异都将是客户端。

=== Additional information ===

===其他信息===

In the your logs, there's no delay at all. The request enter Google and was processed within a few milliseconds. I am sure there's something application-side. Maybe your app is constructing the request URL (first request) from some other source that results in the delay? App Engine has no knowledge of whether or not your app is opened or not or whether it's sending a first request after being opened, it cannot act differently based on it. As long as your App Engine instance is ready and available, it will treat your request the same way regardless of whether or not it's your first request after the app is opened.

在您的日志中,根本没有延迟。请求进入Google并在几毫秒内处理完毕。我确信应用程序方面有一些东西。也许你的应用正在构建来自其他来源的请求URL(第一个请求)导致延迟? App Engine不知道您的应用程序是否被打开,或者它是否在打开后发送第一个请求,它不能基于它采取不同的行动。只要您的App Engine实例准备就绪并且可用,它将以相同的方式处理您的请求,无论它是否是您在应用程序打开后的第一个请求。

#2


0  

Last time I checked I remember having to put a warmup request handler so that Google would know that the instance is up and running and can be used to answer calls. Keep in mind that code has to be EXACTLY under the endpoint you specify in the handler under the yaml file. (Wouldn't be the first time someone forgets that)

上次我检查时,我记得必须放置一个预热请求处理程序,以便Google知道该实例已启动并正在运行并可用于接听电话。请记住,代码必须完全位于您在yaml文件下的处理程序中指定的端点下。 (这不是第一次有人忘记了)

Here are the docs https://cloud.google.com/appengine/docs/standard/python/configuring-warmup-requests this is python specific, but you can also check other languages like Go, Java, and such in the docs.

以下是文档https://cloud.google.com/appengine/docs/standard/python/configuring-warmup-requests这是特定于python的,但您也可以在文档中查看其他语言,如Go,Java等。

If the problem is client dependant (each time a new clients spawns and makes a call it gets the latency) then it is most likely, either a problem with the client app itself or with initialization, registration or DNS resolution.

如果问题是客户端依赖的(每次新客户端生成并进行调用都会产生延迟),那么很可能是客户端应用程序本身的问题,或者是初始化,注册或DNS解析。

You could also try to reproduce the requests with CURL or similar, and see if also with those you see the mentioned delay.

您也可以尝试使用CURL或类似方法重现请求,并查看是否还有那些您看到上述延迟的请求。