Optimizing performance and cost

PCDOE notes, updated November 2026

Section 5 is about 12% of the exam. Two ideas: measure before you tune (collect performance and utilisation data, act on recommendations) and FinOps (make costs visible, owned and continuously optimised without breaking the SLO). Scenarios give a bill or a utilisation chart and ask for the cheapest change that still meets the reliability target.

Collecting performance information

Application performance monitoring

Tool Gives you
Cloud Monitoring Platform and application metrics, golden signals, SLOs, dashboards, alerts
Cloud Trace Request latency by span, latency distributions, comparisons between periods
Cloud Profiler Continuous, low-overhead CPU, heap, contention and wall-time profiles by function (flame graphs); compare versions to catch a regression
Error Reporting Grouped exceptions and their frequency
Application Monitoring / App Hub Group services, workloads and resources into applications with pre-built dashboards, telemetry correlated across them; helps view a whole app’s health and costs
Query Insights (Cloud SQL, AlloyDB), Key Visualizer (Bigtable, Spanner) Slow queries, hot keys
Load balancer metrics and logs Request latency, backend vs total latency, error classes
Network Intelligence Center Performance Dashboard (latency and packet loss between zones and regions), Network Topology
Agent and model performance For AI workloads: latency per model call, tool call duration, token counts, errors and quota from OTel traces and metrics on the Gemini Enterprise Agent Platform and Agent Development Kit

Method: define the SLI and a performance baseline; load test before release; compare before and after for each release (canary analysis); look at percentiles, not averages; relate utilisation to saturation (a service at 20% average CPU may still be throttled or lock-bound). Profile in production because it’s cheap and representative.

Active Assist and recommenders

Active Assist is Google Cloud’s suite of recommendation and insight engines. Each recommender analyses usage and posts recommendations in the Recommendation Hub (and via the Recommender API, exportable to BigQuery, notifications on change).

Category Examples
Cost VM machine type (rightsizing: downsize or change family) and idle VM recommendations, idle persistent disks, idle IP addresses and idle images, unattended projects, committed use discount recommendations, Cloud SQL overprovisioned instance, Cloud Run and GKE cost insights
Security IAM recommender (remove excess roles using 90 days of usage), unused service account keys, firewall insights (shadowed rules), public access findings
Performance Undersized VM or database, managed instance group machine type suggestions, network and Cloud SQL performance
Manageability Fix deprecated settings, Cloud SQL minor issues, unused APIs, org structure
Reliability Missing backups, single points of failure, Cloud SQL out-of-disk prevention, quota and capacity risk

Facts: recommendations come with an estimated impact (savings or risk), can be applied, dismissed or marked claimed, and some can be applied through API or Terraform. VM rightsizing uses at least a week of Ops Agent or hypervisor utilisation (memory data improves quality when the agent is installed). Recommenders for Policy Troubleshooter, Policy Simulator and Network Analyzer are Active Assist insights too. Review them regularly, assign owners, and automate the safe ones (for example snapshot and delete idle disks). Gemini Cloud Assist can summarise them.

FinOps practices

FinOps is the practice of bringing financial accountability to cloud spend, in three loops: inform (visibility and allocation), optimise, and operate (governance, forecasting, culture). Engineers and finance share the work.

Visibility and allocation

  • Labels (env, team, app, cost-center) on resources, enforced with organization policy or IaC; projects and folders per team or environment; tags. Labels appear in billing data; unlabelled spend is unowned spend.
  • Cloud Billing reports and cost table, billing export to BigQuery (standard usage cost, detailed usage cost with resource-level data, pricing data) for custom analysis, joined with labels. Use Looker Studio dashboards. FinOps hub in the console gathers optimisation opportunities, utilisation of commitments and waste.
  • Budgets and alerts on a billing account or scope (project, service, label): thresholds on actual or forecasted spend (50/90/100%); alerts by email, or by Pub/Sub to automate action (notify a team, throttle, in extreme cases disable billing on a sandbox project through a function; disabling billing stops services, so avoid it on production). Budgets don’t cap spend by themselves.
  • Quotas and per-API limits cap runaway usage (a developer launching 1,000 VMs); custom quota overrides per project are a cost safety net.
  • Anomaly detection surfaces unusual cost spikes.

Committed use and automatic discounts

Option Details
Sustained use discounts (SUDs) Automatic discount for VMs running a large part of the month on eligible machine families (N1, N2 and some others, up to about 30%). Not for E2 or other new families; no commitment, no action required
Resource-based committed use discounts (CUDs) Commit to vCPUs, memory, GPUs for 1 or 3 years in a region; deeper discount (up to roughly 55% for most machine types, higher for memory-optimised); the commitment is billed whether used or not; applies to a project or shared across the billing account
Spend-based (flexible) CUDs Commit to an hourly spend across eligible services (Compute Engine, GKE, Cloud Run, Cloud SQL, and others) for 1 or 3 years, with a smaller discount but flexibility across machine families and regions
Reservations Guarantee capacity, not a discount (see capacity planning)
Spot VMs See below

Choose commitments for the steady baseline that will run for the term; use autoscaling and Spot for variable load; don’t commit to more than the stable minimum. Review commitment utilisation and coverage in the FinOps hub.

Spot VMs

  • Spot VMs (--provisioning-model=SPOT) are surplus capacity at 60 to 91% off. Compute Engine can preempt (stop or delete) them at any time with a 30-second warning (shutdown script), and there’s no maximum runtime (unlike the older preemptible VMs, which last at most 24 hours). No SLA, no live migration, and they aren’t covered by CUDs the same way.
  • Set the termination action (STOP or DELETE). Use Spot for fault-tolerant, stateless, batch, CI, rendering, data processing, and mix with on-demand for the critical base: MIG with Spot and on-demand instances, GKE Spot node pools (taint them; use Pod anti-affinity, PDBs and graceful termination), GKE Autopilot Spot Pods, Dataflow flexible resource scheduling, Cloud Batch.
  • Design for interruption: checkpoint work, idempotent jobs, retry, spread across zones and machine types, handle the shutdown signal.
  • Cloud Build and CI runners can use Spot-backed pools to cut cost.

Network cost and tiers

Item Notes
Premium Tier (default) Traffic travels on Google’s global backbone, lower latency and higher reliability, global load balancing requires it
Standard Tier Traffic exits to the internet near the source and rides public transit; cheaper egress, regional forwarding rules and regional load balancing only; fine for cost-sensitive, latency-tolerant workloads
Egress Charged by destination: same zone and internal in some paths is free; cross-zone and cross-region cost; internet egress is highest. Ingress is free
Reduce Serve static content through Cloud CDN, keep chatty services in the same zone/region, use Private Google Access and Private Service Connect rather than internet paths, compress, cache, use Cloud NAT carefully (per GB processed), and pick regions by price and carbon

Optimizing observability costs

Observability can be a top-three line item. Reduce it without losing the signals that protect the SLO:

  • Logging: exclusion and sampling filters, drop debug logs in production, reduce Data Access and VPC Flow Log volume (sample 5 to 10%, longer aggregation interval, only the subnets that matter), route archives to Cloud Storage, shorten retention, avoid logging full payloads in hot paths. Free tier: first 50 GiB per project per month is free to ingest.
  • Metrics: avoid high-cardinality labels (user ID, request ID, full URL), drop unused metrics (in Prometheus, use relabelling or metric exclusion), increase the scrape interval (for example 60 seconds rather than 15), aggregate before sending (OTel Collector), use Prometheus recording rules carefully. Managed Prometheus is billed per sample, custom metrics per volume; system metrics from Google Cloud are mostly free.
  • Traces: sampling rate, tail-based sampling for errors and slow requests, shorter span attributes. Cloud Trace charges per span ingested after a free allowance.
  • Alerting: fewer, aggregated conditions (charged per condition and series evaluated), remove stale policies.
  • Governance: budgets and alerts specific to the observability services, dashboards of bytes ingested per source (logging.googleapis.com/billing/bytes_ingested and metrics volume), owners per noisy source, and a review cadence.
  • Don’t “save” by turning off Admin Activity or audit logs (not possible) or by sampling out the errors you need.

Optimizing individual workloads

Compute Engine

  • Right-size from recommender and monitoring data; use custom machine types or the right family; consider E2 (cost-optimised) for general purpose; Arm (Axion/Tau T2A) for efficiency where software supports it; shut down idle VMs on schedules (instance schedules with resource policies start and stop dev environments overnight); delete idle disks, snapshots and IPs; pick balanced or standard persistent disks over SSD where IOPS don’t need it; use Hyperdisk performance tuning separate from capacity.
  • Use MIG autoscaling so you pay for what the load needs; Spot for fault-tolerant tiers; CUDs for the baseline; images and snapshot lifecycle policies.

Google Kubernetes Engine

  • Autopilot bills per Pod resource request (no idle node cost, managed bin packing); Standard bills nodes, so bin packing and utilisation are your job.
  • Right-size requests and limits (use VPA recommendations, GKE workload rightsizing insights and the cost optimisation dashboard). Over-requested Pods strand node capacity; under-requested Pods get throttled or OOM-killed.
  • Cluster autoscaler with the optimize-utilization profile and node auto-provisioning to pick the right machine shape; HPA for replicas; scale dev clusters down or to zero at night; Spot node pools for fault-tolerant workloads; CUDs for the baseline; multi-tenant clusters to share control plane cost; cost allocation (enable GKE cost allocation to attribute cost by namespace and label).
  • Choose regional vs zonal deliberately (regional clusters cost more in cross-zone traffic and nodes).

Cloud Run

  • Billed on CPU, memory and requests (request-based) or while the instance is up (instance-based, CPU always allocated). Choose request-based for spiky or intermittent traffic and instance-based for steady or background processing.
  • Concurrency: higher concurrency means fewer instances (cheaper) if the code is thread-safe and CPU permits; min instances reduce cold starts but cost idle time (use startup CPU boost and lighter images first); max instances cap cost and protect downstream; right-size CPU and memory; keep images small; use committed-use (spend-based) discounts for steady usage; scale to zero in dev.

Other cost levers

  • Storage: lifecycle rules and Autoclass in Cloud Storage; archive old logs and backups; delete unused snapshots.
  • BigQuery: partition and cluster tables, avoid SELECT *, use slot reservations (editions) for steady load, set maximum bytes billed limits.
  • Databases: right-size Cloud SQL, use read replicas only when needed, stop dev instances, use committed use on Cloud SQL.
  • Idle projects: use unattended project recommender to find and shut them down; remove sandbox sprawl with TTL labels.

Cost and performance for AI workloads (Provisioned Throughput and tokens)

For generative AI on the Gemini Enterprise Agent Platform (formerly Vertex AI):

Option Details
Pay-as-you-go Charged per token (input and output; models and modalities priced differently). Subject to Dynamic Shared Quota: capacity shared dynamically, so latency and rate limits can vary under contention; 429 errors need retry with backoff
Provisioned Throughput Reserve dedicated model capacity (measured in generative AI scale units) for a fixed term (such as weekly, monthly, longer) at a fixed price. Gives predictable latency and availability for production agents with steady, high traffic; over-subscription can spill to pay-as-you-go. It’s a reliability tool first and a cost tool when usage is steady and high enough that the reservation beats per-token pricing. Size it from measured token throughput, not guesses; don’t buy it for spiky or low volume
Batch prediction Large offline jobs at a discount (often around half price), asynchronous

Optimising token consumption:

  • Shorter, tighter prompts and system instructions; remove redundant context; summarise long conversation history; limit retrieved RAG chunks to what’s needed.
  • Context caching for large repeated prefixes (documents, long instructions) at a reduced rate for cached tokens.
  • Use the smallest model that meets quality (Flash and Flash-Lite class models for classification and routing, a larger model only where needed); model routing.
  • Cap max output tokens and ask for structured, concise responses; avoid unnecessary reasoning or thinking budget where not needed.
  • Avoid agent loops with unbounded tool calls; set step limits; cache tool results.
  • Monitor tokens as a metric (input, output, per request, per agent and user), set budgets and quota alerts, and alert on anomalies.
  • Reliability link: Provisioned Throughput for agent reliability, retries with backoff, and fallbacks to another model or region.

Exam checklist

  • Measure first: Trace, Profiler, Error Reporting, Query Insights, percentile latency, load test before and after releases.
  • Active Assist recommenders in five categories (cost, security, performance, manageability, reliability); idle resources and VM rightsizing are the cost ones; IAM recommender is security.
  • Labels and billing export to BigQuery give allocation; budgets alert but don’t cap spend; Pub/Sub budget notifications automate action.
  • SUDs are automatic on eligible families; resource-based CUDs for steady known shapes, spend-based CUDs for flexibility; reservations guarantee capacity only.
  • Spot VMs: 60 to 91% off, 30-second warning, no maximum runtime, no SLA; for stateless, fault-tolerant, batch; mix with on-demand.
  • Premium tier for global, Standard tier cheaper but regional; same-zone traffic and CDN reduce egress.
  • Observability costs: exclusions and sampling, cardinality, scrape interval, trace sampling, retention, route to Cloud Storage.
  • GKE: Autopilot per Pod request, right-size requests, optimize-utilization autoscaler, Spot pools. Cloud Run: request-based vs instance-based, concurrency, min and max instances.
  • Provisioned Throughput buys predictable capacity for steady production AI traffic; reduce tokens by prompt trimming, caching, smaller models, output caps and batch.

Test what you just read. 36 practice questions on optimizing performance and cost.

Practise this domain

All PCDOE notes