Learning center

Slow Cloud SQL connections through a Serverless VPC Access connector

When Cloud SQL slows down behind a Serverless VPC Access connector, put the connector's throughput, instance count and CPU beside the database's CPU. Read both for the same window. A connector at its maximum instances with a flat throughput line is the bottleneck; a quiet connector beside a busy database is not. Connector maintenance explains a different pattern: connections that drop at intervals.

How the symptom shows up#

The revision connects to the instance's private IP through a connector, a set of VM instances attached to one VPC network and region. Traffic sent through it into the VPC originates from the connector's /28 subnet or range. Serverless VPC Access The application sees longer query times, pool waits, and sometimes connection timeouts, which look like a slow database. If the connections time out outright on every attempt, the route is broken rather than slow. Private IP connections from Cloud Run time out

A connector differs from Direct VPC egress in two ways that matter here. Its capacity is a fixed set of VMs of one machine type, and it is shared: every service and job that names it sends traffic through the same instances. Compare Direct VPC egress and VPC connectors

Check 1: read the connector's capacity#

gcloud compute networks vpc-access connectors describe CONNECTOR \
  --region REGION --project PROJECT \
  --format='yaml(name, network, machineType, minInstances, maxInstances, state)'

connectors describe ยท Connector resource

Larger machine types carry more. Google's estimates are 100 to 500 Mbps for f1-micro, 200 to 1,000 Mbps for e2-micro and 3,200 to 16,000 Mbps for e2-standard-4; its worked example gives f1-micro with the default 2 to 10 instances 100 Mbps at the minimum and 500 Mbps at the maximum. The connector scales out under load and does not scale in, and the estimates depend on many factors. Throughput and scaling

Then read its metrics for the incident window. The connector's page in the console charts throughput, the number of instances, and CPU utilization at the 50th, 95th and 99th percentiles, for 1 to 90 days. Google's guidance is to raise the maximum instances when CPU spikes and to move to a larger machine type when throughput is at its limit. Monitor connector usage

Connector in the windowReading
Instances at maxInstances, throughput flat at a ceiling, CPU highThe connector is saturated. Queries wait in the network, not in the database
Instances rising during the slowdown, then steadyThe connector was scaling. Latency during scale-out is expected with connectors
Instances below the maximum, CPU and throughput lowNot the connector. Go to check 2

Find who else uses the connector. A batch job in another service can fill it while your service's own traffic stays flat:

gcloud run services list --project PROJECT --region REGION \
  --format='value(metadata.name, spec.template.metadata.annotations)' \
  | grep 'vpc-access-connector=[^;]*CONNECTOR'

The connector is set per revision by the run.googleapis.com/vpc-access-connector annotation. Revision template annotations

Check 2: put the database beside it#

Read the Cloud SQL instance's CPU utilization and connection count for the same window on its overview page. Monitor Cloud SQL instances

ConnectorDatabaseReading
SaturatedCPU normalThe network path limits throughput. Raise the maximum instances or move the service off the connector
NormalCPU high or connections near the limitThe database is the bottleneck. A larger connector will not help
Both highBoth highLook for one source that drives both, such as a new query returning large result sets

Check 3: connections that drop at intervals#

A different pattern, connections that fail now and then with low load, can come from connector maintenance. Google replaces connector instances during host migrations, base image updates and restarts every two weeks. An instance stops taking new requests one minute before it shuts down. Google's guidance is not to rely on individual connections that last longer than a minute and to use connection pools. If an organization policy blocks the connector's image project, replacement instances fail to start and the instance count can fall over time to zero. Maintenance and instance replacement

What you seeReading
Resets spread across days, each burst short, pool reconnectsInstance replacement. Make sure the pool validates and replaces connections
Instance count falling over days and not recoveringReplacements are failing to start. Read the project's organization policies

When Direct VPC egress changes the picture#

Direct VPC egress removes the connector VMs: Google lists it with lower latency, higher throughput and no VM charges, and with slower instance autoscaling, including from zero, while it creates network interfaces. Comparison table It has its own limits: up to 1 Gbps per container instance, and connection setup at instance startup that can take a minute or more. Direct VPC egress limitations A move from a connector to Direct VPC egress therefore shifts the question from the connector's shared capacity to each instance's startup and the subnet's free addresses.

Moving a service is a deploy: gcloud run deploy with --network and --subnet, plus --clear-vpc-connector to drop the connector, creates a new revision with Direct VPC egress. The Direct VPC subnet must be /26 or larger. gcloud run deploy

A worked fixture: the connector or the database#

The fixture is illustrative. The fictional service orders-api in europe-west1 reaches orders-db at 10.40.0.3 through connector run-ew1-conn, machine type e2-micro, minInstances: 2, maxInstances: 3. From 14:00 UTC, the 95th percentile of query time in the application rises from 12 ms to 900 ms.

Outcome A: a shared connector at its ceiling.

Time (UTC)Connector instancesConnector throughputConnector CPU p99orders-db CPU
13:50290 Mbps30%35%
14:053290 Mbps97%36%
14:303290 Mbps98%34%

The connector reached its maximum of 3 at 14:05 and its throughput stopped rising. The database did not change. The services list shows reports-export, a new export job first run at 14:00 today, names the same connector. Move reports-export or orders-api to Direct VPC egress, or raise the connector's maximum instances. An increase cannot be undone without recreating the connector. Decrease instances

Outcome B: the database.

Time (UTC)Connector instancesConnector throughputConnector CPU p99orders-db CPU
13:50290 Mbps30%35%
14:05295 Mbps32%97%
14:30292 Mbps31%98%

The connector carries about what it carried before. The database's CPU tripled at 14:05. The time is spent in the database; read its queries for the window.

Where the checks mislead#

Google calls the throughput ranges estimates that depend on many factors, including VM network bandwidth. A connector can slow traffic below the table's figure; use the flat line in its throughput chart, not the table, as the sign of a ceiling. Throughput and scaling

A connector that scaled out stays scaled out. Its instance count in the window shows its peak since creation as much as current load, so read CPU and throughput with it.

Pool waits inside the application can look like network latency. Pool size and connection limits per instance are covered in connection budgets, and both sides of the comparison above stay normal when the pool is the limit.

Questions#

Is a Serverless VPC Access connector slower than Direct VPC egress?

Google lists Direct VPC egress with lower latency and higher throughput than connectors. Connectors add latency during traffic surges while new connector instances start, and their throughput depends on machine type and instance count.

How do I tell if the VPC connector is the bottleneck for Cloud SQL?

Read the connector's throughput, instance count and CPU charts for the window. Instances at the maximum with throughput flat and CPU high, while the database's CPU stays normal, point at the connector.

Why do Cloud SQL connections through a VPC connector drop every so often?

Google replaces connector instances during maintenance, and an instance stops accepting new requests a minute before it shuts down. Connections that live longer than that can break; a pool that validates and reopens connections handles it.

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.

Start free with GitHub

Related reading