CHAPTER 08 OF 12
Measure performance and recover from failures
Separate loading, prompt evaluation, decoding and quality before tuning.
In this chapter
Measure the experience your user has
A request can include model loading, tokenizing the prompt, evaluating the prompt, generating output and transferring it back to the application. A user waiting for an answer experiences all of those stages. A decoding rate usually describes only part of the work.
For an interactive product, record time to first visible output and time to completion. For batch extraction, also record throughput at a defined concurrency and the fraction of outputs that pass the rubric. A fast wrong answer is not a successful optimization. Keep download time and installer work outside inference timing, while still measuring them for the first-run experience.
The companion uses non-streaming requests, so it measures total client wall time rather than first-token latency. Runtime fields provide separate load, prompt and generation durations. Do not invent first-token latency from those fields. The native prototype records its own streaming timing separately, under a different protocol.
Change one variable at a time
Useful variables include artifact precision, context size, prompt length, output limit, concurrency and placement on CPU or GPU. Hold the task and scoring rule fixed while changing one variable. Record the new configuration. If several variables change together, you may improve the application but cannot confidently attribute the improvement to one of them.
Warm and initial-load runs are different. Even after unloading a model, operating-system file caches may remain warm. Call a run "after unload" when that is what you did; do not call it a cold-cache benchmark without controlling and documenting the relevant caches.
Thermal behavior matters on phones and laptops. A short burst may look good while sustained work slows down or triggers resource pressure. This edition has no sustained thermal test. A production plan should include realistic duration, charging state and ambient conditions.
Prerequisites
Use the same machine, runtime, model and companion files as earlier labs. Close unrelated heavy tasks if you want a less noisy comparison, and record that choice. Do not disable protections or force memory allocation to obtain a better number.
Steps
Run the small comparison:
python3 rtm_lab.py benchmark --output performance.jsonThe command executes three requests at a configured context of 1,024 tokens and three at 2,048. It also records loaded-runtime state.
Compare wall time with load, prompt-evaluation and generation durations in each raw response. Convert nanoseconds to seconds before comparing units.
Confirm that the answer remains correct. If the output changed or was truncated, treat that as part of the result.
Write down the limitations: these prompts are short, the outputs are short, earlier labs may have loaded the model, and a larger configured context does not mean a longer prompt was supplied.
Expected results
You should receive six preserved requests and measurements. Variation is normal. This sample is too small and too short for a stable model speed ranking or a credible tail-latency percentile. Its purpose is to teach how to separate measurements and avoid unfair comparisons.
Common failures
If loading fails, first check the exact artifact and available resources. If long prompts fail but short ones work, inspect context limits and input accounting. If generation is unexpectedly slow, check the runtime's loaded-model report and competing work. If the first request is much slower, examine load time before blaming decoding.
A process memory figure is not always GPU memory, and a model weight size is not total process memory. Preserve the original metric name and units instead of relabeling whichever number is easiest to obtain.
Exercise
Choose one realistic prompt length and one expected output length for your application. Run enough repetitions to see variability, retain all results and compare medians alongside correctness. Explain which additional evidence would be required before making a public speed claim.
Sources
Ollama generation metrics documents response timing fields. The measured book report preserves the actual small comparison and its limitations.