Bassically · AI Service series, part 4, the conclusion. Nothing new is measured: every number comes from parts 1 to 3, which I measured on my own machine.
Short answer: start with Python, unless you have a reason you can put a number on. The language does not make the model faster, and it does not decide whether the service survives. What differs is the price each language pays.
What was measured
- The service: a cat photo goes in, MobileNetV2 answers "Egyptian cat", through ONNX Runtime on the CPU. The same in all three languages.
- Part 1: one request. The model step costs almost the same in all three.
- Part 2: a thousand requests, each language set up at its best. None failed.
- Part 3: a thousand requests, nothing set. Go lost the most.
The answer, by situation
| Your situation | Pick | You pay |
|---|---|---|
| The team that trains the model also runs the service | Python | 852 MB, five processes |
| Memory is tight, or you want many small instances | Go | 52.6 ms on a large photo |
| You want one process and fast photo handling | Rust | 367 MB, or 84 MB with unsafe |
| Most requests never touch a model | Go or Rust |
The answer in one picture.
Python: the starting choice
- Why pick it: models are made in Python, so the people who train the model can read and change the service. Its ONNX Runtime binding is the official one.
- Why it gives up no speed: the same C++ library runs the model in all three. The model step: 5.6 ms (Python), 6.0 ms (Go), 5.4 ms (Rust). On a large JPEG Python is even the fastest, at 19.0 ms.
- What you pay: 852 MB when idle.
- Why that much: with one process Python failed the retry test, up to 414 connections in 10 seconds. It stopped failing at five processes, and each process loads its own model, about 170 MB.
Go: when memory and a single process matter
- Why pick it: one process, one copy of the model, 99 MB, no trick.
- What you pay: the slowest image code. A large JPEG takes 52.6 ms, against 19.0 ms in Python.
- Why it is slow: its image libraries are written in plain Go, not C. The heavier the model, the less this gap matters: with ResNet50 it is down to a tenth of the request.
- One more thing: its standard server has no limit. With nothing set it lost 637 requests, so you have to write the limit yourself.
Rust: when you want a single process and fast photos
- Why pick it: one process, and per request it is level with Python. A small PNG takes 9.0 ms, against 15.1 ms in Go.
- What you pay: 367 MB, heavier than Go.
- Why:
ort, its ONNX Runtime library, lets only one request use a loaded model at a time. Twenty requests at once need twenty copies of the model. Its author does not consider ONNX Runtime safe to share between threads. - The shortcut: one
unsafeline shares a single copy and gives 84 MB, the lightest of all. That goes against the author's advice, and I only tested it on the CPU for a few minutes.
From part 2: nobody broke, the price is different.
Go or Rust: when most requests never touch a model
- Result: the
/pingendpoint, which answers without a photo or the model, was answered 16,588 times per second by Python, 91,697 by Go and 106,118 by Rust. - Why: in an image classifier the time goes into C and C++ libraries, so Python does almost none of the work. On
/pingthe language's own code does the work. - Note: the load tool ran on the same machine, so this is a comparison, not each server's limit.
In any language: a limit, a queue and a "busy" answer
A thousand connections for 20 seconds, failed requests:
| Python | Go | Rust | |
|---|---|---|---|
| nothing set (part 3) | 101 | 637 | 0 |
| a limit, a queue of 100, "busy" (part 2) | 0 | 0 | 0 |
From part 3: three defaults, three results.
- Why this decides it: with nothing set, each framework's default decides how many requests are worked on at once. Go lets everything in, Python 40, Rust runs the model for one. Rust lost nothing, but everyone waited 5.4 seconds.
- Why you write it yourself: no framework sets it for you. In Go it is a channel and four lines.
- The numbers: 32 at once for Go and 8 per process for Python belong to one laptop and one small model. Measure on your own machine.
What this series did not measure
- GPUs. Everything ran on the CPU.
- A large model under load. Python's and Rust's memory grows with the number of model copies.
- A separate load machine. The load tool and the server shared one laptop.
- Linux. Everything ran on macOS.
- Long runs. Each test lasted 20 seconds.
- Whether the GIL is why Python accepts connections late. Go, which has no GIL, was late too.
- Team speed. "The team that trains the model" in the table is a judgment, not a measurement.
So the answer above holds for a small service on the CPU. Beyond that, measure first.
Closing
This series started by asking why almost every AI service is written in Python. The answer is the same as the conclusion: in a service like this, the language does almost none of the work. The library underneath and the settings on top do.
Run the code on your machine. If your numbers differ from mine, I would like to know.
Setup
- MacBook Pro M1 Pro (10 cores), 32 GB
- 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
ort2.0.0-rc.15 - Code and raw results: github.com/haryarrahman14/ai-service-series
Sources
- Part 1: Why is almost every AI service written in Python?
- Part 2: A thousand requests at once
- Part 3: No limit, no queue
- ort: one request per session
Follow
- Instagram (Bahasa Indonesia): @dasarnya.id
- Instagram (English): @bassically.en
- Threads (Bahasa Indonesia): @dasarnya.id
- Threads (English): @bassically.en
- Medium: @haryarrahman14