简体   繁体   English

Google AppEngine将所有请求发送到同一实例

[英]Google AppEngine sending all requests to same instance

Lately, I have seen GAE taking much, much longer to process requests than it did just a week ago. 最近,我看到GAE处理请求的时间比一周前花费的时间长得多。 Nothing changed in my code, but GAE now is taking 4000-12000ms to respond to requests. 我的代码没有任何变化,但是GAE现在需要4000-12000毫秒来响应请求。 What makes is worse is that I have plenty of instances available with 0 requests on them. 更糟糕的是,我有很多实例,其中有0个请求。
Has anyone else seen this happen? 有人看到过这种情况吗? What can I do to fix it?I have gone as far as to spin up 15 extra instances (and paid through the nose for them) but nothing seems to send requests to the other idle instances reliably. 我可以做些什么来解决呢?我已经努力解决了15个额外的实例(并为它们支付了费用),但是似乎没有任何东西可以可靠地向其他空闲实例发送请求。 My bill has gone from 70-90c/day to $5-8/day without any code change or increase in traffic. 我的帐单从每天70-90c上涨到每天5-8美元,而无需更改代码或增加流量。 In fact, I am losing traffic because of the huge latency. 实际上,由于巨大的延迟,我正在失去流量。

    QPS*    Latency*    Requests    Errors  Age Memory  Availability
    0.000   0.0 ms  1378    0   10:10:09    57.9 MBytes Dynamic
    0.000   0.0 ms  1681    0   15:39:57    57.2 MBytes Dynamic
    0.017   9687.0 ms   886 0   10:19:10    56.7 MBytes Dynamic

I recommend installing AppStats to get a picture of what's taking so long in each request. 我建议安装AppStats以获得每个请求花费这么长时间的图像。 I'd guess that you're having some contention issues or large numbers of reads/writes caused by some new data configuration. 我猜您是由于某些新数据配置而引起一些争用问题或大量读/写操作。

The idle instances won't help decrease latency - it looks like every request takes a long time, and with less than one request per minute (in this sample anyway), 10s requests could run serially on the same instance. 空闲实例无助于减少延迟-似乎每个请求都花费很长时间,并且每分钟少于一个请求(无论如何在此示例中),同一实例上可以连续运行10s个请求。

We have a similar problem in our app. 我们的应用程序中存在类似的问题。 In our case, we are under the impression that GAE's scheduler did a poor job in balancing requests to existing instances. 在我们的案例中,我们给人的印象是,GAE的调度程序在平衡请求到现有实例方面做得很差。

In some cases, the scheduler decided to spin up new instances instead of re-using already existing ones. 在某些情况下,调度程序决定启动新实例,而不是重新使用现有实例。 Since spinning a new instance took 5 to >45 seconds, I suspect this might be what happened to you. 由于旋转新实例需要5到> 45秒,因此我怀疑这可能是发生在您身上的事情。

Try to investigate the following and see if it helps you: 尝试调查以下内容,看看是否有帮助:

  1. Make sure your app has thread-safe enabled so that you could process concurrent requests. 确保您的应用启用了线程安全,以便您可以处理并发请求。 You could configure this in your app.yaml if you are using Python, or in your appengine-web.xml if you use Java. 如果使用Python,则可以在app.yaml中进行配置;如果使用Java,则可以在appengine-web.xml中进行配置 Of course, you also need to make sure that the code in your app is threadsafe. 当然,您还需要确保应用中的代码是线程安全的。
  2. In your application settings, if it is still set on automatic, change the minimum pending latency to a non-automatic setting. 在您的应用程序设置中,如果仍设置为自动, 请将最小等待延迟更改为非自动设置。 I'd suggest around 10 seconds for now, but you could experiment later on which setting would suit you the most. 我建议现在大约10秒钟,但是您可以稍后尝试哪种设置最适合您。 This force the scheduler to wait for a certain time to see if any instance is available within the time before spinning up a new instance. 这迫使调度程序等待一定的时间,以查看在扩展新实例之前该时间内是否有任何实例可用。

Now, to answer your original question regarding sending all requests to same instance , as far as I know there is no way to address a specific front-end instance in order to direct the requests to that particular instance. 现在,就我所知,要回答有关sending all requests to same instance原始问题,据我所知,没有办法解决特定的前端实例以将请求定向到该特定实例的问题。

What you could do is migrate your app to use backend instances instead of the regular frontend instance. 您可以做的是将应用程序迁移为使用后端实例,而不是常规前端实例。 Backends provides a way to directly target any particular instance within it . 后端提供了一种直接定位其中任何特定实例的方法 You could deploy your app in a single backend to have more control on the number of instance that you spawn. 您可以将应用程序部署在单个后端中,以更好地控制生成的实例数量。 And since using the backend bypass the scheduler, you would not encounter latencies caused by new instances spinning up. 而且由于使用了后端绕过调度程序,因此不会遇到由新实例启动引起的延迟。

The major drawback of using this approach is that you lose the auto-scalability benefit of using front-end instances. 使用此方法的主要缺点是您失去了使用前端实例的自动可伸缩性的好处。 But seeing from your low daily billing, I think scalability is not yet a major concern for the scale of your app. 但是从低廉的每日账单来看,我认为可扩展性并不是您应用规模的主要考虑因素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM