Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appengine - Limit the number of instances

Tags:

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.

like image 967
Chris Avatar asked Aug 07 '13 10:08

Chris


People also ask

What is the role of Google Appengine?

App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps, and then let App Engine take care of provisioning servers and scaling your app instances based on demand.

What are the two kinds of instances available in App Engine standard?

App Engine supports the following scaling types, which controls how and when instances are created: Automatic (default) Basic. Manual.

What type of service is App Engine?

Google App Engine (GAE) is a platform-as-a-service product that provides web app developers and enterprises with access to Google's scalable hosting and tier 1 internet service.

How many App Engine instances does a project have?

You can only have one App Engine App per project. However you can have multiple services and multiple version for each service. Yup. You can create multiple services under the same app.


1 Answers

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: F1 automatic_scaling:   max_idle_instances: 1  # default value   min_pending_latency: automatic  # default value   max_pending_latency: 30ms 

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 

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> 

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.
like image 58
Chetabahana Avatar answered Sep 29 '22 11:09

Chetabahana