Skip to content
Get started

Performance ​

The machine ​

Every number here comes from one machine. Run the benchmarks on your own hardware before you plan capacity around them.

PartWhat
CPUAMD Ryzen 7 7800X3D
OSWindows with WSL2
RuntimeBun 1.4.x
Messages64 bytes unless it says otherwise
LoadBun load generators on the same machine

WSL2 loopback adds kernel cost, and the load generators eat cores the server could use. A dedicated Linux box would do better on both counts.

Against JavaScript frameworks ​

The framework suite in netifyjs/benchmarks writes each server the usual way for its framework, and the same Bun load generator drives them all over six load processes. Only frameworks are compared. Raw APIs like node:net, ws or Bun.serve don't do framing, routing or connection handling, which puts them in a different category. ZeroMQ runs on Node 24 because its native addon won't load in Bun. Everything else runs on Bun with compression off, and every figure is the median of three runs.

TCP ​

64 clients each keep 32 length framed messages of 64 bytes in flight. When the replies come back, they send the next batch in one write, much like a busy game client sending several updates per tick.

FrameworkRuntimeEcho
NetifyBun2.52M msg/s
ZeroMQNode133k msg/s
gRPCBun134k msg/s
MoleculerBun131k msg/s
NestJSBun108k msg/s

Netify's side is a full pipeline: a length field decoder, a prepender and an echo handler. It handles about 19 times the traffic of ZeroMQ, gRPC and Moleculer, and 23 times NestJS.

WebSocket ​

FrameworkRuntimeEchoRoom broadcast to 1000 clients
NetifyBun1.19M msg/s2.16M deliveries/s
ColyseusBun513k msg/s190k deliveries/s
Socket.IOBun230k msg/s100k deliveries/s

Echo uses 64 clients, each with 32 binary messages of 64 bytes in flight. Broadcast sends 64 byte messages to one room of 1000 clients for three seconds and counts what arrives. Netify publishes to a native topic and Bun fans it out in native code. The others loop over their sockets in JavaScript.

UDP and HTTP ​

Nothing in the same class exists for UDP or plain HTTP to compare against. These are Netify's own figures. UDP echo keeps 32 datagrams of 64 bytes in flight on each of 64 sockets. HTTP keeps 16 pipelined GET / requests in flight on each of 64 keep-alive connections, the same shape as the TechEmpower plaintext test. The server runs HttpServerCodec, HttpObjectAggregator and a handler that checks the method and path.

TestNetify
UDP echo149k msg/s
HTTP plaintext208k req/s

UDP is as fast as Bun allows. A raw Bun.udpSocket server that batches its replies the same way managed 146k msg/s on the same load.

Running it ​

sh
git clone https://github.com/netifyjs/benchmarks
cd benchmarks
bun install
BENCH_LOADS=6 bun run frameworks

The README there shows how to run them against a local copy of Netify.

Pass tcp, udp, http, websocket, tcpcores, httpcores or websocketcores to run one group, or a list like tcp/netify,tcp/nestjs to pick servers. The suite also runs raw API servers such as node:net and Bun.listen, handy for measuring Netify's own overhead but left out of the tables here. BENCH_RUNS sets the runs behind each median (3 by default). NODE_BIN points the Node servers at a different node from the one on your path. Results go to frameworks/results.json, which the home page of this site reads at build time.

Across cores ​

Netify on 4 processes sharing one port with Cluster. Ten load processes drive 160 connections to give the extra cores work.

Test1 core4 cores
TCP echo2.52M msg/s7.14M msg/s
UDP echo149k msg/s740k msg/s
HTTP plaintext208k req/s681k req/s
WebSocket echo1.19M msg/s1.65M msg/s

The load generators share the machine with the server, which is why 4 cores give about three times one core for TCP and HTTP. WebSocket gains less because its clients cost more to run, and on this machine they run out of steam first. UDP runs one port per worker, since Bun's UDP socket can't share a port between processes. The load spreads its sockets over the four ports.

Between shards ​

Two shards on one machine, linked by ShardLink over Unix sockets.

TestResult
Messages, one wayAbout 3M/s
Requests with many in flightAbout 470k/s
One request waiting on its replyAbout 95 µs

Most of that throughput comes from batching. Messages sent in the same tick go out as one frame per shard.

Threads and offloading ​

SetupResult
4 WorkerGroup threads, framedAbout 6% behind 4 processes
200 µs of work per message, inline4.9k/s
Same, OffloadHandler on 4 workers18.2k/s
Same, on 8 workers36.4k/s

Worker threads explains both setups and when each one fits.

WebSocket ​

Netify's two WebSocket modes side by side, from the websocket benchmark. It drives one server with a lighter load than the framework suite.

ServerEcho
Netify WebSocketBootstrap (native)About 1M/s
Netify JavaScript codec on ServerBootstrapAbout 0.93M/s

Broadcasting to a room of 1000 sockets, native topics reached about 1.45M deliveries a second. A ChannelGroup loop over the JavaScript codec reached 73k. Anything that fans out to browsers should use topics.

Reliable UDP ​

TestResult
One process, no lossAbout 1.05M/s
One process, 5% simulated lossAbout 390k to 590k/s
Median round trip17 µs
One process, encryptedAbout 755k/s
4000 peers at 30 Hz, load in other processesAbout 107k/s on about one core

In the 4000 peer run, each echoed message cost 8.8 µs of CPU, about half of it in the kernel.

Game ticks ​

The mmo benchmark runs 5000 TCP players in zones of 50 at 20 Hz. Every tick builds a snapshot per zone and sends it with broadcastSync.

ShardsMedian tick
143 to 50 ms
47 to 23 ms

A 20 Hz tick gets 50 ms. With one shard, about 94% of the time goes on kernel writes, one per player per tick. Faster JavaScript won't fix that. You need more cores, whether that's shards or gateways.

mmo:gateway keeps the world in one process and moves the sockets out to gateways. The clients time each snapshot from the start of the tick until it lands.

PlayersLayoutDelivery, medianDelivery, p99
5000One process36 ms81 ms
5000World and 4 gateways8 ms16 ms
10000One process71 ms156 ms
10000World and 4 gateways16 ms35 ms

With gateways the world only used 5 to 8% of a core.

BENCH_REACH=1 puts each player in their zone and the two either side. Gateways send one write per player per tick however many zones they're in. Before that change, 5000 players with 4 gateways had a delivery p99 of 34 to 40 ms, and now it's about 20 ms. There's more on both layouts in Game servers.

Running the benchmarks ​

They live in netifyjs/benchmarks. Every benchmark runs its server in its own process, away from the load's event loop.

CommandWhat it runs
bun run frameworksNetify against other frameworks over TCP, UDP, WebSocket and HTTP
bun run echoTCP echo: raw Bun, Netify, then Netify framed
bun run microMicro benchmarks for buffers, codecs and the pipeline
bun run clusterThe TCP server on several processes or threads
bun run mmoThe game tick benchmark
bun run mmo:gatewayThe same game with one world and gateway processes
bun run reliableReliable UDP in one process, with and without loss
bun run reliable:scaleMany reliable UDP peers spread over load processes
bun run chaosBots handing off between shards while shards get killed
bun run websocketWebSocket echo: bare Bun, native, and the JavaScript codec
bun run offloadOffloadHandler with 200 µs of work per message

Most take arguments after the script name.

sh
bun run echo raw,netify,framed 64
bun run micro buffer
bun run cluster framed 4 8 processes
bun run cluster framed 4 8 threads
bun run mmo 5000 4
bun run mmo:gateway 5000 4
bun run reliable:scale 4000 30 4
bun run websocket bun,native,netify 4
bun run offload 4
BenchmarkArguments
echoVariants, then message size in bytes
microA pattern to filter benchmarks by name
clusterVariant, workers, load processes, processes or threads
mmoPlayers, shards
mmo:gatewayPlayers, gateways, 0 for one process
reliable:scalePeers, messages a second per peer, load processes
chaosShards, players, ms between kills, 0 for none
websocketVariants, load processes
offloadWorkers, 0 for inline

echo opens 64 connections with 32 messages in flight on each. It warms up for a second, then measures for 5. BENCH_ENCRYPT=1 turns on encryption for reliable:scale.

CPU profiles ​

Set BENCH_PROFILE to a folder and the server runs under Bun's CPU profiler. The profiles land in that folder as Markdown.

sh
BENCH_PROFILE=./profiles bun run echo netify
BENCH_PROFILE=./profiles bun run mmo 5000 1

It works with echo, mmo, websocket and reliable:scale. To profile your own server, point BENCH_SERVER at its script. echo then starts yours in place of the built in one.

Hot paths ​

Each of these rules came out of a profile. Netify's own code sticks to them, and your handlers should too.

Flush once per read batch ​

Every flush is a syscall, and one read from Bun often carries several messages. Queue replies in channelRead and flush them together in channelReadComplete.

ts
import { 
InboundHandlerAdapter
, type
HandlerContext
} from '@netifyjs/netify'
/** * Echoes with one flush per batch * @class */ class
EchoHandler
extends
InboundHandlerAdapter
<unknown> {
/** * Queues the reply * @param context the connection * @param message what came in */ public override
channelRead
(
context
:
HandlerContext
,
message
: unknown): void {
context
.
writeSync
(
message
)
} /** * Sends the batch * @param context the connection */ public override
channelReadComplete
(
context
:
HandlerContext
):
Promise
<void> {
return
context
.
flush
()
} }

If you can't change a handler, FlushConsolidationHandler batches its flushes for you.

Use sync writes ​

write and writeAndFlush create a promise for every message. If nothing's going to await it, use writeSync, writeAndFlushSync or writeAndFlushEncodedSync. Errors still reach exceptionCaught.

Stay synchronous ​

When a handler returns without awaiting, Netify passes the message on without creating a promise. An async method creates one on every call, even if it never awaits anything. Return void where you can. Save async for handlers that do real I/O.

Read sizes without copying ​

Use buffer.readableBytes. It reads a number stored on the buffer, while buffer.toUint8Array().length builds a view first.

Avoid small subarrays ​

A subarray call on Bun takes about 25 to 30 ns. That's longer than allocating a small new Uint8Array, and cutting lots of tiny views off a big array adds up. ByteBuf.readSlice shares memory without calling subarray. readBytes makes a copy.

Fan out once ​

Encode a broadcast once and send the same bytes to everyone. On TCP that's ChannelGroup.broadcastSync, and on native WebSocket topics it's server.publish. Calling writeAndFlush in a loop runs the encoder and creates a promise for every player.

Shard across cores ​

One process uses one core. Clustering gives you more processes and Worker threads more threads. Game servers covers splitting a game world across them.

Released under the MIT licence.