Engineering Optimization of LLM Inference Latency and Throughput
This article explains how to measure and improve LLM inference performance, covering TTFT, TPOT, end-to-end duration, and concurrency limits. It discusses why text-first pipelines are easier to optimize, five practical ways to speed up slower models, how to build a model evaluation scorecard, and how to plan capacity and cost with extra headroom for multimodal workloads.
1. Where the Problem Starts: Release Cadence Is Really a Compute Constraint
A pattern keeps repeating in this round of LLM releases: flagship and lightweight models from different vendors tend to ship in similar time windows, and models with strong text-only capability often come first. This is not a marketing coincidence. It is the combined result of compute supply and how training and inference resources are allocated.
Multimodal capability has a visibly heavier cost structure. Text inference compute grows mainly with context length and generation length, while images, video, and audio must be encoded and aligned before they enter the model, which adds the compute cost of high-dimensional representations on top of the original sequence. During training, multimodal sample pairs also place higher demands on storage bandwidth and parallel communication. As a result, multimodal versions usually face tighter resource scheduling, while text-only versions are easier to iterate and deliver quickly.
For adopters, the practical takeaway is that a model’s “newness” is not the same as the quality of its engineering experience. What actually determines the production experience is latency, throughput, stability, and unit cost, not release order.
2. Breaking “Fast and Slow” into Measurable Metrics
Many teams complain that a model is “too slow,” but without metric decomposition there is no way to locate the bottleneck. At minimum, separate these four quantities:
- Time to first token (TTFT): the time from sending a request to receiving the first visible output. It determines how responsive the interaction feels.
- Time per output token (TPOT): the average interval between subsequent output chunks. It determines how smoothly long text reads.
- End-to-end total duration: most affected by output length, so long-generation tasks should be measured separately.
- Throughput and concurrency ceiling: the number of requests served per unit of time, which determines capacity and cost.
Illustrative load-testing and measurement logic can be written as follows (pseudocode, expressing only the measurement approach):
def measure_once(client, prompt, max_tokens=512):t0 = now_ms()first_token_at = Nonechunks = []for piece in client.stream(prompt, max_tokens=max_tokens):if first_token_at is None:first_token_at = now_ms()chunks.append(piece)t1 = now_ms()return {"ttft_ms": first_token_at - t0,"tpot_ms": (t1 - first_token_at) / max(1, len(chunks) - 1),"total_ms": t1 - t0,"out_tokens": len(chunks),}
One point deserves emphasis: measuring a single request is almost meaningless. Production behavior depends on queuing under concurrency, so measurements must be repeated at stepped concurrency levels (for example 1, 5, 20, 50) to observe whether TTFT rises nonlinearly as concurrency increases. If TTFT degrades sharply at moderate concurrency, the bottleneck is usually server-side queuing and GPU memory or batching configuration, not the model being inherently slow.
3. The Engineering Logic of Text-First
Text-only pipelines are preferred in most business scenarios for three reasons.
First, the pipeline is short. Input and output are scalar sequences, preprocessing and postprocessing are minimal, network transfer volume is small, and serialization overhead is low, which makes it easy to push TTFT down to a few hundred milliseconds.
Second, it is cache-friendly. Prompt prefixes in text requests are often highly repetitive, so prefix caching, result caching, and semantic caching can all cut repeated computation significantly. Multimodal inputs are large in binary size and highly variable, so their cache hit rate is naturally lower.
Third, it is more predictable. Text token counts are easy to estimate, and capacity planning can extrapolate linearly from token throughput. Multimodal compute consumption depends on resolution, frame count, and duration, so it fluctuates more and capacity headroom must be wider.
A common practice is to tier the system: latency-sensitive stages that need immediate feedback go through a lightweight text-only model, while stages that need image or audio/video understanding are triggered asynchronously through a multimodal pipeline, with long-running work moved off the user’s waiting path via a task queue and result callback.
User request|- Sync: text understanding / intent recognition / structured extraction (low latency)\- Async: multimodal parsing -> message queue -> inference cluster -> object storage -> callback notification
4. Five Ways to Speed Up a Slower Model
If the business must use a more capable but slower model, optimization can start from these directions, most of which are vendor-independent:
- Cap output length. Generation time is the main source of latency, and aligning max_tokens with actual business needs often pays off more than switching models.
- Stream responses. Render as soon as the first token arrives, turning a “total duration” problem into a “first token latency” problem, which noticeably improves perceived experience.
- Batching and concurrency scheduling. Reasonable dynamic batching on the server improves throughput, but it must work with timeout policies so that long requests do not slow down the whole batch.
- Tiered caching. Exact caching handles repeated requests, prefix caching handles shared system prompts, and semantic caching handles paraphrased questions. Combined, the three typically remove a substantial share of calls.
- Model tier routing. Use a lightweight model for high-frequency simple requests, and escalate to a stronger model only when confidence is insufficient or the task is complex.
The routing logic can be simplified as:
def route(req):if req.estimated_output_tokens < 200 and req.complexity == "low":return light_modelif req.need_vision or req.complexity == "high":return strong_modelreturn light_model
5. A Selection Scorecard: Turning Subjective Impressions into Decision Inputs
It is worth building a reusable scorecard during technology selection, covering the following dimensions with a weight assigned to each:
- Latency profile: TTFT and TPOT curves at different concurrency levels;
- Capability coverage: accuracy and format compliance on the target task set;
- Context and output limits: whether long-document and long-generation needs are met;
- Stability: error rate, timeout rate, and how often rate limits are triggered;
- Cost structure: the difference between per-token billing and resource-usage billing, converted using your own traffic model;
- Ecosystem and operability: whether logging, monitoring and alerting, and tracing are complete.
Evaluation must use your own business samples, not generic leaderboards. A reliable approach is to sample 200 to 500 real requests into a fixed evaluation set, run it after every model or parameter change, and write results into the logging service and monitoring and alerting system to form a baseline that supports continuous comparison.
6. Capacity and Cost: Leave Headroom for Multimodal
Multimodal capability has stronger elasticity requirements for compute. Three principles are recommended for capacity planning: first, separate the sync and async pipelines into different pools so long tasks do not crowd out interactive resources; second, reserve an independent resource pool for multimodal parsing and set caps on queue length and wait timeout; third, put immutable inputs such as images and audio/video into object storage and pass them by reference, avoiding repeated transfer of large objects through the inference pipeline.
If a container platform hosts the inference services, pair it with elastic scaling and priority queues, and mark interactive requests as high priority. Logging and monitoring need to cover metrics such as queue time, batch size, and GPU memory usage; otherwise capacity problems only surface when users complain.
7. Conclusion
The gap in model release timing essentially reflects how compute is allocated between multimodal and text-only work, not a direct ranking of capability. The more robust engineering path is to first establish a quantifiable latency and throughput baseline, then carry the main interactions on a low-latency text-only pipeline, treat multimodal as an asynchronous enhancement, and finally use output length control, streaming responses, tiered caching, and model tier routing to bring a stronger model’s latency back into an acceptable range. The combination of general capabilities offered by Baidu AI Cloud across model services, container platforms, object storage, and monitoring and alerting can serve as an infrastructure reference when implementing this architecture.
