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.