Why the question is not obvious#
Cloud Run's request latency metric measures from when a request reaches the running container to when it leaves, excluding container startup. Every database call the request makes is inside that number, as is every millisecond the container spends computing or waiting for CPU. A slow query and a CPU-starved instance both raise it the same way. Cloud Run metrics
A canary or traffic split makes the comparison easier, because two revisions share one database. When both slow down together, the shared database is the first suspect. When only one does, its own code or its instances are. A shared slowdown does not clear the new revision, though: a new query it sends can load the database for everyone.
This guide is about latency with working connections. If requests fail or wait for a connection, read the hub's stage table first.
Check 1: latency by revision#
In Metrics Explorer, choose the resource type Cloud Run Revision and plot these metrics grouped by revision_name, which every cloud_run_revision series carries. Monitored resource labels · Cloud Run monitoring
| Metric | What it shows |
|---|---|
run.googleapis.com/request_latencies | Distribution of request latency, container entry to exit |
run.googleapis.com/container/cpu/utilizations | Distribution of container CPU utilization across instances |
run.googleapis.com/container/max_request_concurrencies | Distribution of the maximum concurrent requests per instance each minute |
The same metrics page says each is sampled every 60 seconds and can take up to 120 seconds to appear. Cloud Run metrics
For single requests, the request log carries httpRequest.latency, the time from receiving the request to sending the response, and the revision that served it:
gcloud logging read '
logName="projects/PROJECT/logs/run.googleapis.com%2Frequests"
AND resource.labels.service_name="SERVICE"
AND timestamp>="START_TIME" AND timestamp<="END_TIME"' \
--project PROJECT --order=asc --limit=1000 \
--format='value(timestamp, resource.labels.revision_name, httpRequest.latency, httpRequest.requestUrl)'
Cloud Run request logs · HttpRequest.latency
Concurrency matters because it changes what CPU utilization means. The setting is a ceiling; when an instance's CPU is already highly used, Cloud Run may send it fewer requests and scale out instead. An instance pinned near full CPU with concurrency at its configured maximum is a Cloud Run bottleneck, whatever the database does. Maximum concurrent requests
Check 2: the database over the same minutes#
Plot cloudsql.googleapis.com/database/cpu/utilization for the instance on the same time axis. It is the fraction of the reserved CPU in use and can exceed 1.0. Cloud SQL metrics
Then open Query insights for the instance. Its database load chart splits query time into CPU and CPU wait, IO wait and lock wait, with a line for the instance's CPU capacity. CPU load counts both running and waiting for the scheduler, so it can rise above the capacity line, which is how the chart shows an instance running out of CPU. Selecting a query shows its share of the load, and tags added with sqlcommenter let you tie a query to an application route or controller. Query insights · Add tags to SQL queries
| Latency rose for | Cloud SQL CPU and query load | Revision CPU and concurrency | Reading |
|---|---|---|---|
| All revisions | Rose at the same minute | Normal | The database. Find the query that grew in Query insights; if it is new, the revision that sends it is the cause |
| All revisions | Lock wait rose, CPU did not | Normal | Contention: a long transaction or a migration holding locks. Look at what started at that minute |
| One revision | Flat | CPU near full, or concurrency at its ceiling | The Cloud Run instance. The new code needs more CPU per request, or concurrency is too high for it |
| One revision | Flat | Normal | Neither: a slower external call, a new network path, or a different query pattern that waits on round trips. Compare the code |
A worked fixture: a canary that slowed down#
The fixture is illustrative. At 09:00 UTC, orders-api-00018 receives 20% of traffic and orders-api-00017 keeps 80%. Both connect to orders-db, a 4-vCPU instance.
Incident A. p95 request latency, from request_latencies:
| Minute (UTC) | orders-api-00017 | orders-api-00018 | database/cpu/utilization |
|---|---|---|---|
| 08:55 | 180 ms | 0.35 | |
| 09:02 | 190 ms | 210 ms | 0.48 |
| 09:06 | 1,300 ms | 1,450 ms | 0.97 |
Both revisions slowed together, and the database's CPU rose with them. Query insights shows CPU and CPU wait above the capacity line from 09:04, and one query accounts for most of it: a search by customer email that the order history page in orders-api-00018 introduced, tagged with that route. orders-api-00017 never sends it. The time is in the database, and the cause is the new revision's query. Moving the 20% back removes the load for both.
Incident B. Same canary, different readings:
| Minute (UTC) | orders-api-00017 | orders-api-00018 | database/cpu/utilization |
|---|---|---|---|
| 08:55 | 180 ms | 0.35 | |
| 09:06 | 185 ms | 1,450 ms | 0.37 |
Only orders-api-00018 slowed. Database CPU is flat, and Query insights shows no change in load or in the top queries. container/cpu/utilizations for orders-api-00018 sits at 0.98 at p95, and its maximum concurrency reaches 80, the service's setting. The new revision serializes each response with a library that is far heavier on CPU. The time is in the Cloud Run instance; lower its concurrency or give it more CPU while the code is fixed, and leave the database alone.
Where the checks mislead#
Metrics arrive in one-minute samples. A spike shorter than a minute can show in one metric and vanish into another's average, so line them up by minute and accept a minute of slack.
Query insights shows completed queries by default; a query that is still running during the spike appears only under active queries. On Enterprise edition, metrics are kept for 7 days, and the dashboard reports up to the top 100 query combinations per day, so a short incident's query may already be aggregated away if you look late. Query insights
Cloud Run with request-based billing throttles CPU outside requests. A revision whose work continues after the response, or whose pool maintenance runs in the background, behaves differently under instance-based billing; check the billing setting when comparing two services. Billing settings
Latency that both revisions share with no rise in database load can come from the path between them. A revision deployed to another region adds a network round trip to every query; a service and an instance in different regions covers that case. For the general method of separating a release from a slow dependency, see deploy latency spikes.
Questions#
How do I know if Cloud SQL is the bottleneck for my Cloud Run service?
Plot database/cpu/utilization and Query insights' database load on the same minutes as each revision's request latency. If database load rose with the latency, especially above the CPU capacity line, the time is in the database.
Does a slow Cloud SQL query clear the new revision?
No. If the query that grew is one the new revision sends, the revision caused the load even though every revision slowed down. Query insights tags and the query text tie the load to code.
What does high Cloud Run CPU with low database CPU mean?
The request spends its time computing in the container or waiting for CPU there. Check whether concurrency is at its configured maximum, and compare CPU per request between revisions.