A cloud system must be fast enough for its users and cheap enough for its owner. The two aims often pull in different directions, and the engineer must find a balance.

Measuring Performance

Performance is measured by response time or latency, the time to answer a request, throughput, the number of requests handled per second, utilisation of CPU, memory and network, availability, the share of time that the service is up, and error rate. Tools such as Amazon CloudWatch, Azure Monitor and Prometheus collect these metrics, and set alarms. Load testing shows how the system behaves under heavy use, and tracing finds the slow part of a request.

Techniques of Performance Optimization

Right-sizing picks the instance type that fits the load, so that it is neither starved nor idle. Auto-scaling adds and removes instances with the load. Load balancing spreads requests. Caching keeps frequent answers in fast memory, such as Redis or Memcached, which cuts the load on the database. A content delivery network (CDN), such as CloudFront, keeps copies of content near the users, to reduce latency. Database tuning, with indexes and read replicas, speeds up data access. Asynchronous processing with queues moves slow tasks out of the request path. Placing resources close to the users, in the right region, cuts delay. Compression and efficient code also help.

Definition: Caching. Keeping copies of frequently used data in fast storage near the point of use, so that later requests are answered quickly without repeating slow work.

Techniques of Cost Efficiency

Pay for what is used: shut down idle resources, and use auto-scaling to follow demand. Choose the right pricing model: on-demand for uncertain loads, reserved instances or savings plans for steady loads, and spot instances for tasks that can be interrupted, at much lower prices. Use storage tiers, moving old data to cheaper archives. Reduce data transfer between regions, since egress is costly. Tag resources and set budgets and alerts. Use serverless for irregular work. Review costs often with the tools of the provider, in the practice of FinOps. A cheaper design is not always the best, since the cost of failure or slow service may be more than the saving.

Table 4.1: Optimization techniques

Technique Goal Effect
Auto-scaling Match capacity to load Lower cost, steady speed
Caching Avoid repeat work Lower latency
CDN Serve content near users Lower latency
Reserved instances Commit for a discount Lower cost
Spot instances Use spare capacity Much lower cost

Example 4.1: Effect of a cache

Problem: A page takes 200 ms to build from the database and 5 ms from the cache. 90 percent of requests are found in the cache. Find the average response time.

Solution:

  1. Average = 0.9 × 5 + 0.1 × 200.
  2. = 4.5 + 20 = 24.5 ms.

Result: The average is 24.5 ms, about eight times faster than the 200 ms without a cache.

hit, t_cache, t_db = 0.9, 5, 200
avg = hit * t_cache + (1 - hit) * t_db
print(avg, round(t_db / avg, 1))

Output

24.499999999999996 8.2

Common mistakes

  • Choosing the biggest instance size just to be safe, which wastes money.
  • Caching data that changes often without a plan to refresh it.
  • Optimizing cost alone and letting the service become slow or unreliable.

Key takeaways

  • Performance is measured by latency, throughput, utilisation and availability.
  • Caching, CDNs, auto-scaling and right-sizing improve performance.
  • Reserved and spot instances and storage tiers cut cost.
  • Monitor continuously and review costs often.

Practice questions

  1. Name three measures of performance.
  2. What is caching?
  3. Name two ways to cut cloud cost.

Answers to the practice questions

  1. Latency, throughput and availability (also utilisation, error rate).
  2. Keeping frequently used data in fast storage so that later requests are answered quickly.
  3. Right-sizing and reserved or spot instances (also shutting down idle resources, storage tiers).

Sources

  • Official BCA syllabus Cloud Computing, course code 25BCA405DS03, Unit IV