Performance optimization starts with identifying key metrics, usually related to latency and throughput. The addition of monitoring to capture and track these metrics exposes weak points in the application. Finally, optimization can be undertaken to improve performance metrics.

Identify latency metrics

Ensure that you keep your UI as responsive as you can, noting that users expect even higher standards from mobile applications. Latency should also be measured and tracked for backend services, particularly since it can lead to throughput issues if left unchecked.

Some suggested metrics to track include:

  • Request duration.
  • Request duration at subsystem granularity (such as API calls).
  • Job duration.

Identify throughput metrics

Throughput is a measure of the total number of requests served over a given period of time. Throughput may be affected by latency of subsystems, so you may need to optimize for latency to improve throughput.

Some suggested metrics to track include:

  • Queries per second.
  • Size of data transferred per second.
  • Number of I/O operations per second.
  • Resource utilization (CPU/memory usage etc.)
  • Size of processing backlog (pub/sub, number of threads etc.)

Don't be mean

A common mistake in measuring performance is only looking at the mean (average) case. While this is useful, it doesn't provide insight into the distribution of latency. A better metric to track is the performance percentiles, for example select 50th/75th/90th/99th percentile for a metric. Generally optimizing can be done in two steps. First optimize for 90th percentile latency, then consider the 99th percentile (also known as tail latency)—the small portion of requests which take much longer to complete.

Server-side monitoring for detailed results

Server side profiling is generally preferred for tracking metrics. The server side is usually much easier to instrument, allows access to more granular data, and is less subject to perturbation from connectivity issues. Once you instrument code to capture performance timings, you can use a framework such as Google Stackdriver to setup monitoring dashboards tracking performance.

Stackdriver dashboard showing request latency timings

Browser monitoring for end-to-end visibility

Browser profiling can provide additional insights into the end user experience, it will show which pages have slow requests, and you can map these onto server side monitoring to further investigate. Google Analytics provides out of the box monitoring for page load times in the page timings report. This provides several useful views for understanding the user experience on your site, in particular:

  • Page load times
  • Redirect load times
  • Server response times