Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Run is very slow vs. local machine

We have a small script that scrapes a webpage (~17 entries), and writes them to Firestore collection. For this, we deployed a service on Google Cloud Run.

The execution of this code takes ~5 seconds when tested locally using Docker Container image. The same image when deployed to Cloud Run takes over 1 minute.

Even simple command as "Delete all Documents in a Collection", which takes 2-3 seconds locally, takes over 10 seconds when deployed on Cloud Run.

We are aware of Cold Start, and so we tested the performance of Cloud Run on the third, fourth and fifth subsequent runs, but it's still quite slow.

We also experimented with the number of CPUs, instances, concurrency, memory, using both default values as well as extreme values at both ends, but Cloud Run's performance is slow.

Is this expected? Are individual instances of Cloud Run really this weak? Can we do something to make it faster?

The problem with this slowness is that if we run our code for large number of entries, Cloud Run would eventually time out (not to mention the cost of Cloud Run per second)

like image 864
sudcha Avatar asked Apr 11 '20 09:04

sudcha


People also ask

Why is Google Cloud Platform so slow?

Prioritize primary content​ The Google Cloud page loads a large initial JavaScript bundle. The longer it takes to load and initialize this code, the longer it takes to load page-specific code and to render the list of Cloud Functions the user wants to see.

When should I use cloud run?

Cloud Run is intended for those who focus on container-based development versus using source-based systems. The idea is that containers provide separation of duties between the developer and the platform where the container executes.

Does cloud run have cold start?

Does Cloud Run have cold starts? Yes. If a Cloud Run service does not receive requests for a long time, it will take some time to start it again. This will add additional delay to the first request.


1 Answers

Posting answer to my own question as we experimented a lot with this, and found issues in our own implementation.

In our case, the reason for super slow performance was async calls without Promises or callbacks.

What we initially missed was this section: Avoiding background activities

Our code didn't wait for the async operation to end, and responding to the request right away. The async operation then moved to background activity and took forever to finish.


Responding to comments posted, or similar questions that may arise: 1. We didn't try experiment with local by setting up a VM with same config because we figured out the cause sooner.

  1. We are not writing anything on filesystem (yet), and operations are simple calls. But this is a good question, and we'll keep it in mind when we store/write data
like image 144
sudcha Avatar answered Sep 21 '22 07:09

sudcha