Sub topic 17
Troubleshooting memory, speed, and connection problems
This chapter assumes you can run ollama pull and ollama run, call the REST API on port 11434, and read basic terminal output. Most Ollama problems fall into three groups: the server is unreachable, the model does not fit in memory, or generation is slow. Check them in that order.
Connection problems
A "connection refused" error means no server is listening where the client is looking. Test the default address first:
curl http://localhost:11434A healthy server replies Ollama is running. If it does not:
- Start the server with
ollama serve, or start the system service your installer created. - If you set
OLLAMA_HOST, make sure the client uses the same host and port. - If the client runs in a container or another machine,
localhostpoints at the wrong place. Bind the server to a reachable address, for exampleOLLAMA_HOST=0.0.0.0, and restrict access with a firewall, because Ollama has no authentication.
The server log shows why a start failed. On Linux with systemd, run journalctl -u ollama. On macOS, read ~/.ollama/logs/server.log.
Memory problems
A model needs memory for its weights plus a cache that grows with the context window. Two things commonly cause failures:
- The model is too large. You may see an error such as "model requires more system memory than is available". Pick a smaller parameter count or a lower quantization, such as a 4-bit tag.
num_ctxis too high. A larger context window increases memory use even when the prompt is short.
Run ollama ps while a model is loaded. The PROCESSOR column shows where it runs. 100% GPU is the fast case. A split such as 40%/60% CPU/GPU means part of the model spilled into system RAM, which slows generation.
Speed problems
Slow output usually has one of these causes:
- CPU offload. If
ollama psshows CPU use, shrink the model or the context. - Cold start. The first request after idle time reloads the model. Raise
OLLAMA_KEEP_ALIVEto keep it in memory longer. - Long prompts. The time before the first token grows with prompt length.
- Other programs. Browsers and games compete for GPU memory.
This script times a request and reports the server's own numbers:
import requests
resp = requests.post(
"http://localhost:11434/api/generate",
json={"model": "llama3.2", "prompt": "Say hello.", "stream": False},
timeout=120,
)
resp.raise_for_status()
data = resp.json()
print("load seconds:", data["load_duration"] / 1e9)
print("tokens/s:", data["eval_count"] / (data["eval_duration"] / 1e9))A large load_duration points to a cold start. A low tokens-per-second figure with ollama ps showing CPU use points to offload.
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection refused | Server not running or wrong host | `ollama serve`, check `OLLAMA_HOST` |
| Out-of-memory error on load | Model or `num_ctx` too large | Smaller tag, lower `num_ctx` |
| Slow replies, CPU shown | Partial offload | Smaller model or context |
| Slow first reply only | Model unloaded after idle | Increase `OLLAMA_KEEP_ALIVE` |
Exercise
You run ollama ps and the PROCESSOR column reads "35%/65% CPU/GPU". Replies are slow. Name the cause and two ways to fix it.
Show answer
The model does not fully fit in GPU memory, so part of it runs on the CPU. Use a smaller model or a lower quantization, or reduce num_ctx so the context cache takes less memory.