This benchmarks a websocket server intended as a simple but very active chat room.
First, start the server. By default, it will wait for 32 clients which the client script will handle.
Run in Bun (Bun.serve):
bun ./chat-server.bun.jsRun in Node ("ws" package):
node ./chat-server.node.mjsRun in Deno (Deno.serve):
deno run -A ./chat-server.deno.mjsThen, run the client script. By default, it will connect 32 clients. This client script can run in Bun, Node, or Deno
node ./chat-client.mjsThe client script loops through a list of messages for each connected client and sends a message.
For example, when the client sends "foo", the server sends back "John: foo" so that all members of the chatroom receive the message.
The client script waits until it receives all the messages for each client before sending the next batch of messages.
A single client process can become the bottleneck for fast servers. To spread the 32 clients across several processes, start
each one with CLIENTS_COUNT set to its share and TOTAL_CLIENTS set to the total the server was started with, so every
process expects the echoes of all senders:
CLIENTS_COUNT=32 bun ./chat-server.bun.js &
for i in 1 2 3 4; do CLIENTS_COUNT=8 TOTAL_CLIENTS=32 bun ./chat-client.mjs & done; waitThis project was created using bun init in bun v0.2.1. Bun is a fast all-in-one JavaScript runtime.