Google Cloud Run not scaling up despite large backlog and available instances

Viewed 268

I am seeing something similar to this post. It looked like additional detail was needed to answer that question, so I'm re-asking with my details since those details weren't provided.

I am running a modified version of the Google Cloud Run image processing tutorial example.

I am inserting tasks into a task queue using this create tasks snippet. The tasks from the queue get pushed to my cloud run instance.

The problem is it isn't scaling up and making it through my tasks in a timely manner.

My cloud run service configuration:

  • I have tried setting a minimum of both 0 and 50 instances
  • I have tried a maximum of 100 and 1000 instances
  • I have tried --concurrency=1 and 2, and 8
  • I have tried with --async and without --async

With 50 instances pre-allocated even with concurrency set to 1, I am typically seeing ~10 active container instances and ~40 idle container instances. I have ~30,000 tasks in the queue and it is getting through ~5 jobs/minute.

My tasks queue has the default settings. My containers aren't using a lot of cpu, but they are using a lot of memory.

A process takes about a minute to complete. I'm only running one process per container instance. What additional parameters should be set to get higher throughput?


Edit - adding additional logs

I enabled the logs for the queue, I'm seeing some errors for some of the jobs. The errors look like this:

{
insertId: "<my_id>"
jsonPayload: {
@type: "type.googleapis.com/google.cloud.tasks.logging.v1.TaskActivityLog"
attemptResponseLog: {
attemptDuration: "19.453155s"
dispatchCount: "1"
maxAttempts: 0
responseCount: "0"
retryTime: "2021-10-20T22:45:51.559121Z"
scheduleTime: "2021-10-20T16:42:20.848145Z"
status: "UNAVAILABLE"
targetAddress: "POST <my_url>"
targetType: "HTTP"
}
task: "<my_task>"
}
logName: "<my_log_name>"
receiveTimestamp: "2021-10-20T22:45:52.418715942Z"
resource: {
labels: {
location: "us-central1"
project_id: "<my_project>"
queue_id: "<my-queue>"
target_type: "HTTP"
}
type: "cloud_tasks_queue"
}
severity: "ERROR"
timestamp: "2021-10-20T22:45:51.459232147Z"
}

I don't see errors in the cloud run logs.


Edit - Additional Debug Information

I tried to take the queue out of the equation to determine if it is cloud run or the queue. Instead I directly used curl to post to the url. Some of the tasks ran successfully, for others I received an error. In the below logs empty lines are successful:

upstream connect error or disconnect/reset before headers. reset reason: connection termination


upstream connect error or disconnect/reset before headers. reset reason: connection termination
upstream connect error or disconnect/reset before headers. reset reason: connection termination
upstream connect error or disconnect/reset before headers. reset reason: connection termination

upstream connect error or disconnect/reset before headers. reset reason: connection termination

This makes me think cloud run isn't handling all of the incoming requests.


Edit - task completion time test

I wanted to test if the time it takes to complete a task causes any issues with CloudRun and the Queue scaling up and keeping up with the tasks.

In place of the task I actually want completed I put a dummy task that just sleeps for n seconds and prints the task details to stdout (which I can read in the cloud run logs).

With n set to 0, 5, 10 seconds I see the number of instances scale up and it keeps up with the tasks being added to the queue. With n set to 20 seconds or more I see that less CloudRun instances are instantiated and items accumulate in the task queue. I see more errors with the Unavailable status in my logs.

According to this post:

Cloud Run offers a longer request timeout duration of up to 60 minutes

So it seems that long running tasks are expected. Is this a Google bug or am I missing setting some parameter?

1 Answers
  1. I do not think this is a Cloud Run Service problem. I think this is an issue with how you have Tasks setup.

  2. The dates in the log entry look odd. Take a look at the receiveTimestamp and the scheduleTime. The task is scheduled for six hours before the receive time. Do you have a timezone problem?

  3. According to the documentation, if the response_time is not set then the task was not attempted. It looks like you are scheduling tasks incorrectly and the tasks never run.

Search for the text The status of a task attempt. in this link:

Types for Google Cloud Tasks

Related