Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

long-running job on GCP cloud run

I am reading 10 million records from BigQuery and doing some transformation and creating the .csv file, the same .csv stream data I am uploading to SFTP server using Node.JS.

This job taking approximately 5 to 6 hrs to complete the request locally.

Solution has been delpoyed on GCP Cloud run but after 2 to 3 second cloud run is closing the container with 503 error.

Please find below configuration of GCP Cloud Run.

Autoscaling: Up to 1 container instances CPU allocated: default Memory allocated: 2Gi Concurrency: 10 Request timeout: 900 seconds

Is GCP Cloud Run is good option for long running background process?

like image 326
mayur nimavat Avatar asked Jan 08 '20 13:01

mayur nimavat


People also ask

How long can cloud Run Run?

To minimize the impact of cold starts, Cloud Run may keep some instances idle for a maximum of 15 minutes. These instances are ready to handle requests in case of a sudden traffic spike.

Is aws easier than GCP?

GCP - Difficulty Level. AWS and GCP are equally easy and challenging. There is no specific answer that could declare one easier than the other. There is a learning curve with Google Cloud, but one should also not overlook the fact that due to AWS's market share, many AWS certified engineers are already in the market.

What is the use of cloud run in GCP?

Cloud Run is a managed compute platform that enables you to run containers that are invocable via requests or events. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications.


Video Answer


3 Answers

Update: 2021-Oct

Cloudrun supports background activities.

Configure CPU to be always-allocated if you use background activities
Background activity is anything that happens after your HTTP response has been delivered. To determine whether there is background activity in your service that is not readily apparent, check your logs for anything that is logged after the entry for the HTTP request.

Configure CPU to be always-allocated
If you want to support background activities in your Cloud Run service, set your Cloud Run service CPU to be always allocated so you can run background activities outside of requests and still have CPU access.


like image 22
Espresso Avatar answered Nov 12 '22 03:11

Espresso


You can use a VM instance with your container deployed and perform you job on it. At the end kill or stop your VM.

But, personally, I prefer serverless solution and approach, like Cloud Run. However, Long running job on Cloud Run will come, a day! Until this, you have to deal with the limit of 60 minutes or to use another service.

As workaround, I propose you to use Cloud Build. Yes, Cloud Build for running any container in it. I wrote an article on this. I ran a Terraform container on Cloud Build, but, in reality, you can run any container.

Set the timeout correctly, take care of default service account and assigned role, and, thing not yet available on Cloud Run, choose the number of CPUs (1, 8 or 32) for the processing and speed up your process.

Want a bonus? You have 120 minutes free per day and per billing account (be careful, it's not per project!)

like image 185
guillaume blaquiere Avatar answered Nov 12 '22 03:11

guillaume blaquiere


Is GCP Cloud Run is good option for long running background process?

Not a good option because your container is 'brought to life' by incoming HTTP request and as soon as the container responds (e.g. sends something back), Google assumes the processing of the request is finished and cuts the CPU off.

Which may explain this:

Solution has been delpoyed on GCP Cloud run but after 2 to 3 second cloud run is closing the container with 503 error.

like image 43
winwiz1 Avatar answered Nov 12 '22 03:11

winwiz1