Trying to run this site with Cloud Run in GCP
This site is hosted on GCP with App Engine. I've never tried App Engine before, so I can't really be sure that App Engine would be a good fit for this blog site. However, it seems pretty easy to run applications on App Engine according to some youtube videos so I just went with it.
Running this site on App Engine doesn't require lots of efforts. I just search "GCP App Engine Spring Boot" in youtube and followed the instructions from those youtube videos (most of them are pretty much the same set of instructions). However the process is not as smooth as I would've hoped for. I did encounter an issue that makes my application failing on App Engine. And the thing with App Engine is that it doesn't expose much error information when my application fails to run. It just keeps saying that my application is failing.
Luckily for me, I was knowledgable enough to link this issue with memory usage. This is, after all, a Java application and the default provisioned memory in App Engine is pretty small. Instances might not have enough memory to kick start my Spring Boot Application. And indeed, after I changed the CPU and memory resource requirement in my app.yaml file, my application was running successfully in App Engine.
Now the really issue is, after one month of running my blog site, I got a very fat bill from GCP. It was roughly 120 dollars for my application. 120 dollar is ridiculously huge amount of money given that my blog site has close to zero traffic. I shouldn't pay up to 120 dollars for a site that nobody visits. So I want to get to the bottom of it and see who is silently eating my pie.
My setting is pretty simple. I have one service running in App Engine. It asks for two instances, and each instance has 2 cpus and 4 GB of memory. I use the google cloud pricing calculator to give me a rough estimation of my cost and the result isn't really appeasing. It simply costs too much to have that kinds of settings.
Later I change my setting to 1 instance and this instance would have 1 cpu and 2 GB of memory. This would greatly bring cost down to 30 dollars every month.
I am already very happy with this. But I randomly run into a blog talking about Cloud Run as GCP's serverless solution that maybe I can try with serverless to bring down my cost again. And here is my process to try to migrate my blog site to Cloud Run.
First of all I also have a VM running in the same project that starts a mysql database server. My App Engine application is connecting to that VM for the database usage. This poses a particular challenge for Cloud Run application since Cloud Run applications don't share the same network with VM even if they are in the same project and same region.
There are however, two ways to fix this issue.
- Stop using VM to host mysql database and switch to Cloud SQL, since Cloud Run is automatically connected to Cloud SQL.
- Create a Serverless VPC access connector and hook you Cloud Run application to the given connector so application can talk to VPC.
Cloud SQL seems like a good idea, except that it's very expensive once we want to allocate any kind of decent resource to the mysql database. According to the Pricing Calculator, once I choose a standard (or lightweight) hosts with 1 cpu and 3.75 GB of memory, the cost would be at least 50 dollars. The only way to bring the cost down is to use micro hosts, which I assume would hammer the performance of mysql database, since it only have 1 cpu and 0.75 GB of memory. This don't seem to be the way to go.
Serverless VPC connector would be good fit since it only cost roughly 20 dollars. I would come back to it later.