本文介绍了Appengine - 限制实例的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 实际上应该有一个限制到特定数量的实例的选项,无论如何。 在应用程序设置菜单中,您所能做的只是限制IDLE实例的最大数量,我不确定它是否按预期工作。我的意思是我将最大空闲实例设置为1,将最小待处理延迟设置为15秒,但我仍然偶尔会看到2个实例偶尔运行,长时间没有请求。他们在空闲15分钟后不应该关闭吗?为什么它甚至用这些设置触发了一个秒实例,考虑到没有请求达到15秒的延迟? 我运行一个简单的我的IP是什么Python应用程序,真的不需要高性能。我的意思是,如果响应时间在100毫秒或5秒之后,它确实没有什么区别,重要的是只有一个实例正在运行,所以每天28个实例小时不会耗尽。解决方案我的应用程序目前只有少量的流量,所以付出一点点钱都是我的问题。学习并尝试了如何优化实例类的许多选项。我发现以下设置为我提供了最低 结算费率 在Google Appengine上启用帐单状态的应用程序。 我使用F1类来设置Frontend实例。 这里我是yaml版本的代码。 instance_class:F1 automatic_scaling: max_idle_instances:1#默认值 min_pending_latency:自动#默认值 max_pending_latency:30ms 我使用B1类来设置Backend实例。 这里我是yaml版本的代码。 instance_class:B1 basic_scaling: max_instances:1 idle_timeout:10m 这里是放在appeengine中的代码。 web.xml(如果使用maven编译java) < threadsafe> true< / threadsafe> < instance-class> B1< / instance-class> < basic-scaling> < max-instances> 1< / max-instances> <空闲超时> 10m< /空闲超时> < / basic-scaling> 通常我运行4个模块,2个F1级别模块和2个B1级别模块。他们每天花费我0。然而,当我的网站忙于交通时,我将课程提高到F2和B2,每日总费用低于0.50美元。 以下是一些提示以减少收费实例: 如果您的F类模块比 28小时免费每日限额 ,请考虑使用 Class B 。借此,您可以获得另一个 9个免费实例小时 。您可以使用它来运行其他任何工作,例如 cron , 任务 或 background 。确保自动关闭 / _ ah / stop 正常工作。不要让剩余的空闲实例数过来。 简化您的主页或着陆页以最少实例运行。如果可能的话不超过一个实例。只有当你的访问者在你的页面上做些什么时,让它运行更多的实例。考虑通过采用 blobstore 的免费配额来优化您的网站, 数据存储 和 数据存储 。您也可以在 Google托管库 上使用该脚本以最大限度地减少出站带宽。 每当流量请求发送到模块的处理程序时,它肯定会运行一个实例。因此除了设置 静态缓存过期 建议您使用Google云端存储(GCS)从您的存储分区中提供静态文件,如html,图像,js和css 客户端库 和 gsutil 。 将其设置为 公共读 。有了这个方案,您的实例将会显着减少,因为它不会受到请求的影响。您可能会认为 GCS每月定价 为比起小时实例成本 。 按照解释子域名(包括 www ), ://cloud.google.com/storage/docs/website-configuration#tipsrel =nofollow noreferrer> here 。此外,如果您喜欢使用空白域,则可以通过 Alias / AName 直接发送到GCS (c.storage.googleapis.com) 。 如果您的应用程序基于数据操作动态运行,则需要知道每种类型的数据库都像 MySQL ,Cloud Storage等也会运行一个实例或操作计数器。确保您阻止了任何有害的漫游器流量,并且不为其提供动态页面。建议您考虑使用数据存储小操作。与其他数据库操作相比,这种数据操作将免费。当然,您需要优化代码才能使用它,例如 Quercus 。这里有一些很好的讨论 here , 此处 和 这里 。 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?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. 解决方案 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.I use F1 Class to set Frontend instance.Here i the code in yaml version.instance_class: F1automatic_scaling: max_idle_instances: 1 # default value min_pending_latency: automatic # default value max_pending_latency: 30msI use B1 class to set Backend instance.Here i the code in yaml version.instance_class: B1basic_scaling: max_instances: 1 idle_timeout: 10mAnd 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>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: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 - 限制实例的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 21:07