Idle Memory of a Go Binary vs PHP-FPM and Node

What I found when I measured idle memory on my own servers: a compiled Go binary sat at about 15 MB, PHP-FPM and Node used considerably more.

· 3 min read · Erik Kubica

I spent thirteen years writing PHP and JavaScript. I defended them in client meetings, refactored sprawling monoliths, and treated throwing another 4 GB of RAM at a virtual server as a normal cost of doing business.

Then server rates went up, cloud invoices started creeping upward, and I sat down with a terminal to look at what my servers were doing during idle hours.

I had not looked at this closely before, and the numbers surprised me.

The Baseline Memory Cost

Before a web application handles its first HTTP request, its runtime is already using memory.

Take a PHP-FPM pool running Laravel or Symfony. You configure five worker processes for modest traffic. Each worker boots the framework, loads dependencies, and settles at around 45 MB of Resident Set Size (RSS).

$ ps aux --sort=-%mem | grep -E "php-fpm|node|go-api" | head -n 6
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
www-data  1420  0.1  2.4 284120 48120 ?        S    08:12   0:01 php-fpm: pool www
www-data  1421  0.1  2.3 283900 46890 ?        S    08:12   0:01 php-fpm: pool www
www-data  1422  0.1  2.4 284240 48450 ?        S    08:12   0:01 php-fpm: pool www
node      1894  0.4  5.1 892340 102400 ?       Sl   08:14   0:04 node dist/server.js
app       2105  0.0  0.7  72450  14820 ?       Ssl  08:15   0:00 /usr/local/bin/api

What that output shows on my setup:

  • PHP-FPM: Three idle workers using roughly 143 MB RSS. Add five more to handle an afternoon traffic bump and you are near 400 MB just to keep the pool ready.
  • Node.js: One process at about 102 MB RSS before serving a single JSON response.
  • Go API: One compiled static binary at 14.8 MB RSS.
$ free -m
               total        used        free      shared  buff/cache   available
Mem:            1980         312        1240          14         428        1510
Swap:           1024           0        1024

On a $12 Hetzner cloud box with 4 GB of RAM, memory is a real limit, so these differences matter more than they would on a large server.

Disk Size

Run du -sh on a production Node project after the build pipeline has finished.

$ du -sh node_modules/ target/ bin/
584M    node_modules/
15M     bin/api

In this project node_modules weighed over half a gigabyte, with around 1,400 nested packages. Every deployment pulls, unpacks, and audits that.

The Go build produced a single 15 MB static binary with no runtime interpreter, no shared libraries, and no vendor folder deployed to production.

A smaller footprint is a convenience for deployment and idle memory, not a measure of how good the code is.

After Migrating One API

Here is what I saw after migrating a customer API from a PHP-FPM cluster to Go.

I pointed wrk at the endpoints to simulate a rush:

$ wrk -t4 -c200 -d30s http://127.0.0.1:8080/v1/orders
Running 30s test @ http://127.0.0.1:8080/v1/orders
  4 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     2.14ms    1.12ms  18.42ms   84.12%
    Req/Sec     1.24k   182.10     1.62k    71.00%
  148520 requests in 30.04s, 42.18MB read
Requests/sec:   4944.07
Transfer/sec:      1.40MB

Almost 5,000 requests per second on a single machine, with CPU around 4% and memory under 20 MB. That was one endpoint on one machine, so treat it as a rough data point.

PHP is a fine choice for plenty of projects. WordPress still powers a large share of the web, and Laravel is an enjoyable framework to work in. But if idle memory and hosting cost matter on your project, as they did on mine, it is worth measuring your own runtime before deciding whether a rewrite is worth it. For many existing applications, it will not be.

Tell me what you need built

Usually a reply within a day, by email or WhatsApp.