---
title: "Slow first requests on new Cloud Run instances: connection setup or the query? | Proofline"
description: "Time the database connection and the query separately on each new instance's first requests."
url: https://proofline.sh/learn/cloud-run-cold-start-cloud-sql-connect-latency/
---

[Learning center](/learn/)

# Slow first requests on new Cloud Run instances: connection setup or the query?

Time the database connection and the query separately on each new instance's first requests. If opening the connection takes most of the time, open the pool during startup and give startup more CPU; if the query does, the cold start is not the cause and the database is the place to look.

Capacity overruns The Proofline team November 23, 2026 7 min read

## How it shows up

Latency rises whenever Cloud Run adds instances: after a deploy, at a traffic step, when a service scales out or from zero. Most requests stay fast, and the slow ones are the first one or two each new instance serves. Cloud Run separates starting an instance from processing requests, so a request can wait for a new instance to start; a request that waits pends for up to 3.5 times the service's average startup time or 10 seconds, whichever is greater. [Container startup](https://cloud.google.com/run/docs/tips/general) · [Pending requests](https://cloud.google.com/run/docs/about-instance-autoscaling)

The startup that Cloud Run measures ends when the container listens on its port. Anything the application does after that, on its first request, adds to that request's latency. A database connection opened lazily, on first use, is one such step, and it is more than a TCP handshake. Through Cloud Run's built-in connection or a language connector, the client first obtains the instance's connection details and an ephemeral certificate from the Cloud SQL Admin API, then completes TLS and PostgreSQL authentication. Google's tips page names the cost: lazy initialization adds latency to the first requests to new instances, and under load during a deploy it can cause overscaling and dropped requests. [Lazy initialization](https://cloud.google.com/run/docs/tips/general) · [Connector API calls](https://cloud.google.com/sql/docs/quotas) · [Connect from Cloud Run](https://cloud.google.com/sql/docs/postgres/connect-run)

## Check 1: are the slow requests the first on their instance?

Read the request log with the instance and latency of each request:

```
gcloud logging read \
  'resource.type="cloud_run_revision"
   AND resource.labels.service_name="SERVICE"
   AND logName="projects/PROJECT/logs/run.googleapis.com%2Frequests"
   AND timestamp>="START_TIME"' \
  --project PROJECT --order=asc --limit=1000 \
  --format='value(timestamp, labels.instanceId, httpRequest.latency, httpRequest.status)'
```

Group by `labels.instanceId` and compare each instance's first requests with its later ones. Cloud Run's `varlog/system` log records each instance start with a reason: `AUTOSCALING`, `DEPLOYMENT_ROLLOUT` or `MANUAL_OR_CUSTOMER_MIN_INSTANCE`. [Cloud Run logs](https://cloud.google.com/run/docs/logging) · [LogEntry HttpRequest](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry)

If the slow requests are spread across old and new instances alike, the cold start is not the explanation; read [latency after a deploy](/learn/deploy-latency-spike/) instead.

## Check 2: split connect time from query time

The request log cannot separate the two. The application has to: log, per request, the time spent borrowing or opening a connection and the time spent in the query, with the instance's identity. Many pools and drivers expose events or hooks for connection creation; a timer around the pool checkout and another around the query is enough. Log `K_REVISION` with them so the lines can be grouped by revision. [Container runtime contract](https://cloud.google.com/run/docs/container-contract)

| First request on a new instance | Later requests on the same instance | Reading |
| --- | --- | --- |
| Connect time dominates | Connect time near zero, query time normal | Connection setup on the request path. Move it to startup |
| Query time dominates | Query time normal | The first query is slow for its own reasons, such as a cold cache in the application. Not the connection |
| Query time dominates | Query time just as high | The query is slow everywhere. Look at the database and [whether the deploy changed the load](/learn/did-our-deploy-overload-a-dependency/) |
| Connect time dominates, and connects fail or time out | Same | Not latency: a connection problem. Use [the four stages](/learn/cloud-run-cloud-sql-connection-errors/#stage) |

## Check 3: what the revision does at startup

```
gcloud run revisions describe REVISION \
  --project PROJECT --region REGION \
  --format='yaml(metadata.annotations, spec.containers[0].resources)'
```

The annotation `run.googleapis.com/startup-cpu-boost` records startup CPU boost. When it is on, Cloud Run gives the instance more CPU during startup and for 10 seconds after: 2 CPUs for a limit up to 1, 4 for 2, 8 for 4 and above. `gcloud` enables it by default on new services when the flag is not given, so older services and services deployed by other tools may not have it. [Revision annotations](https://cloud.google.com/run/docs/reference/rest/v1/ObjectMeta) · [Startup CPU boost](https://cloud.google.com/run/docs/configuring/services/cpu) · [`--cpu-boost`](https://cloud.google.com/sdk/gcloud/reference/run/services/update)

## Choose the fix

| Lever | Effect on the first request | Cost or risk |
| --- | --- | --- |
| Open the pool at startup, before listening | Connection setup happens before the instance takes requests; the first request finds a connection ready | Startup takes longer, so requests that wait for a new instance wait longer. A database that is down now fails the startup probe instead of a request ([revision not ready](/learn/cloud-run-revision-not-ready/)) |
| Startup CPU boost | Work done during startup, and in the 10 seconds after, gets more CPU | Billed for the boosted CPU during that time |
| Minimum instances | Fewer requests meet a new instance at all | Billed while idle; idle instances still need [protection against stale connections](/learn/cloud-run-idle-cpu-stale-cloud-sql-connections/) |

Create the pool in global scope so every request on the instance reuses it; Cloud Run reuses instances across requests, though any single request cannot know it will benefit. Opening one or two connections at startup is usually enough to take the setup off the first request; opening the full pool at startup multiplies the connections each new instance needs before it serves anything, which matters during a scale-out near the [connection budget](/learn/cloud-run-cloud-sql-connection-budget/). [Global variables](https://cloud.google.com/run/docs/tips/general) · [Minimum instances](https://cloud.google.com/run/docs/configuring/min-instances)

Enabling startup CPU boost or changing the startup code deploys a new revision. With `gcloud`, `gcloud run services update SERVICE --cpu-boost` does that.

## A worked fixture: two slow mornings

The fixture is illustrative. `orders-api-00018` runs with a CPU limit of 1 and no `run.googleapis.com/startup-cpu-boost` annotation, because the service was created by an older Terraform module. Its code creates the SQLAlchemy engine at import and opens connections on first use. The application logs `db_connect_ms` and `query_ms` for every request.

**Morning A, 2026-11-20.** Traffic doubles at 09:00 UTC and Cloud Run adds instances for `AUTOSCALING`.

| Time (UTC) | Instance | Request latency | `db_connect_ms` | `query_ms` |
| --- | --- | --- | --- | --- |
| 09:00:04 | `…7d10` started |  |  |  |
| 09:00:06 | `…7d10` | 2,840 ms | 2,410 | 35 |
| 09:00:06 | `…7d10` | 2,910 ms | 2,460 | 41 |
| 09:00:09 | `…7d10` | 62 ms | 0 | 38 |

Twelve new instances show the same shape: about 2.4 seconds of connection setup on their first concurrent requests and nothing afterwards. The time is on the request path. The team opens two connections during startup, before the server listens, and deploys `orders-api-00019` with `--cpu-boost`. On the next scale-out, new instances take about 1.5 seconds longer to start, and their first requests measure 40 to 70 ms.

**Morning B, 2026-11-22.** After a release that adds a report query, first requests on new instances again take about 2.6 seconds.

| Instance | Request | `db_connect_ms` | `query_ms` |
| --- | --- | --- | --- |
| `…a301` (new) | first | 45 | 2,580 |
| `…a301` (new) | fifth | 0 | 2,490 |
| `…5c2e` (two hours old) | any | 0 | 2,530 |

Connection setup takes 45 ms and the query takes the rest on new and old instances alike. The new instances were only where people looked first. The report query needs an index; startup settings will not change it.

## Where the checks mislead

Startup latency and request latency overlap. A request that waited for a new instance includes the instance's startup in its own latency, so a slow first request with a fast `db_connect_ms` may still be a slow container start. Compare the instance's `varlog/system` start time with its first request's timestamp.

The application's timers measure what the code sees. A pool checkout that waits for a free connection, because the pool is full, looks like slow connecting. Log whether the checkout opened a new connection or waited for an existing one.

The Admin API calls that a connector makes when an instance starts count toward a per-minute quota. A scale-out that starts many instances at once can turn slow first requests into failed ones: see [Admin API quota during scale-out](/learn/cloud-sql-admin-api-quota-cloud-run-scale-out/).

## Questions

### Why is the first request to a new Cloud Run instance slow when it uses Cloud SQL?

If the application opens its database connection on first use, that request pays for the connection setup: obtaining the connection details and certificate through the Cloud SQL Admin API, TLS and authentication. Later requests reuse the connection. Timing connect and query separately shows whether this is the cause.

### Does startup CPU boost help Cloud SQL connection time on Cloud Run?

It gives the instance more CPU during startup and for 10 seconds after. Connection setup the application does in that window gets the extra CPU; setup done on a later request does not. Measure before and after, since the network and the database also take part.

### Should I open all pool connections when a Cloud Run instance starts?

Opening one or two removes the setup from the first request. Opening the full pool makes every new instance claim its whole share of database connections before serving, which can exhaust the connection limit during a large scale-out.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Dependency timeouts only from new ECS tasks or Cloud Run revisions](/learn/dependency-timeouts-only-from-new-tasks/)
    
    Network outages The Proofline team November 20, 2026 9 min read
    
-   ### [The first request after idle gets a dead Cloud SQL connection](/learn/cloud-run-idle-cpu-stale-cloud-sql-connections/)
    
    Broken dependencies The Proofline team November 23, 2026 7 min read
