Appengine - 限制实例数量 [英] Appengine - Limit the number of instances

查看:33
本文介绍了Appengine - 限制实例数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何都应该有一个选项来限制特定数量的实例.在应用程序设置菜单中,您所能做的就是限制 IDLE 实例的最大数量,我不确定它是否按预期工作.我的意思是我将 Max Idle Instances 设置为 1,将 Min Pending Latency 设置为 15 秒,但我仍然看到 2 个实例偶尔运行,长时间没有请求.他们不是应该在闲置 15 分钟后关闭吗?考虑到没有请求达到 15 秒的延迟,为什么它甚至会使用这些设置触发秒实例?

There should really be a option to limit to a specific number of instances, no matter what. In the application settings menu all you can do is to limit the maximum number of IDLE instances, which I'm not sure if it works as intended. I mean I set the Max Idle Instances to 1 and the Min Pending Latency to 15 seconds, but I still see 2 instances running occasionally, for long period of times with no requests. Aren't they supposed to close after 15 min of being idle? And why does it even fire a seconds instance with those settings, considering that no request reached 15 seconds delay?

我运行了一个简单的我的 IP 是什么"python 应用程序,它确实不需要高性能.我的意思是,如果响应在 100 毫秒或 5 秒之后真的没有任何区别,重要的是只有一个实例在运行,这样每天 28 个实例小时就不会用完.

I run a simple "what's my IP" python app, that really doesn't need high performance. I mean it really doesn't make a difference if the response is after 100ms or 5 seconds, all it matters is that only one instance is running, so that those daily 28 instance hours don't ever run out.

推荐答案

我的应用程序目前只有很少的流量,所以支付一点钱对我来说是一件很重要的事情.在学习并尝试了很多关于如何优化实例类的选项之后.我发现以下设置为我提供了最低的计费率在 Google Appengine 上启用帐单状态的情况下运行应用程序.

My app is currently having only litte number of traffic, so paying even a little dollar is a matter to me. After learning and trying so many option on how to optimize the instance class. I found the following setting that gives me a lowest billing rates on running application with Billing Status Enabled on Google Appengine.

我使用 F1 类来设置前端实例.
这里是 yaml 版本的代码.

I use F1 Class to set Frontend instance.
Here i the code in yaml version.

instance_class: F1
automatic_scaling:
  max_idle_instances: 1  # default value
  min_pending_latency: automatic  # default value
  max_pending_latency: 30ms

我使用 B1 类来设置后端实例.
这里是 yaml 版本的代码.

I use B1 class to set Backend instance.
Here i the code in yaml version.

instance_class: B1
basic_scaling:
  max_instances: 1
  idle_timeout: 10m

这里是放在appeengine.web.xml中的代码(如果用maven编译java)

And here is the code to put in appeengine.web.xml (if compiling java with maven)

<threadsafe>true</threadsafe>
<instance-class>B1</instance-class>
<basic-scaling>
<max-instances>1</max-instances>
<idle-timeout>10m</idle-timeout>
</basic-scaling>

通常我运行4个模块,F1类2个模块,B1类2个模块.他们每天花费我 0.但是,当我的网站因流量而变得繁忙时,我将班级提高到 F2 和 B2,并且每日总成本不到 0.50 美元.

Usually I am running 4 modules, 2 modules in F1 class, and 2 modules in B1 class. They cost me 0 daily. However when my site is getting busy against traffic then I raise up the class to F2 and B2 and the total daily cost is less than US$ 0.50.

以下是减少计费实例的一些技巧:

Here are some tips to reduce the billable instance:

  • 如果您的 F 类模块运行时间超过 28 小时免费每日配额,考虑使用 创建另一个模块B级.这样您就可以再获得 9 个免费实例小时.您可以使用它来运行任何其他作业,例如 crontask背景.确保自动关闭 /_ah/stop 工作正常.不要让长时间空闲的实例被计算在内.
  • 简化您的主页或登录页面,以使用最少的实例运行.如果可能,不超过一个实例.仅当您的访问者在您的页面上执行某些操作时,让它运行更多实例.考虑通过获取 blobstore 的免费配额来优化您的网站em>、数据存储数据存储区.您还可以使用 Google 托管库 上的脚本来最小化输出带宽.
  • 每当流量请求发送到模块的处理程序时,它肯定会运行一个实例.所以除了设置静态缓存过期 建议使用 Google Cloud Storage (GCS) 客户端库gsutil.
    然后将其设置为 public-read.使用此方案,您的实例将显着减少,因为它不受请求的影响.您可能会认为 GCS 每月定价每小时实例成本.
    了解如何使用子域(包括www)将您的存储桶配置为网站,如这里.此外,如果您想使用您的空白域,您可以通过设置 A(主机)和 AAAA,或者如果您的裸域可以设置为 别名/AName直接到 GCS (c.storage.googleapis.com).
  • 如果您的应用程序基于数据操作动态运行,您需要了解每种类型的数据库,例如 MySQL、云存储等也将运行实例或操作计数器.确保您阻止了任何不需要的机器人流量,并且不为它们提供动态页面.我建议您也考虑使用 "Datastore小型运营".与其他数据库操作相比,这种数据操作将花费您免费.当然,您需要优化代码才能像 Quercus 一样使用它.关于它有一些很好的讨论这里此处此处.
  • If your Class F module run more than the 28 hours free daily quota, consider to create another module with Class B. By this you get another 9 free instance hours. You can use it to run any other job like cron, task or background. Make sure the automatic shutdown of /_ah/stop works properly. Don't let a long idle instance left counted.
  • Simplify your homepage or landing page to run with minimum instance. If possible no more than one instance. Let it runs more instance only when your visitor do something on your page. Consider to optimize your site by take the free quota of blobstore, data storage, and datastore. You may also use the script on Google Hosted Libraries to minimize the outgoing bandwidth.
  • Whenever a traffic request is going to a handler of a module it will definitely run an instance. So beside of setting static cache expiration it is advisable to let static files like html, images, js, and css are served from your bucket using Google Cloud Storage (GCS) client library and gsutil.
    Set it then as public-read. With this scheme your instance will be reduced significantly as it has no impact by the request. You might consider that the GCS Monthly Pricing is much cheaper compare to the monthly bill raised by the total cumulative of Hourly Instance Cost.
    Find how to configure your bucket as a website using subdomains (including www) as explained here. Additionally, in case you like to use your blank domain, you can either redirect it to www by set the A (Host) and AAAA, or you can even make it completely independent if your naked domain can be set as an Alias/AName directly to the GCS (c.storage.googleapis.com).
  • If your application is running dynamically based on data operation you need to aware that every type of Database like MySQL, Cloud Storage etc will also run an instance or operation counter. Make sure that you are blocking any unwanted bot traffic and not serving them a dynamic page. I suggest you to consider also to use "Datastore Small Operations". Compare to other database operation this kind of data operation will cost you Free. Of course you will need to optimize your code in order to use it like Quercus. There are some nice discussion on it here, here and here.

这篇关于Appengine - 限制实例数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆