Skip to content

No limit, no queue: which server breaks first, Python, Go or Rust?

The same AI service in all three, with every setting left at its default. One loses hundreds of requests and grows to 2 GB.

Bassically · AI Service series, part 3. I measured this on my own machine. The code is in the repo.

Short answer: Go, and not because of Go. With nothing set, each framework decides how many requests it works on at once, and that one default decides who breaks.

This is not how to run a server: part 2 showed that with a limit and a queue, none of the three loses a request. Here I took those away.

What I tested

  • The service: a cat photo goes in over HTTP, the model answers "Egyptian cat". The servers are part 2's, unchanged.
  • The servers: Python with FastAPI, Go with net/http, Rust with axum. Same MobileNetV2 model, same ONNX Runtime, on the CPU.
  • What I left out: no limit, no queue, no thread count, one process each.
  • Failed means not accepted, or not answered, within 10 seconds. Every number is the median of five runs.

One endpoint, three servers, the same answer.

The result

A thousand connections for 20 seconds:

PythonGoRust
failed1016370
median wait2.5 s0.19 s5.4 s
peak memory535 MB1,979 MB661 MB

Three defaults, three ways of handling a thousand connections.

Go lost 637 requests and grew to 2 GB

  • What happened: every request started at once. Half were answered fast, the rest waited past 10 seconds and failed.
  • Why: Go's net/http starts a goroutine for every connection and has no limit. A goroutine costs a few kilobytes, so the standard library leaves the limit to you.
  • Why memory exploded: a thousand photos were decoded at the same time, each with its own buffers.

Python lost 101 requests

  • What happened: memory stayed safe at 535 MB, but some connections were never accepted.
  • Why: FastAPI runs heavy work on a thread pool that holds 40. Request 41 waits outside, and whoever waits past 10 seconds counts as failed.
  • Note: nobody picked 40 for running a model. It is a general default that happens to act as a limit.

Rust lost none, but everyone waited 5.4 seconds

  • What happened: every request was answered, all at about the same speed.
  • Why: tokio allows 512 threads, but Rust's ONNX Runtime library, ort, lets only one request use a loaded model at a time. Its author does not consider ONNX Runtime safe to share between threads.
  • So: 512 photos can be decoded at once, but they go through the model in single file. That is the strictest limit of the three.

The other tests say the same

TestPythonGoRust
1,000 at the same momentfailed in 4 of 5 runsfailed in 1 of 5answered all, in 9.5 s
150% of capacity0 failed339 failed0 failed
half of capacity8.6 ms10.6 ms8.1 ms
  • Rust is close to the edge: at a thousand at once it needed 9.5 of the 10 seconds, because one model handles about 105 photos per second.
  • Below capacity all three are fine, because nothing has to wait. The defaults only matter once the load passes what a server can serve.

Did the GIL make Python lose requests?

Python's 101 failed requests were connections that were never accepted. A common suspect is the GIL.

  • What the GIL is: a lock in Python. Only one thread can run Python code at a time.
  • Why it could be the cause: accepting a connection is Python code. While one thread holds the lock, new connections wait outside.
  • How I tested it: four processes instead of one. Each process has its own lock, so four can accept at the same time. If the GIL is the bottleneck, failures should drop.
1 process4 processes
answered per second497540
runs that lost requests4 of 52 of 5
memory when idle165 MB711 MB

Four processes are not clearly faster, but they lose fewer requests.

  • Failures dropped, from 4 runs of 5 to 2. That fits the GIL: more locks, more connections accepted in time.
  • Speed barely moved. Why: the photo and model work does not need the lock, because it runs in C and C++ libraries that release it (part 1).
  • Not proven: four processes are also four separate servers accepting connections, lock or no lock. This test cannot separate the two.

So the GIL may explain why Python lost requests. It does not explain its speed.

So which breaks first?

  1. Go, because its standard library trusts you to set the limit, and I did not.
  2. Python, because its 40 threads protect memory but leave connections waiting outside.
  3. Rust does not break, because its library refuses to share the model. It is the slowest instead.

That ranks three defaults, not three languages: the same model ran at the same speed in all three.

What to do instead

Give every heavy server three rules:

  • A limit: how many requests to work on at once.
  • A queue: how many may wait.
  • A "busy" answer (HTTP 503) for the rest, right away.

Part 2 did exactly that, and none of the three lost a request. In Go it is a channel and four lines.

Limits

  • The load tool and the servers share one laptop.
  • One small photo, one small model, the CPU only.
  • Not measured: why Python and Go accept connections late while busy, and why Go's waits are so uneven.

Next

Part 4 answers the question the series started with: if you build an AI service tomorrow, which one do you pick?

Setup

  • MacBook Pro M1 Pro (10 cores), 32 GB, on AC power
  • ONNX Runtime 1.32.0
  • Python 3.14.6 with FastAPI 0.163.2
  • Go 1.27.4
  • Rust 1.100.0 with axum 0.8.9 and ort 2.0.0-rc.15
  • Load tool: oha 1.17.0
  • Code and raw results: github.com/haryarrahman14/ai-service-series, folder 03-defaults

Sources

Follow