If you do not tune performance and control costs in the cloud, your application will either be slow enough to drive users away or expensive enough to burn through a company's budget in a few weeks. Performance tuning and cost optimisation are the two sides of the same important coin: making sure your cloud services run quickly and reliably while paying only for what you actually need. This chapter explains how to identify slowdowns, fix them without breaking things, and keep your cloud bill from becoming a horror story — all core skills tested on the PCDOE exam.
Jump to a section
A simple way to picture Performance Tuning and Cost Optimization
A Head Chef runs a busy restaurant kitchen. Their job is to serve delicious meals to every table as fast as possible, without letting the kitchen run out of ingredients or exceed the weekly budget.
One night, the Head Chef notices the ticket machine is printing orders faster than the line cooks can plate them. The chefs are rushing, making mistakes, and the wait time for a table of four stretches to forty-five minutes. Customers start walking out. That is a performance issue. The Chef cannot just hire ten more cooks overnight, because the kitchen has limited space and the restaurant cannot afford the extra payroll. Instead, they look at the data: the deep fryer is idle for ten minutes every hour because the grill station is always backed up. The Chef reorganises the prep list, moving some fried items to the grill cook during the slow period. Orders start flowing again. That is performance tuning — matching capacity to demand.
At the same time, the Chef reviews the monthly invoice from the supplier. They are paying premium prices for pre-chopped vegetables when one of the junior cooks could chop them during a quiet afternoon shift. They also notice they order twenty kilos of imported truffle oil every month, but only use five. By switching to local produce and trimming waste, the Chef cuts the food-cost percentage from 38% to 28% without lowering a single plate's quality. That is cost optimisation — spending only what is needed to deliver the same result. The Head Chef, like a Google Cloud DevOps Engineer, constantly balances speed of service against the budget, using data to make small, smart adjustments rather than brute-force fixes.
Let us start with a simple truth: cloud computing is just renting someone else's computer over the internet. Google Cloud runs massive data centres full of servers, and you pay to use a slice of that power. When your application runs on those rented servers, you want it to respond quickly (performance) and you want to pay as little as possible for that speed (cost). These two goals often pull in opposite directions. Throwing more powerful servers at a slow app will make it faster, but it will also make your bill explode. The art is finding the sweet spot.
This is where performance tuning comes in. Performance tuning means finding the reason your application is slow and fixing that root cause instead of just buying a bigger server. The most common reason for slowness is a bottleneck, a single part of the system that cannot keep up with the rest. Imagine a factory assembly line where one machine can only process ten units per hour, but the machine before it sends fifty units per hour. The line backs up. In cloud applications, a bottleneck could be the CPU (Central Processing Unit, the brain of the server that does calculations), the memory (RAM, the short-term workspace that holds active data), the disk (the hard drive that stores data permanently), or the network (the connection that moves data between servers and to users).
Google Cloud provides tools to find these bottlenecks. Cloud Monitoring is a service that collects metrics, which are numbers that measure something, like 'requests per second' or 'CPU utilisation percentage'. You can set up a dashboard that shows these metrics as graphs. If you see CPU utilisation hitting 100% for a long time, your bottleneck is the CPU. If memory is maxed out, you need more memory. If disk read/write times spike, your storage is too slow. If network latency is high, the problem might be that your server is too far from your users.
Once you find the bottleneck, you have several options for fixing it. One is vertical scaling, which means giving the existing server more power: a faster CPU, more memory, a faster disk. In Google Cloud, you stop the Compute Engine virtual machine (a VM is just a virtual server that acts like a real computer) and change its machine type to a bigger one. This is simple but only works up to the maximum size of a single machine. It is also expensive because you are paying for that big machine all the time, even when it is not busy.
A better approach is often horizontal scaling, also called elastic scaling. Instead of making one server bigger, you add more servers to share the work. You put your application behind a load balancer that acts like an airline check-in counter that directs passengers to the clerk with the shortest line. The load balancer spreads incoming user requests across multiple VM instances. When traffic goes up, you automatically add more instances. When traffic drops, you remove the extra ones. This is called autoscaling. You pay only for the instances you are using at that exact moment. It is the most cost-effective way to handle variable traffic, like a website that gets ten times more visitors on Mondays than on Tuesdays.
Cost optimisation is the other half. It means making sure you are not wasting money. The biggest waste in cloud computing is overprovisioning: buying a server that is much more powerful than you need 'just in case' traffic spikes. Instead, you should right-size your instances. Right-sizing means looking at the utilisation data from Cloud Monitoring and picking the machine type that matches your actual peak usage, not your imagined peak.
Another cost trick is using committed use discounts (CUDs). If you know you will run a certain number of servers for a year or three years, you can commit to Google Cloud and get a big discount (up to 57% off standard prices). This works well for stable, always-on workloads like a database. For flexible workloads, you can use preemptible VMs or spot VMs. These are spare compute capacity that Google sells at a huge discount (up to 80% off), but Google can reclaim them at any moment with 30 seconds' notice. They are perfect for batch processing jobs that can be interrupted and restarted, like rendering a video or analysing a large dataset overnight.
Finally, you must manage storage costs. Not all data needs to be stored on super-fast SSDs. Google Cloud has different storage classes: Standard for frequently accessed data, Nearline for data accessed once a month, Coldline for data accessed once a quarter, and Archive for data that must be kept for years but almost never accessed. Moving old log files to Archive storage can slash your storage bill by 80%.
In summary, performance tuning and cost optimisation are a continuous cycle:
Measure utilisation with Cloud Monitoring.
Identify the bottleneck or the source of waste.
Apply the right fix (scale horizontally, right-size, change storage class).
Measure again to confirm improvement.
Repeat endlessly.
The PCDOE exam expects you to know which tool to use for which problem and how to interpret the metrics you get back.
Measure Baseline Performance
Before you change anything, collect current metrics from Cloud Monitoring: CPU utilisation, memory usage, disk I/O latency, network throughput, and request latency. This gives you a baseline to compare against after you make changes. Without a baseline, you cannot prove improvement.
Identify the Bottleneck
Analyse the metrics to find which resource is hitting its limit. For example, if CPU is at 95% while memory is at 40%, the CPU is the bottleneck. Always look at the 99th percentile, not just the average, because averages hide short spikes that cause user-visible slowness.
Choose the Right Scaling Strategy
If the bottleneck is a stateless component (like a web server), implement horizontal scaling with an autoscaling managed instance group. If the bottleneck is a stateful component (like a database), consider vertical scaling or read replicas. The choice depends on whether the component can handle multiple instances sharing the load.
Optimise Storage and Data Transfer
Review your storage usage: move infrequently accessed data to cheaper storage classes (Nearline, Coldline, Archive). Also check egress costs — transferring data out of Google Cloud to the internet costs money. Use a CDN (Content Delivery Network) like Cloud CDN to cache content closer to users and reduce egress.
Implement Cost Governance
Set up budget alerts in Cloud Billing that send notifications when spending exceeds a threshold. Review committed use discounts for steady workloads. Turn off idle resources (like development VMs that run 24/7 but are used only 8 hours a day). Use labels to tag resources by department or project so you can track who is spending what.
Validate and Repeat
After applying changes, go back to Cloud Monitoring and compare the new metrics against your baseline. Confirm that latency dropped and cost decreased. If not, go back to step 2. This is a continuous cycle, not a one-time task.
Imagine you are the new Site Reliability Engineer (SRE) at a company that runs an online photo-editing application. The app lets users upload high-resolution images, apply filters, and download the results. The company is growing fast, but users have been complaining that the app is slow, especially during the evening. Meanwhile, the finance director has just sent an angry email saying the cloud bill doubled last month. You need to solve both problems.
Here is exactly what you do step by step.
First, you open Cloud Monitoring and create a dashboard that shows the key metrics for the last 30 days. You look at the CPU utilisation of the VM instances that run the web server frontend. You see it is averaging 85% during peak hours and hitting 100% for short bursts. That is a bottleneck. Users are waiting for the web server to accept their upload request because the server is too busy. Next, you look at the memory utilisation of the database instance. It is using only 40% of its 64 GB of RAM. That is not the problem. Then you examine the disk I/O latency on the shared file system where processed images are stored. The latency spikes to 500 milliseconds during peak times. That is bad. The storage system is too slow to keep up with the read/write requests.
Now you have two bottlenecks: the web server CPU and the storage latency. You also need to understand the cost spike. You open the Cloud Billing reports. You see that the Compute Engine cost has risen sharply because you are running 20 n2-highmem-32 instances (very large, expensive VMs) around the clock. You also see a large bill for persistent disk storage. You discover that the engineering team provisioned those big instances six months ago 'just in case' and never changed them. They also never deleted old processed images. There are 5 terabytes of images from last year that nobody has touched.
To fix the performance, you start with horizontal scaling. You create an instance template with a smaller, cheaper machine type (n2-standard-8 instead of n2-highmem-32). You configure a managed instance group (MIG) that uses autoscaling based on CPU utilisation. You set the target CPU utilisation to 70%. Now, when traffic rises, new instances spin up automatically. When traffic drops, they are removed. This solves the web server bottleneck.
For the storage latency, you realise that the shared file system is using standard persistent disk (pd-standard), which has limited IOPS (input/output operations per second, a measure of speed). You migrate the active image storage to pd-ssd (solid-state drive, much faster), which reduces latency from 500ms to 10ms. You set up a lifecycle policy that moves images older than 30 days to a Cloud Storage bucket using the Nearline storage class and images older than one year to Archive class.
Finally, you implement committed use discounts for the three database instances that must run 24/7. You also set up budget alerts that send an email to the team when the monthly spend exceeds 80% of the forecast. After two weeks, you check the monitoring dashboard again. User complaints have dropped to zero, and the cloud bill is 40% lower than the previous month. You have successfully tuned performance and optimised costs.
The Google Professional Cloud DevOps Engineer exam tests Performance Tuning and Cost Optimisation in a very specific way. It does not ask you to memorise every VM type or price. Instead, it tests your ability to understand what metrics mean, what tool to use to fix a problem, and how to make smart trade-offs. Here is exactly what you need to know.
Question types you will see:
You are given a scenario where an application is slow. You are shown a graph of metrics. You must identify the bottleneck. For example, a graph shows high network latency but low CPU usage. The correct answer will be: 'Increase the machine's network bandwidth' or 'Move the instance to a region closer to users.
You are given a scenario where the cloud bill is too high. You must choose the cost-saving action. For example: 'Migrate the workload to preemptible VMs' or 'Use a committed use discount for the steady-state workload.
You are asked about autoscaling policies. They love to test the difference between CPU-based autoscaling and request-based autoscaling. CPU-based autoscaling adds instances when the CPU is busy, but this can be slow because CPU usage rises only after the request has already arrived. Request-based autoscaling (also called load-based scaling) measures the number of requests in the queue and adds instances before the CPU gets busy. The exam expects you to choose request-based autoscaling for latency-sensitive applications.
Common traps they set:
They give you a graph that shows low average CPU utilisation and ask why the app is slow. Beginners think, 'CPU is low, so the problem must be elsewhere.' But the trap is that the graph shows average across 1 hour, masking short spikes that last seconds. The correct answer is: 'Check the 99th percentile CPU utilisation' or 'Check request latency distribution.
They offer a solution that is technically correct but too expensive. For example, 'Increase the size of all VM instances to the maximum' will fix a bottleneck, but the exam favours horizontal scaling (autoscaling) over vertical scaling because it is more cost-efficient.
They test right-sizing vs overprovisioning. They will describe a team that bought huge VMs 'for headroom'. The correct exam answer is to use Cloud Monitoring data to right-size the instances based on actual peak utilisation.
Key concepts they love to test:
Cloud Monitoring metrics: cpu/utilization, memory/bytes_used, disk/read_bytes_count, network/host.external.egress_bytes. You must know which metric corresponds to which resource.
Cloud Logging and Error Reporting: used for debugging performance issues at the application code level, not infrastructure level.
Profiler: a tool that shows exactly which lines of code are consuming the most CPU and memory. This is for code-level performance tuning, not infrastructure tuning.
Trace: a tool that tracks a single request as it travels through multiple microservices. Used to find which service in a chain is slow.
Storage classes: Standard, Nearline, Coldline, Archive. The exam will give a scenario about old medical images that must be retained for 7 years but accessed once a year. The correct class is Archive.
Preemptible VMs: they can be stopped by Google at any time. Use for fault-tolerant batch jobs. Cannot be used for stateful applications.
Committed Use Discounts (CUDs): require a 1-year or 3-year commitment. Best for predictable workloads.
When you see a question about cost, always think: 'Is this workload predictable or not? Is it stateful or stateless? Can it tolerate interruption?' The exam answer will often hinge on that distinction.
Performance tuning starts with finding the bottleneck using Cloud Monitoring metrics, not by blindly upgrading hardware.
Horizontal scaling (adding more small instances via autoscaling) is usually more cost-effective than vertical scaling (upgrading to a larger single instance).
Right-sizing your VMs based on actual peak utilisation data is the single most impactful action for cloud cost optimisation.
Committed use discounts are ideal for predictable, always-on workloads like databases, not for bursty or experimental workloads.
Preemptible VMs offer up to 80% discount but are only safe for fault-tolerant batch processing tasks that can restart after interruption.
Use the correct storage class: Standard for hot data, Nearline for monthly access, Coldline for quarterly access, Archive for data kept for years but rarely read.
These come up on the exam all the time. Here's how to tell them apart.
Vertical Scaling
Increases capacity by making a single server larger (more CPU, RAM, disk).
Has an upper limit because you cannot grow a single machine infinitely.
Often more expensive for variable workloads because you pay for full capacity even during low traffic.
Horizontal Scaling
Increases capacity by adding more servers to spread the load.
Can handle unlimited growth by adding instances on demand.
More cost-effective for variable workloads because you pay only for active instances.
CPU-Based Autoscaling
Adds or removes instances based on average CPU utilisation of the existing instances.
Can be slow to react because CPU usage rises only after a request is already being processed.
Good for workloads that have consistent request processing times.
Request-Based Autoscaling
Adds or removes instances based on the number of pending requests in the queue.
React faster because it detects queued requests before they hit the CPU.
Better for latency-sensitive applications where fast response is critical.
Committed Use Discount (CUD)
Requires a 1-year or 3-year commitment to a minimum level of resource usage.
Provides a discount of up to 57% but you pay even if you do not use the capacity.
Best for stable, predictable workloads that run continuously.
Preemptible VM
No commitment — you pay per second as you go.
Provides up to 80% discount but Google can reclaim the VM with 30 seconds notice.
Best for batch, fault-tolerant jobs that can be interrupted and restarted.
Standard Storage Class
Designed for frequently accessed data with low latency (milliseconds).
Higher storage cost per GB compared to Archive.
No retrieval fee for data access.
Archive Storage Class
Designed for long-term backup of data accessed less than once per year.
Lowest storage cost per GB.
High retrieval fee and latency of several hours to access data.
Cloud Monitoring
Collects infrastructure-level metrics like CPU, memory, disk, and network utilisation.
Shows you what resource is being used, but not which code is using it.
Used for identifying infrastructure bottlenecks.
Cloud Profiler
Collects application-level data showing which functions consume the most CPU and memory.
Shows you which specific line of code is the problem.
Used for identifying code-level performance issues.
Mistake
If my application is slow, I should always upgrade to a bigger VM instance.
Correct
You should first identify the bottleneck using Cloud Monitoring. Often the bottleneck is not CPU but storage I/O or network. Upgrading the wrong resource wastes money and may not fix the slowness.
Beginners assume a faster computer always means a faster application. But cloud applications have many components, and the slowest part is the bottleneck. Fixing the wrong part is like buying a faster engine for a car whose tyres are flat.
Mistake
Autoscaling always saves money because you only pay for what you use.
Correct
Autoscaling saves money only if you have variable traffic. If traffic is steady 24/7, autoscaling adds overhead and you are better off with a committed use discount on a fixed number of instances.
People hear 'autoscaling is cost-effective' and apply it everywhere. But constant scaling up and down can cause thrashing (rapidly adding and removing instances), which leads to wasted time spinning up new VMs and paying for partial minutes.
Mistake
Using the cheapest storage class is always the best for cost optimisation.
Correct
Choosing the cheapest storage class is good only if you do not need fast access. If you move frequently accessed data to Coldline or Archive, read latency skyrockets and re-read costs can exceed the savings.
The cost calculation includes retrieval fees. Beginners look only at the per-GB storage cost and ignore the per-GB retrieval cost and the time penalty. This mistake comes from not reading the full pricing page.
Mistake
Cloud Monitoring shows me exactly what is wrong.
Correct
Cloud Monitoring shows you metrics, not causes. High CPU utilisation could mean a code bug, a sudden traffic spike, or a failing hardware component. You must interpret the metric and then use Cloud Profiler or Trace to find the root cause.
Non-technical people think monitoring is magic. They see a red alert and expect the tool to tell them the fix. But monitoring is just data; the engineer must apply reasoning.
Mistake
Preemptible VMs are the same as regular VMs but cheaper.
Correct
Preemptible VMs can be shut down at any moment with 30 seconds notice. They are not suitable for stateful workloads (like databases) or long-running jobs that cannot be checkpointed and restarted.
The low price is tempting, but beginners ignore the 'preemptible' part. They treat them like regular VMs and lose work. This is a classic exam trap.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Use Cloud Profiler to see which functions in your code consume the most CPU and memory. Use Cloud Trace to see the latency of each service call. If infrastructure metrics (CPU, memory, disk) are low but the code is slow, the problem is in the code, not the servers.
Vertical scaling means making a single server bigger (more CPU, more RAM). Horizontal scaling means adding more servers to share the load. Horizontal scaling is usually better for availability and cost because you can add and remove servers as demand changes.
No. Preemptible VMs can be terminated at any time, so they are not safe for stateful applications like databases that require persistent data and continuous uptime. Use them for batch processing, rendering, or analytics jobs that can tolerate interruptions.
Right-sizing means changing your VM machine type to match the actual resource usage you see in Cloud Monitoring. If you use only 10% of your current VM's CPU, you downsize to a smaller, cheaper machine type that meets the real need.
Move data that is rarely accessed to cheaper storage classes like Nearline or Archive. Set lifecycle policies that automatically transition objects to colder storage after a set number of days. Delete unnecessary snapshots and old disk images.
A committed use discount (CUD) is a discount you get in exchange for promising to use a certain amount of compute resources for 1 or 3 years. You should use it only for predictable, steady workloads that run 24/7, like production databases or internal business applications.
You've finished Performance Tuning and Cost Optimization. Continue through the PCDOE study guide to build a complete picture of the exam.
Done with this chapter?