Two Qwen Code sessions on one Ollama slot waited 46 seconds; a slot each waited one
- Hardware
- One NVIDIA L4 (24 GB) for the Ollama comparison
- Models & engines
- Qwen Code 0.27.4 talking to Qwen3.8-27B Q4_K_M
Ollama 0.40.16, and standalone llama.cpp b12441 for the follow-up
For two slots on Ollama: OLLAMA_NUM_PARALLEL=2 and OLLAMA_CONTEXT_LENGTH=16384 - Key gotcha
- The 46-to-1-second comparison is not cache reuse alone: two slots also remove queueing. The llama.cpp -sps 0 test is the closer look at the cache decision, and the second agent still had to process its first prompt in full.
What they built
A coding agent looks like one conversation, but each tool result sends a longer prompt that mostly repeats the last one. That reuse is cheap when the server can keep the previous turn's model state. It gets expensive when a second agent takes the same slot.
Tensward tried this with two unmodified Qwen Code sessions running against Ollama. When both sessions took turns on one slot, the median request waited about 46 seconds for the response to start. When each session had a slot of its own, it waited about one second.
With a shared slot, 54% of the prompt tokens the server processed were repeats. With a slot each, that fell to 0.4%. The model was Qwen3.8-27B, a hybrid with full-attention layers and recurrent layers whose running state is updated in place, so a later token can wipe the state an earlier prefix would need.
Setup
- Qwen Code 0.27.4 talking to Qwen3.8-27B Q4_K_M
- One NVIDIA L4 (24 GB) for the Ollama comparison
- Ollama 0.40.16, and standalone llama.cpp b12441 for the follow-up
- For two slots on Ollama: OLLAMA_NUM_PARALLEL=2 and OLLAMA_CONTEXT_LENGTH=16384
How it works
- The two sessions shared a long prefix, then diverged. After one session finished, its earliest saved checkpoint already included tokens the other session did not share, so the server often had to start the next prompt from token one.
- The sessions shared 60-66% of their tokens, which cleared llama.cpp's 50% threshold for reusing the slot directly, even though the matching text contained no usable checkpoint. Each switch then displaced the state the other session would need next.
- On standalone llama.cpp they kept both agents on one slot and used -sps 0 so each request went through the RAM cache. On Ollama 0.40.16 they could give each session a slot, but the runner did not expose the similarity flag. The 16,384-token budget still fit the largest prompt, which was 14,956 tokens.
Results & numbers
- On Ollama, the shared-slot median wait was about 46 seconds, against about one second with a slot each. That result includes both better cache reuse and the ability to serve the two sessions at the same time.
- In standalone llama.cpp on one slot, default runs processed about 128,800 prompt tokens with a median first-byte wait of 48.5 s and 47.1 s, and 2.4-2.9 GiB of peak host memory. With -sps 0, prompt tokens fell to 43,300 and 43,700, the wait to 17.4 s and 16.8 s, and peak host memory rose to 7.2 GiB.
- Saving and loading state cost about 0.8 seconds per request. From the timestamps, they estimate that roughly 14 of the remaining 17 seconds were spent waiting for the other session to finish.
- In a separate test of eight short conversations that shared a system prompt, allowing closer checkpoints with --checkpoint-min-step 0 let all eight slots save at that boundary. Across four paired Ollama runs, throughput rose 10.9% and median time to first token fell 17.5%.
Gotchas
- The 46-to-1-second comparison is not cache reuse alone: two slots also remove queueing. The llama.cpp -sps 0 test is the closer look at the cache decision, and the second agent still had to process its first prompt in full.
- The coding-agent comparison used one small fix-the-tests task, with one run per Ollama configuration and two per llama.cpp configuration. One session alone, including a test with two sub-agents, showed little repeated processing.
- The eight-slot checkpoint result was measured on short tool-calling conversations, not a long agent session. Hybrid models lose their place more easily than a full-attention model, because recurrent state cannot be trimmed the same way as a KV cache.
“With a shared slot, 54% of the prompt tokens it processed were repeats. With a slot each, that fell to 0.4%.”— Tensward
Do it yourself
- If two agents share one Ollama model, watch how long each request waits for the first token and how many prompt tokens the server processes after a switch.
- Try giving each session its own slot, for example OLLAMA_NUM_PARALLEL=2, and set OLLAMA_CONTEXT_LENGTH so the largest prompt still fits.
- On standalone llama.cpp, -sps 0 sends each request through the RAM cache, at the cost of more host memory.
- For many short conversations that share a system prompt, check whether checkpoints land at the end of that prompt; --checkpoint-min-step 0 is the flag Tensward used to allow closer saves.
OLLAMA_NUM_PARALLEL=2 OLLAMA_CONTEXT_LENGTH=16384 ollama serveSimilar setups
Running a 35B MoE model on a laptop with a 4 GB GTX 1650: measured, not guessed
Nabil Doghri ran Qwen3.6-35B-A3B (Q4_K_M) through Ollama on a GTX 1650 Max-Q laptop and measured about 21-22 tokens per second once loaded, with most of the 23 GB model sitting in system RAM.
Running NVIDIA's looped Dory 4B on a CPU homelab with llama.cpp and an Ollama wrapper
Big Iron built NVIDIA's llama.cpp fork on a no-GPU Debian VM, measured Dory 1.0 4B at each loop count against Qwen3.5-4B, and got it running inside Ollama 0.40 through a wrapper around Ollama's internal llama-server.
Replacing Ollama with a llama.cpp router on a shared workstation GPU
A developer moved a busy single-GPU workstation (chat UI, agent, batch study-guide writer, embedders, classifiers) from Ollama to llama.cpp's router mode and measured throughput and embedding parity before switching.
LM Studio vs Ollama on an RTX 5080: memory settings mattered more than the app
LK Wood IV ran LM Studio and Ollama on the same RTX 5080 with identical GGUF files and found the apps within 14% of each other, while one wrong offload or context setting cost up to 3.4x.