I Made Six Languages Fight Over an HTTP Server
I had a very normal thought: what happens if I write the same HTTP server in six different languages and make all of them suffer under the same workload?
So that is exactly what I did. This post is about the server itself, why I built it, how the six implementations differ, and what happened when I pushed concurrent connections from 1 all the way to 1000.
The important result is not “language X is better than language Y”. It is that an HTTP server is a surprisingly nice little microscope for looking at sockets, concurrency, runtimes and the cost of abstractions.
01 · Why I Did This
Most programming-language comparisons eventually collapse into the same argument: somebody posts a graph, somebody else replies “but benchmarks are fake”, and five minutes later everyone is comparing logos.
I wanted something more useful.
I wanted to understand what actually happens when several languages are asked to do the same small networking job. That meant writing roughly the same HTTP server in C, C++, Go, Java, JavaScript and Python, then giving them the same general workload.
The project was also an excuse to learn more about networking instead of treating HTTP as a magical function called app.listen() that simply appears whenever a tutorial tells you to.
I wanted to see the boring parts too: sockets, connections, concurrency, latency, CPU usage and memory.
So, naturally, I turned a perfectly reasonable learning exercise into a pile of graphs.
02 · What Actually Is an HTTP Server?
At a high level, an HTTP server is just a program that waits for clients, receives HTTP requests and sends HTTP responses back.
Underneath that HTTP layer, these implementations are dealing with network connections. For this project, that means TCP sockets.
socket()
│
▼
bind()
│
▼
listen()
│
▼
accept()
│
▼
read request
│
▼
parse HTTP
│
▼
build response
│
▼
write response
│
▼
close connection
The TCP side
The server creates a socket, binds it to an address and port, and starts listening. When a client connects, the server accepts that connection and gets a socket it can use to talk to that client.
The HTTP side
Once the connection exists, the server is just receiving bytes. Those bytes happen to follow the HTTP protocol.
GET / HTTP/1.1
Host: localhost
Connection: close
The server then sends bytes back in the form of an HTTP response:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 18
hello from TaHooR
That is the basic loop. The fun starts when a lot of clients want to do it at the same time, because now the server has to deal with concurrency, scheduling and resource usage instead of one polite browser behaving itself.
03 · The Six Implementations
I kept the servers intentionally small. The point was not to compare six giant frameworks with six completely different feature sets. The point was to keep the job similar enough that the runtime and implementation differences were actually interesting.
C
C sits closest to the socket API here. The code is explicit, the operating-system calls are visible, and there is not much standing between the program and the network stack.
int server_fd = socket(AF_INET, SOCK_STREAM, 0);
bind(server_fd, (struct sockaddr *)&address, sizeof(address));
listen(server_fd, SOMAXCONN);
while (1) {
int client_fd = accept(server_fd, NULL, NULL);
/* read request */
/* build response */
/* write response */
close(client_fd);
}
→ View the complete C implementation on GitHub
C++
C++ is still using the same underlying networking primitives, but the surrounding code gets the language's stronger abstractions and a little less “hello, I am manually holding a bag of bytes” energy.
int server = socket(AF_INET, SOCK_STREAM, 0);
bind(server, reinterpret_cast<sockaddr*>(&address),
sizeof(address));
listen(server, SOMAXCONN);
while (true) {
int client = accept(server, nullptr, nullptr);
// read request
// build response
// write response
close(client);
}
→ View the complete C++ implementation on GitHub
Go
Go changes the feel of the code quite a bit. Networking is in the standard library, and concurrency can be expressed with goroutines instead of manually mapping every connection to an operating-system thread.
listener, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal(err)
}
for {
conn, err := listener.Accept()
if err != nil {
continue
}
go handleConnection(conn)
}
→ View the complete Go implementation on GitHub
Java
Java brings the JVM into the picture. That means the application is running inside a managed runtime with its own memory-management and execution machinery. The interesting part is seeing what that costs in this particular workload.
ServerSocket server = new ServerSocket(8080);
while (true) {
Socket client = server.accept();
// read request
// build response
// write response
client.close();
}
→ View the complete Java implementation on GitHub
JavaScript
JavaScript uses Node.js here, so the networking model is event-driven and asynchronous. The interesting contrast is that the syntax looks extremely high-level while the benchmark is still ultimately measuring a program moving data over sockets.
import http from "http";
const server = http.createServer((req, res) => {
res.writeHead(200, {
"Content-Type": "text/plain"
});
res.end("hello from TaHooR");
});
server.listen(8080);
→ View the complete JavaScript implementation on GitHub
Python
Python gives us a very compact, readable networking implementation. There is a lot less ceremony around the actual HTTP server, which makes it a nice contrast with the lower-level implementations.
from http.server import HTTPServer, BaseHTTPRequestHandler
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
body = b"hello from TaHooR"
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
server = HTTPServer(("0.0.0.0", 8080), Handler)
server.serve_forever()
→ View the complete Python implementation on GitHub
04 · How I Tested Them
Every language was run against the same general workload. I varied concurrent connections and thread counts, then collected throughput, latency, CPU usage and peak memory.
Concurrent connections
1
10
100
500
1000
Thread counts
1 thread
2 threads
4 threads
8 threads
Metrics
- HTTP throughput
- Average latency
- Average CPU usage
- Peak memory usage
The aggregate dataset contains 51 completed tests for each language.
These numbers are measurements of these particular implementations, runtime configurations, hardware and workload. They are not a universal leaderboard for programming languages.
In other words: please do not walk into a programming-language subreddit with this graph and start a civil war.
05 · Results
Here is where the experiment gets spicy. The results are not what I would have guessed purely from the language names.
Aggregate results
| Language | Requests/s | CPU | Peak memory |
|---|---|---|---|
| C | 59,738 | 71.6% | 1.78 MB |
| C++ | 71,047 | 70.6% | 3.92 MB |
| Go | 42,962 | 93.2% | 10.48 MB |
| Java | 57,239 | 82.1% | 127.44 MB |
| JavaScript | 22,500 | 98.7% | 79.52 MB |
| Python | 53,351 | 82.7% | 10.28 MB |
So what stands out?
C++ came out on top for aggregate throughput in this dataset at about 71k requests per second. C followed at roughly 59.7k, with Java and Python surprisingly close behind.
C had the smallest peak memory footprint at about 1.78 MB in the aggregate results. Java, meanwhile, was by far the hungriest, reaching roughly 127.44 MB in the same summary.
JavaScript was the outlier on this workload. Its aggregate throughput was about 22.5k requests per second while its CPU figure was the highest of the six at about 98.7%.
And Go? Go's concurrency model is one of the most interesting parts of the comparison, but this particular benchmark did not magically reward it with first place. That is exactly why running the experiment was more useful than guessing the answer beforehand.
Throughput
Throughput is simply how many requests the server manages to process per second. Higher is better here.
Latency
Throughput tells us how much work gets done. Latency tells us how long an individual request is waiting around for its turn to leave the building.
CPU usage
CPU usage shows how aggressively each implementation is using the processor while handling the workload.
Memory usage
This graph is where runtime overhead becomes especially hard to ignore. Native implementations stay tiny in this setup, while managed or higher-level runtimes start carrying noticeably more baggage.
The full dataset
These four graphs are the visual summary, not the entire experiment. The repository contains the benchmark scripts and raw results so the whole thing can be inspected instead of trusting a suspiciously pretty graph on my website.
→ View the raw benchmark data on GitHub
I also kept the other thread counts in the repository because there is no reason to hide the ugly graphs just because the four-thread version is prettier.
06 · What I Actually Learned
The first lesson was that the language itself is only part of the story.
The runtime, networking APIs, concurrency model, memory management and the actual implementation all affect what the benchmark sees. Two programs written in the same language can behave very differently, which is why a benchmark like this should really be thought of as a benchmark of implementations, not a definitive ranking of language mascots.
The second lesson was that more threads do not automatically mean more performance. At some point the hardware, runtime and workload become the bottleneck, and throwing more parallelism at the problem just gives the CPU more paperwork.
The third lesson was the most useful one: networking stops feeling abstract once you build the thing yourself. accept(), sockets, requests, responses and concurrency suddenly become concrete instead of being vocabulary from a backend tutorial.
07 · Why Am I Cooler Than Random Kids?
This section is obviously peer-reviewed science.
$ ./why-am-i-cooler
checking credentials...
[✓] built an HTTP server
[✓] implemented it in six languages
[✓] tested 1 → 1000 concurrent connections
[✓] measured throughput
[✓] measured latency
[✓] measured CPU usage
[✓] measured memory usage
[✓] generated graphs
[✓] wrote the results down instead of saying "trust me bro"
random-kid.exe:
[✓] made another todo app
verdict:
TaHooR is cooler.
confidence interval:
probably
exit code: 0
Is this a scientifically valid way to establish coolness? No.
Did I spend several hours benchmarking servers instead of doing something sensible? Also no comment.
08 · Source Code
The complete implementations, benchmark tooling and result data are all in the repository.
→ Open the complete HTTP benchmark repository on GitHub
http-servers-bench/
├── servers/
│ ├── c/
│ ├── cpp/
│ ├── go/
│ ├── java/
│ ├── javascript/
│ └── python/
├── benchmark/
└── results/
I built this because I wanted to understand what was happening underneath the HTTP abstraction.
Also because “write the same HTTP server six times and benchmark it” is a much cooler weekend project than “make a to-do app”, and I will die on this hill.