# API Maker WebSocket benchmark : 2 vCPU, 4 GB RAM (Linode shared CPU)

> API Maker WebSockets on 2 shared vCPUs, 4 GB (Linode) : 338,016 clients connected at once, 8 KB each, 4,041 new clients a second, with memory and outputs.

Source: https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html

<nav class="am-bench-switch" aria-label="WebSocket benchmark servers">
Shared CPU

- [1 vCPU1 GB · 26k clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-1-vcpu-1gb.html)
- [2 vCPU4 GB · 338k clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html)
- [4 vCPU8 GB · 802k clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-4-vcpu-8gb.html)
- [8 vCPU32 GB · 3.66M clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-8-vcpu-32gb.html)

Dedicated CPU

- [2 vCPU4 GB · 338k clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-dedicated-2-vcpu-4gb.html)
- [4 vCPU8 GB · 796k clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-dedicated-4-vcpu-8gb.html)
- [8 vCPU16 GB · 1.73M clients](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-dedicated-8-vcpu-16gb.html)

Compare

- [WebSocketsthe answers](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/index.html)
- [All resultsevery server side by side](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/summary.html)
- [Scale to N usersone server or many](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/scaling.html)

</nav>

WebSocket benchmark · Linode (Akamai Cloud) · Shared CPU · 14 October 2026

**2 vCPU, 4 GB RAM : 338,016 WebSocket clients connected at once.**

API Maker 4.0.0 on a Linode 4 GB (g6-standard-2) : 2 shared vCPUs and 4 GB of RAM at $24 a month, its MongoDB and Redis on the same machine. A second server opened WebSocket clients, each with both tokens and a subscription of its own, until the memory of the server was full, while autocannon made the calls which notify them : every run 60 seconds, the memory and CPU of every part sampled each second.

Clients connected

338,016

the memory was full : 499 MB left

Memory per client

8.5KB

API Maker 3.1 · kernel 4.3 · Redis 1.0

New clients / second

4,041

both tokens and a subscription · 9,504 without one

Notification delivered in

1.45ms

p50 at 1,000 a second · p99 3.15 ms

## The server

| | |
|---|---|
| Server | Linode (Akamai Cloud), Linode 4 GB (g6-standard-2), shared cpu, $24 / month |
| CPU | AMD EPYC 7642 48-Core Processor, 2 shared vCPUs (KVM)<br>KVM guest, 1 thread per core · L1d 128 KiB (2 instances) · L2 1 MiB (2 instances) · L3 32 MiB (2 instances) · BogoMIPS 4599.99 |
| Memory | 4 GB (3,915 MB usable), swap 4.3 GB (496 MB of Linode + 3.8 GB made by the installer) |
| Disk, region | 80 GB SSD, Mumbai, India (ap-west) |
| System | Ubuntu 24.04.4 LTS, Linux 6.8.0-134, Docker 29.9.0 |
| API Maker | 4.0.0 : release build of api_maker_be_rust 423a34c with the new WebSocket core of 14 October 2026 (opt-level 3, fat LTO), installed by its installer (https://apimaker.dev/v4/install.sh), no reverse proxy |
| Settings | the defaults of the installer : one worker thread per vCPU, up to 1,048,576 open files for the service (`LimitNOFILE`), and the sandboxes kept running for the whole run (removeSandboxInactiveSinceMinutes 1440) |
| Network limits | as the installer sets them : 1,002,240 connections tracked by the firewall of Linux (`net.netfilter.nf_conntrack_max`), 16,384 waiting to be accepted (`net.core.somaxconn`). The memory of all its TCP connections together : raised by API Maker as the clients came, to 979 MB at the most (`net.ipv4.tcp_mem`, 25 % of the memory ; Linux gives 9 %) |
| Databases | MongoDB 8.0.10 (the MongoDB of API Maker, a replica set of one member, in Docker) · Redis 7.0.5 (the Redis of API Maker, in Docker) : on the same server. No other database runs |
| Sandboxes | TypeScript on Node.js 24.21.0 (an image of 404 MB built by API Maker), 2 sandboxes of the account (sandboxCountForAdmin 2, the default) |
| Load generator | Dedicated 8 GB (g6-dedicated-4) : AMD EPYC 7642 48-Core Processor, 4 dedicated vCPUs, Ubuntu 24.04.4 LTS. The WebSocket clients : am_ws_load, a program in Rust made for these benchmarks, a socket and a task per client, from 21 addresses of the load generator. The HTTP calls : Node.js 24.21.0, autocannon 8.0.0 |
| Network | A VLAN of the same data centre, round trip 0.35 ms (ping) |
| Date | 14 October 2026, 03:17 to 03:54 UTC |

Only what the run needs was running : API Maker and its two sandboxes, its MongoDB and its Redis. API Maker was restarted and the swap emptied before the run. How every number was taken : [How the WebSocket benchmarks are made](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/methodology.html). Every server side by side : [All results](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/summary.html). The APIs of this server : [2 vCPU · 4 GB, API benchmark](https://docs.apimaker.dev/v4/docs/benchmarks/linode-shared-2-vcpu-4gb.html).

## The data

- **The clients** connect to `ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>` : the token of an API user, and the token of a person, a row of the `customers` table of the [benchmark dataset](https://apimaker.dev/json/benchmark_dataset.json) (`https://apimaker.dev/json/benchmark_dataset.json`) made by a DB token generator. API Maker checks both.
- **A subscription** is one `REGISTER` for the custom WebSocket event `order-updates` with a condition of its own : `{ conditionType: 'RESPONSE', criteria: { recipientId: '<the number of the client>' } }`. It is the way [one notification reaches one person](https://docs.apimaker.dev/v4/docs/pages/web-socket-event-page.html).
- **A notification** for one person is 141 bytes ; a row of the dataset told to the clients of a table is 321 bytes.
- **The tables** are the ones of the [API benchmarks](https://docs.apimaker.dev/v4/docs/benchmarks/methodology.html#the-data), in MongoDB : ten rows of customers, ten columns each.

## Results at a glance

**New clients per second**

[Connect : the token of the API user](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#connect-1-token) · 9,799

[Connect : both tokens](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#connect-2-tokens) · 9,504

[Connect with both tokens and subscribe](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#subscribe) · 4,041

[Subscribe to an event with a can user connect code](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#can-user-connect) · the code ran in the server · 3,438

[Subscribe : the code reads the database](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#can-user-connect-database) · the code ran in the sandbox · 1,605

[Subscribe : the code reads the clock](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#can-user-connect-sandbox) · the code ran in the sandbox · 3,031

100 clients at a time connect, are let in and leave, for 60 seconds.

**Notifications per second**

[A notification for one person](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#one-person) · 7,657 calls / second · 7,562

[A broadcast](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#broadcast) · 105 calls / second · 103,387

[Rows inserted in a table](https://docs.apimaker.dev/v4/docs/benchmarks/websockets/linode-shared-2-vcpu-4gb.html#insert) · 604 calls / second · 59,275

As many calls as the server takes : what the clients received each second.

## How many clients fit

Clients connect 2,000 a second, level after level, each with both tokens and a subscription of its own ; at each level they wait 30 seconds while the server is sampled (the level the run stops at, 60). The run stopped adding clients at **338,016** : the memory of the server was full. 446 MB of its 3,916 MB were still counted as available, and Linux had moved 282 MB to the swap since the clients began to connect, to make that room : 164 MB were left (the run stops when what is available, less what Linux moved to the swap since the clients began to connect, is under 5 % of the memory of the server).

> Diagram : Clients connected and memory used during the run
>
> The run of this server, second after second : the WebSocket clients connected, up to 338,016, and the memory the server used, up to 3,463 MB of 3,915 MB.

API Maker · MongoDB of API Maker · Redis · Sandboxes · Linux : its sockets, Docker, the rest · Available

No client

at rest

10,000 clients

connected

25,000 clients

connected

50,000 clients

connected

100,000 clients

connected

150,000 clients

connected

200,000 clients

connected

250,000 clients

connected

300,000 clients

connected

338,016 clients

connected

| Clients | API Maker | Redis | Kernel | MongoDB | Sandboxes | Server, used | Available | Swap | CPU busy |
|---|--:|--:|--:|--:|--:|--:|--:|--:|--:|
| None (at rest) | 110 | 1 | 201 | 123 | 51 | **802** | 3,114 | 0 | 1.4 % |
| **10,000** | 149 | 12 | 270 | 157 | 246 | **1,124** | 2,792 | 0 | 1.3 % |
| **25,000** | 202 | 27 | 310 | 195 | 246 | **1,275** | 2,641 | 0 | 1.4 % |
| **50,000** | 275 | 52 | 412 | 192 | 246 | **1,462** | 2,454 | 0 | 2.1 % |
| **100,000** | 437 | 102 | 626 | 192 | 246 | **1,866** | 2,050 | 0 | 2.6 % |
| **150,000** | 599 | 157 | 838 | 192 | 246 | **2,267** | 1,649 | 0 | 3.7 % |
| **200,000** | 751 | 204 | 1,049 | 192 | 246 | **2,652** | 1,264 | 0 | 6.8 % |
| **250,000** | 892 | 250 | 1,264 | 191 | 246 | **3,030** | 886 | 0 | 8.5 % |
| **300,000** | 1,020 | 313 | 1,473 | 170 | 183 | **3,333** | 583 | 118 | 9.5 % |
| **338,016** | 1,110 | 347 | 1,635 | 117 | 91 | **3,417** | 499 | 310 | 9.7 % |

Memory in MB. API Maker is the resident memory of its process ; Redis is the memory of its data (`used_memory`) ; the kernel of Linux keeps every socket and every tracked connection in its slab ; a container is counted the way `docker stats` counts it. CPU busy is the whole server while the clients wait : the server pings every client once a minute, and each answers.

### Memory when the server is full

With **338,016 clients** connected and waiting, of the 3,916 MB of the server :

| Part | At rest, no client | 338,016 clients | More |
|---|--:|--:|--:|
| **API Maker** (process) | 110 MB | **1,110 MB** | + 1,000 MB |
| Redis (container) | 3 MB | **356 MB** | + 353 MB |
| Linux kernel : sockets, tracked connections (slab) | 201 MB | **1,635 MB** | + 1,434 MB |
| MongoDB of API Maker (container) | 123 MB | **117 MB** | − 6 MB |
| Sandboxes (2 containers) | 51 MB | **91 MB** | + 41 MB |
| **Whole server**, used | 802 MB | **3,417 MB** | + 2,615 MB |
| Available | 3,114 MB | **499 MB** | |
| Swap used | 0 MB | **310 MB** | |
| Open files of API Maker | 28 | **338,044** | |
| Keys of Redis · channels it listens on | 13 · 5 | **676,048 · 338,021** | |

MongoDB and the sandboxes grew during the runs before this one (the inserts, the code of the events), not with the clients.

### What a client costs

Between 100,000 and 250,000 clients (4 levels), each client more cost the server **8.5 KB** :

| Where | Per client | What it is |
|---|--:|---|
| **API Maker** | **3.1 KB** | The client itself : its socket and the one task which reads it, its tokens and what they said, its subscription and the channel it is told on. |
| Linux kernel | 4.3 KB | The TCP socket, and the entry of the connection in the table of the firewall (Docker makes Linux track every connection). |
| Redis | 1.0 KB | The subscription : its key, its place in the list of its condition, and the channel API Maker listens on. |
| **In all** | **8.5 KB** | 123,507 clients per GB of memory. |

Measured over the levels at which nothing was in the swap. The memory the whole server had available went down by 7.9 KB per client : MongoDB, the sandboxes and the cache of files give some back while the clients take theirs.

## One more subscription, and a broadcast to everybody

With 50,000 clients connected, every client sent a second `REGISTER`, for an event without a condition (`announcements`), 2,000 of them a second : 50,000 were taken in 25.0 s. They waited 30 seconds with two subscriptions each, were told 3 broadcasts, one call of the emit event WS API each, and took the subscription back with `UNREGISTER`.

One subscription more

1.2KB

per client : API Maker 0.5 KB · Redis 0.8 KB

A broadcast to 50k clients

0.57s

until the last client read it

Half of them told after

363ms

the first after 157 ms

Clients told / second

87,821

one call, every client

| Broadcast | Clients told | The call answered after | The first client | Half of them | 99 % of them | The last one | Clients told a second |
|---|--:|--:|--:|--:|--:|--:|--:|
| 1 | 50,000 of 50,000 | 0.77 s | 192 ms | 466 ms | 761 ms | **766 ms** | 65,278 |
| 2 | 50,000 of 50,000 | 0.72 s | 167 ms | 424 ms | 715 ms | **721 ms** | 69,309 |
| 3 | 50,000 of 50,000 | 0.57 s | 157 ms | 363 ms | 565 ms | **569 ms** | 87,821 |

One call of the emit event WS API tells every client : API Maker asks Redis for the clients of the event, publishes the notification for each of them, and the server which holds a client sends it. The times are counted from the moment the call is written to the moment a client reads its notification.

| Memory, 50,000 clients | One subscription each | Two subscriptions each | A subscription more, per client |
|---|--:|--:|--:|
| API Maker | 275 MB | 297 MB | 0.5 KB |
| Redis (its data) | 52 MB | 88 MB | 0.8 KB |
| Keys of Redis · channels | 100,016 · 50,005 | 150,017 · 100,005 | |
| **Whole server**, less available | | | **1.2 KB** |

## New clients per second

How many clients a second the server lets in : 100 clients at a time connect, are let in and leave, one after the other, for 60 seconds (after 5 seconds which are not counted). It is what a server faces when its clients all come back, after a deployment or a network cut. The times are counted from the start of the TCP connection.

### Connect : the token of the API user

A client connects with `x-am-authorization` alone, is told `CONNECTED`, and leaves. API Maker checks the token of the API user and finds its groups : what every WebSocket client costs before it asks for anything.

Clients / second

9,799

588,525 clients in 60 s, 100 at a time

Let in after, p50

5.59ms

connected 5.59 ms · TCP 0.22 ms

Let in after, p99

10.8ms

max 26.7 ms

Refused or lost

0

not connected, not subscribed, no answer

(Server during this run) API Maker **1.9 vCPU** · whole server busy **99 %** · load generator busy **66 %**

am_ws_load · Connect : the token of the API user · 60 s

```text
$ am_ws_load churn -c 100 -d 60 "ws://<server>:38246/?x-am-authorization=<token>"
Running 60s test @ ws://<server>:38246
100 clients at a time : connect, CONNECTED, leave

┌─────────────┬─────────┬──────────┬──────────┬──────────┬──────────┬─────────┬──────────┐
│ Stat        │ 2.5%    │ 50%      │ 97.5%    │ 99%      │ Avg      │ Stdev   │ Max      │
├─────────────┼─────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ TCP connect │ 0.15 ms │ 0.22 ms  │ 0.58 ms  │ 0.99 ms  │ 0.25 ms  │ 0.21 ms │ 9.82 ms  │
├─────────────┼─────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ CONNECTED   │ 1.87 ms │ 5.59 ms  │ 9.81 ms  │ 10.8 ms  │ 5.6 ms   │ 2.11 ms │ 26.72 ms │
├─────────────┼─────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ Left        │ 5.58 ms │ 10.06 ms │ 15.62 ms │ 17.01 ms │ 10.18 ms │ 2.63 ms │ 39.81 ms │
└─────────────┴─────────┴──────────┴──────────┴──────────┴──────────┴─────────┴──────────┘
┌─────────────┬───────┬───────┬───────┬────────┬─────────┬────────┬───────┐
│ Stat        │ 1%    │ 2.5%  │ 50%   │ 97.5%  │ Avg     │ Stdev  │ Min   │
├─────────────┼───────┼───────┼───────┼────────┼─────────┼────────┼───────┤
│ Clients/Sec │ 7,743 │ 8,580 │ 9,809 │ 10,840 │ 9,808.8 │ 602.66 │ 7,743 │
└─────────────┴───────┴───────┴───────┴────────┴─────────┴────────┴───────┘

Time from the start of the connection to each step. Clients counted once per second.
# of samples: 60

589k clients let in in 60.06s, 0 refused or lost
```

### Connect : both tokens

A client connects with `x-am-authorization` and `x-am-user-authorization`, is told `CONNECTED`, and leaves. Both tokens are checked : the one of the API user, and the one of a person, made by the DB token generator of the account.

Clients / second

9,504

570,797 clients in 60 s, 100 at a time

Let in after, p50

5.77ms

connected 5.77 ms · TCP 0.24 ms

Let in after, p99

11.4ms

max 27.5 ms

Refused or lost

0

not connected, not subscribed, no answer

(Server during this run) API Maker **1.9 vCPU** · whole server busy **99 %** · load generator busy **62 %**

am_ws_load · Connect : both tokens · 60 s

```text
$ am_ws_load churn -c 100 -d 60 "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
Running 60s test @ ws://<server>:38246
100 clients at a time : connect, CONNECTED, leave

┌─────────────┬─────────┬──────────┬──────────┬──────────┬──────────┬─────────┬──────────┐
│ Stat        │ 2.5%    │ 50%      │ 97.5%    │ 99%      │ Avg      │ Stdev   │ Max      │
├─────────────┼─────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ TCP connect │ 0.16 ms │ 0.24 ms  │ 1.01 ms  │ 1.38 ms  │ 0.32 ms  │ 0.29 ms │ 15.18 ms │
├─────────────┼─────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ CONNECTED   │ 1.93 ms │ 5.77 ms  │ 10.42 ms │ 11.44 ms │ 5.84 ms  │ 2.24 ms │ 27.5 ms  │
├─────────────┼─────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ Left        │ 5.59 ms │ 10.29 ms │ 16.56 ms │ 17.94 ms │ 10.49 ms │ 2.83 ms │ 36.1 ms  │
└─────────────┴─────────┴──────────┴──────────┴──────────┴──────────┴─────────┴──────────┘
┌─────────────┬───────┬───────┬────────┬────────┬─────────┬────────┬───────┐
│ Stat        │ 1%    │ 2.5%  │ 50%    │ 97.5%  │ Avg     │ Stdev  │ Min   │
├─────────────┼───────┼───────┼────────┼────────┼─────────┼────────┼───────┤
│ Clients/Sec │ 7,633 │ 7,780 │ 10,036 │ 10,775 │ 9,513.3 │ 945.61 │ 7,633 │
└─────────────┴───────┴───────┴────────┴────────┴─────────┴────────┴───────┘

Time from the start of the connection to each step. Clients counted once per second.
# of samples: 60

571k clients let in in 60.06s, 0 refused or lost
```

### Connect with both tokens and subscribe

The whole of what an application does : connect with both tokens, `CONNECTED`, one `REGISTER` for a custom WebSocket event with a condition of its own (`recipientId` : its user id), the answer, then leave. API Maker checks the groups and the auth provider of the event, keeps the subscription in Redis and listens on its channel ; when the client leaves, all of it is taken back.

Clients / second

4,041

242,684 clients in 60 s, 100 at a time

Let in after, p50

21.5ms

connected 4.80 ms · TCP 0.21 ms

Let in after, p99

31.2ms

max 54.1 ms

Refused or lost

0

not connected, not subscribed, no answer

(Server during this run) API Maker **1.5 vCPU** · Redis **0.2 vCPU** · whole server busy **100 %** · load generator busy **37 %**

am_ws_load · Connect with both tokens and subscribe · 60 s

```text
$ am_ws_load churn -c 100 -d 60 "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>" --register 'order-updates'
Running 60s test @ ws://<server>:38246
100 clients at a time : connect, CONNECTED, REGISTER, leave

┌─────────────┬──────────┬──────────┬──────────┬──────────┬──────────┬─────────┬──────────┐
│ Stat        │ 2.5%     │ 50%      │ 97.5%    │ 99%      │ Avg      │ Stdev   │ Max      │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ TCP connect │ 0.15 ms  │ 0.21 ms  │ 0.37 ms  │ 0.53 ms  │ 0.23 ms  │ 0.17 ms │ 9.45 ms  │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ CONNECTED   │ 1.56 ms  │ 4.8 ms   │ 9.02 ms  │ 10.02 ms │ 4.93 ms  │ 1.95 ms │ 24.85 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ REGISTER    │ 13.98 ms │ 21.47 ms │ 29.3 ms  │ 31.2 ms  │ 21.51 ms │ 3.86 ms │ 54.14 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ Left        │ 16.94 ms │ 24.59 ms │ 33.25 ms │ 35.42 ms │ 24.73 ms │ 4.13 ms │ 64.22 ms │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┴─────────┴──────────┘
┌─────────────┬───────┬───────┬───────┬───────┬─────────┬────────┬───────┐
│ Stat        │ 1%    │ 2.5%  │ 50%   │ 97.5% │ Avg     │ Stdev  │ Min   │
├─────────────┼───────┼───────┼───────┼───────┼─────────┼────────┼───────┤
│ Clients/Sec │ 3,652 │ 3,657 │ 4,075 │ 4,381 │ 4,044.7 │ 195.87 │ 3,652 │
└─────────────┴───────┴───────┴───────┴───────┴─────────┴────────┴───────┘

Time from the start of the connection to each step. Clients counted once per second.
# of samples: 60

243k clients let in in 60.06s, 0 refused or lost
```

### Subscribe to an event with a can user connect code

The same, on an event whose *can user connect code* decides who may subscribe : it reads the person of `x-am-user-authorization` from `g.req.auth`. The code ran in the server itself (lean code, QuickJS).

Clients / second

3,438

206,487 clients in 60 s, 100 at a time

Let in after, p50

25.3ms

connected 5.38 ms · TCP 0.21 ms

Let in after, p99

37.0ms

max 52.7 ms

Refused or lost

0

not connected, not subscribed, no answer

(Server during this run) API Maker **1.5 vCPU** · Redis **0.2 vCPU** · whole server busy **100 %** · load generator busy **33 %**

am_ws_load · Subscribe to an event with a can user connect code · 60 s

```text
$ am_ws_load churn -c 100 -d 60 "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>" --register 'checked-token'
Running 60s test @ ws://<server>:38246
100 clients at a time : connect, CONNECTED, REGISTER, leave

┌─────────────┬──────────┬──────────┬──────────┬──────────┬──────────┬─────────┬──────────┐
│ Stat        │ 2.5%     │ 50%      │ 97.5%    │ 99%      │ Avg      │ Stdev   │ Max      │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ TCP connect │ 0.15 ms  │ 0.21 ms  │ 0.39 ms  │ 0.63 ms  │ 0.23 ms  │ 0.18 ms │ 11.8 ms  │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ CONNECTED   │ 1.72 ms  │ 5.38 ms  │ 10.26 ms │ 11.5 ms  │ 5.53 ms  │ 2.22 ms │ 22.75 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ REGISTER    │ 16.48 ms │ 25.25 ms │ 34.82 ms │ 36.99 ms │ 25.34 ms │ 4.58 ms │ 52.7 ms  │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ Left        │ 20 ms    │ 28.86 ms │ 39.2 ms  │ 41.73 ms │ 29.07 ms │ 4.85 ms │ 61.6 ms  │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┴─────────┴──────────┘
┌─────────────┬───────┬───────┬───────┬───────┬─────────┬────────┬───────┐
│ Stat        │ 1%    │ 2.5%  │ 50%   │ 97.5% │ Avg     │ Stdev  │ Min   │
├─────────────┼───────┼───────┼───────┼───────┼─────────┼────────┼───────┤
│ Clients/Sec │ 3,048 │ 3,079 │ 3,461 │ 3,684 │ 3,441.4 │ 167.20 │ 3,048 │
└─────────────┴───────┴───────┴───────┴───────┴─────────┴────────┴───────┘

Time from the start of the connection to each step. Clients counted once per second.
# of samples: 60

206k clients let in in 60.06s, 0 refused or lost
```

### Subscribe : the code reads the database

The same, with a can user connect code which also reads the person from the database (`g.sys.db.getAll` with a `find`) before it answers : one read of MongoDB for every subscription. The code ran in a sandbox of the account.

Clients / second

1,605

96,421 clients in 60 s, 100 at a time

Let in after, p50

56.5ms

connected 8.26 ms · TCP 0.21 ms

Let in after, p99

82.7ms

max 124 ms

Refused or lost

0

not connected, not subscribed, no answer

(Server during this run) API Maker **0.7 vCPU** · Redis **0.1 vCPU** · MongoDB **0.4 vCPU** · sandboxes **0.7 vCPU** · whole server busy **100 %** · load generator busy **17 %**

am_ws_load · Subscribe : the code reads the database · 60 s

```text
$ am_ws_load churn -c 100 -d 60 "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>" --register 'checked-database'
Running 60s test @ ws://<server>:38246
100 clients at a time : connect, CONNECTED, REGISTER, leave

┌─────────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬───────────┐
│ Stat        │ 2.5%     │ 50%      │ 97.5%    │ 99%      │ Avg      │ Stdev    │ Max       │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼───────────┤
│ TCP connect │ 0.16 ms  │ 0.21 ms  │ 0.34 ms  │ 0.4 ms   │ 0.22 ms  │ 0.09 ms  │ 6.67 ms   │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼───────────┤
│ CONNECTED   │ 2.5 ms   │ 8.26 ms  │ 15.96 ms │ 17.52 ms │ 8.5 ms   │ 3.47 ms  │ 27.34 ms  │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼───────────┤
│ REGISTER    │ 38.82 ms │ 56.45 ms │ 77.44 ms │ 82.69 ms │ 56.83 ms │ 9.79 ms  │ 123.78 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼───────────┤
│ Left        │ 43.81 ms │ 61.82 ms │ 83.65 ms │ 89.28 ms │ 62.28 ms │ 10.09 ms │ 131.84 ms │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴───────────┘
┌─────────────┬───────┬───────┬───────┬───────┬─────────┬───────┬───────┐
│ Stat        │ 1%    │ 2.5%  │ 50%   │ 97.5% │ Avg     │ Stdev │ Min   │
├─────────────┼───────┼───────┼───────┼───────┼─────────┼───────┼───────┤
│ Clients/Sec │ 1,322 │ 1,429 │ 1,620 │ 1,690 │ 1,607.0 │ 60.82 │ 1,322 │
└─────────────┴───────┴───────┴───────┴───────┴─────────┴───────┴───────┘

Time from the start of the connection to each step. Clients counted once per second.
# of samples: 60

96k clients let in in 60.06s, 0 refused or lost
```

### Subscribe : the code reads the clock

The same, with a can user connect code which reads the time of the machine (`Date.now()`) : code which is not lean, so API Maker runs it in a sandbox of the account. The code ran in a sandbox of the account.

Clients / second

3,031

182,012 clients in 60 s, 100 at a time

Let in after, p50

29.6ms

connected 5.06 ms · TCP 0.21 ms

Let in after, p99

42.7ms

max 59.9 ms

Refused or lost

0

not connected, not subscribed, no answer

(Server during this run) API Maker **1.3 vCPU** · Redis **0.2 vCPU** · sandboxes **0.3 vCPU** · whole server busy **100 %** · load generator busy **31 %**

am_ws_load · Subscribe : the code reads the clock · 60 s

```text
$ am_ws_load churn -c 100 -d 60 "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>" --register 'checked-sandbox'
Running 60s test @ ws://<server>:38246
100 clients at a time : connect, CONNECTED, REGISTER, leave

┌─────────────┬──────────┬──────────┬──────────┬──────────┬──────────┬─────────┬──────────┐
│ Stat        │ 2.5%     │ 50%      │ 97.5%    │ 99%      │ Avg      │ Stdev   │ Max      │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ TCP connect │ 0.15 ms  │ 0.21 ms  │ 0.36 ms  │ 0.47 ms  │ 0.23 ms  │ 0.14 ms │ 10.56 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ CONNECTED   │ 1.75 ms  │ 5.06 ms  │ 9.31 ms  │ 10.31 ms │ 5.18 ms  │ 1.95 ms │ 22.29 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ REGISTER    │ 19.52 ms │ 29.62 ms │ 40.26 ms │ 42.69 ms │ 29.67 ms │ 5.26 ms │ 59.87 ms │
├─────────────┼──────────┼──────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
│ Left        │ 22.5 ms  │ 32.86 ms │ 44.13 ms │ 46.66 ms │ 32.97 ms │ 5.49 ms │ 63.62 ms │
└─────────────┴──────────┴──────────┴──────────┴──────────┴──────────┴─────────┴──────────┘
┌─────────────┬───────┬───────┬───────┬───────┬─────────┬────────┬───────┐
│ Stat        │ 1%    │ 2.5%  │ 50%   │ 97.5% │ Avg     │ Stdev  │ Min   │
├─────────────┼───────┼───────┼───────┼───────┼─────────┼────────┼───────┤
│ Clients/Sec │ 2,670 │ 2,687 │ 2,996 │ 3,608 │ 3,033.5 │ 211.32 │ 2,670 │
└─────────────┴───────┴───────┴───────┴───────┴─────────┴────────┴───────┘

Time from the start of the connection to each step. Clients counted once per second.
# of samples: 60

182k clients let in in 60.06s, 0 refused or lost
```

## Can user connect code

An event of the WebSocket Events page can carry a *can user connect code* : API Maker runs it for every subscription to the event, with the tokens of the client in `g.req.auth` and the subscription in `g.req.eventData`, and lets the client subscribe when it returns `{ canConnect: true }`. Three codes were measured : one which reads the person of the token, one which also reads the database, one which reads the clock.

**Reads the person of the token**

**Can user connect code of the event checked-token : ran in the server**

```typescript
import * as T from 'types';

async function main(g: T.IAMGlobal) {
    // The person of x-am-user-authorization : only somebody who signed in subscribes, from a country we serve.
    const person = g.req.auth.authAMDB;
    if (!person) return { canConnect: false, errorText: 'Sign in first.' };
    return { canConnect: person.country === 'India', errorText: 'Not available in your country.' };
};
module.exports = main;
```

**Reads the database**

**Can user connect code of the event checked-database : ran in the sandbox**

```typescript
import * as T from 'types';

async function main(g: T.IAMGlobal) {
    const person = g.req.auth.authAMDB;
    if (!person) return { canConnect: false, errorText: 'Sign in first.' };
    // Still a customer ? One read of the database for every subscription.
    const rows = await g.sys.db.getAll({ instance: 'mongodb', database: 'am_bench', collection: 'customers', queryParams: { find: { customer_id: person.customer_id } } });
    return { canConnect: rows.length === 1 && rows[0].country === 'India', errorText: 'Not a customer any more.' };
};
module.exports = main;
```

**Reads the clock**

**Can user connect code of the event checked-sandbox : ran in the sandbox**

```typescript
import * as T from 'types';

async function main(g: T.IAMGlobal) {
    const person = g.req.auth.authAMDB;
    if (!person) return { canConnect: false, errorText: 'Sign in first.' };
    // The time of the machine : this code runs in the sandbox of the account.
    const hour = new Date(Date.now()).getUTCHours();
    return { canConnect: person.country === 'India' && hour >= 0, errorText: 'Not available in your country.' };
};
module.exports = main;
```

| Can user connect code | Runs in | Clients / second | Subscribed after, p50 | p99 | Against no code |
|---|---|--:|--:|--:|--:|
| No code | – | **4,041** | 21.5 ms | 31.2 ms | – |
| Reads the person of the token | the server (QuickJS) | **3,438** | 25.3 ms | 37.0 ms | 15 % fewer |
| Reads the person from the database | a sandbox of the account | **1,605** | 56.5 ms | 82.7 ms | 60 % fewer |
| Reads the clock | a sandbox of the account | **3,031** | 29.6 ms | 42.7 ms | 25 % fewer |

Lean code (it only reads what it is handed) runs in the server itself, with QuickJS, on the thread which serves the client. Code which needs more runs in a sandbox of the account : every subscription is then a round trip to the sandbox.

## Notifications

With 10,000 clients connected, autocannon makes the HTTP calls which notify them, for 60 seconds, and the clients count what they receive and how late. Each kind of notification is measured twice : at a pace far under what the server takes, which shows how long a notification takes, and with no pace, which shows how many a second the server tells. *Delivery* is the time from the moment autocannon writes the request to the moment the client reads the notification : the HTTP call, API Maker, Redis, and the WebSocket.

### A notification for one person

autocannon calls the [emit event WS API](https://docs.apimaker.dev/v4/docs/apis-all/system-apis/system-generated-emit-event-ws-api.html) with both tokens ; every call names another one of the 10,000 connected clients (`recipientId`), which is the only one told. The clients measure how long each notification took from the moment its request was written.

**1,000 calls a second**

Calls / second (paced)

1,000

60,000 calls in 60 s, 10 connections

Notifications / second

991

60,010 received by 10,000 clients

Delivery p50

1.45ms

average 1.52 ms

Delivery p99

3.15ms

max 6.24 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **0.2 vCPU** · Redis **0.0 vCPU** · whole server busy **15 %** · load generator busy **13 %**

    autocannon · A notification for one person, 1,000 a second

    ```text
    $ autocannon -c 10 -d 60 -R 1000 -l -m POST -b '{"name":"order-updates","eventData":{"recipientId":"<id of a client>","t":<now>,"type":"order-updated","order_no":1001,"status":"SHIPPED"}}' -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" -H "content-type: application/json" "http://<server>:38246/api/system-api/bench/emit-event-ws"
    Running 60s test @ http://<server>:38246/api/system-api/bench/emit-event-ws
    10 connections

    ┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬──────┐
    │ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max  │
    ├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼──────┤
    │ Latency │ 0 ms │ 1 ms │ 2 ms  │ 3 ms │ 1.18 ms │ 0.51 ms │ 6 ms │
    └─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴──────┘
    ┌───────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
    │ Stat      │ 1%     │ 2.5%   │ 50%    │ 97.5%  │ Avg    │ Stdev  │ Min    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
    │ Req/Sec   │ 999    │ 1,000  │ 1,000  │ 1,000  │ 1,000  │ 0.19   │ 999    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
    │ Bytes/Sec │ 357 kB │ 357 kB │ 357 kB │ 357 kB │ 357 kB │ 46.7 B │ 357 kB │
    └───────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 60

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 0            │
    ├────────────┼──────────────┤
    │ 0.01       │ 0            │
    ├────────────┼──────────────┤
    │ 0.1        │ 0            │
    ├────────────┼──────────────┤
    │ 1          │ 0            │
    ├────────────┼──────────────┤
    │ 2.5        │ 0            │
    ├────────────┼──────────────┤
    │ 10         │ 1            │
    ├────────────┼──────────────┤
    │ 25         │ 1            │
    ├────────────┼──────────────┤
    │ 50         │ 1            │
    ├────────────┼──────────────┤
    │ 75         │ 1            │
    ├────────────┼──────────────┤
    │ 90         │ 2            │
    ├────────────┼──────────────┤
    │ 97.5       │ 2            │
    ├────────────┼──────────────┤
    │ 99         │ 3            │
    ├────────────┼──────────────┤
    │ 99.9       │ 4            │
    ├────────────┼──────────────┤
    │ 99.99      │ 5            │
    ├────────────┼──────────────┤
    │ 99.999     │ 6            │
    └────────────┴──────────────┘

    61k requests in 60.06s, 21.4 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    10,000 clients subscribed, 63.57s

    ┌──────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
    │ Stat     │ 2.5%    │ 50%     │ 97.5%   │ 99%     │ Avg     │ Stdev   │ Max     │
    ├──────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
    │ Delivery │ 0.81 ms │ 1.45 ms │ 2.67 ms │ 3.15 ms │ 1.52 ms │ 0.48 ms │ 6.24 ms │
    └──────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
    ┌───────────┬────┬──────┬───────┬───────┬───────┬────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%   │ 97.5% │ Avg   │ Stdev  │ Min │
    ├───────────┼────┼──────┼───────┼───────┼───────┼────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 1,000 │ 1,000 │ 951.8 │ 213.87 │ 0   │
    └───────────┴────┴──────┴───────┴───────┴───────┴────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    60k notifications received in 63.57s (60,010 of 60,000 expected), 10.7 MB read
    ```

**As many as the server takes**

Calls / second

7,657

459,373 calls in 60 s, 100 connections

Notifications / second

7,562

459,473 received by 10,000 clients

Delivery p50

12.9ms

average 12.9 ms

Delivery p99

19.5ms

max 37.9 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **1.6 vCPU** · Redis **0.1 vCPU** · whole server busy **99 %** · load generator busy **44 %**

    autocannon · A notification for one person, as many as the server takes

    ```text
    $ autocannon -c 100 -d 60 -w 4 -l -m POST -b '{"name":"order-updates","eventData":{"recipientId":"<id of a client>","t":<now>,"type":"order-updated","order_no":1001,"status":"SHIPPED"}}' -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" -H "content-type: application/json" "http://<server>:38246/api/system-api/bench/emit-event-ws"
    Running 60s test @ http://<server>:38246/api/system-api/bench/emit-event-ws
    100 connections
    4 workers

    ┌─────────┬──────┬───────┬───────┬───────┬──────────┬─────────┬───────┐
    │ Stat    │ 2.5% │ 50%   │ 97.5% │ 99%   │ Avg      │ Stdev   │ Max   │
    ├─────────┼──────┼───────┼───────┼───────┼──────────┼─────────┼───────┤
    │ Latency │ 8 ms │ 12 ms │ 18 ms │ 19 ms │ 12.52 ms │ 2.55 ms │ 47 ms │
    └─────────┴──────┴───────┴───────┴───────┴──────────┴─────────┴───────┘
    ┌───────────┬─────────┬─────────┬─────────┬────────┬──────────┬────────┬─────────┐
    │ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%  │ Avg      │ Stdev  │ Min     │
    ├───────────┼─────────┼─────────┼─────────┼────────┼──────────┼────────┼─────────┤
    │ Req/Sec   │ 6,543   │ 7,063   │ 7,639   │ 8,131  │ 7,656.74 │ 303.3  │ 6,540   │
    ├───────────┼─────────┼─────────┼─────────┼────────┼──────────┼────────┼─────────┤
    │ Bytes/Sec │ 2.34 MB │ 2.52 MB │ 2.73 MB │ 2.9 MB │ 2.73 MB  │ 108 kB │ 2.33 MB │
    └───────────┴─────────┴─────────┴─────────┴────────┴──────────┴────────┴─────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 240

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 2            │
    ├────────────┼──────────────┤
    │ 0.01       │ 3            │
    ├────────────┼──────────────┤
    │ 0.1        │ 5            │
    ├────────────┼──────────────┤
    │ 1          │ 7            │
    ├────────────┼──────────────┤
    │ 2.5        │ 8            │
    ├────────────┼──────────────┤
    │ 10         │ 9            │
    ├────────────┼──────────────┤
    │ 25         │ 11           │
    ├────────────┼──────────────┤
    │ 50         │ 12           │
    ├────────────┼──────────────┤
    │ 75         │ 14           │
    ├────────────┼──────────────┤
    │ 90         │ 16           │
    ├────────────┼──────────────┤
    │ 97.5       │ 18           │
    ├────────────┼──────────────┤
    │ 99         │ 19           │
    ├────────────┼──────────────┤
    │ 99.9       │ 24           │
    ├────────────┼──────────────┤
    │ 99.99      │ 35           │
    ├────────────┼──────────────┤
    │ 99.999     │ 45           │
    └────────────┴──────────────┘

    459k requests in 60.04s, 164 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    10,000 clients subscribed, 63.77s

    ┌──────────┬─────────┬──────────┬──────────┬──────────┬─────────┬─────────┬──────────┐
    │ Stat     │ 2.5%    │ 50%      │ 97.5%    │ 99%      │ Avg     │ Stdev   │ Max      │
    ├──────────┼─────────┼──────────┼──────────┼──────────┼─────────┼─────────┼──────────┤
    │ Delivery │ 7.99 ms │ 12.87 ms │ 18.08 ms │ 19.49 ms │ 12.9 ms │ 2.51 ms │ 37.92 ms │
    └──────────┴─────────┴──────────┴──────────┴──────────┴─────────┴─────────┴──────────┘
    ┌───────────┬────┬──────┬───────┬───────┬─────────┬─────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%   │ 97.5% │ Avg     │ Stdev   │ Min │
    ├───────────┼────┼──────┼───────┼───────┼─────────┼─────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 7,654 │ 8,278 │ 7,358.7 │ 1435.98 │ 0   │
    └───────────┴────┴──────┴───────┴───────┴─────────┴─────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    459k notifications received in 63.77s (459,473 of 459,373 expected), 82.3 MB read
    ```

### A broadcast

1,000 more clients subscribe to an event without a condition : every call of the emit event WS API reaches all 1,000 of them.

**5 calls a second**

Calls / second (paced)

5

300 calls in 60 s, 1 connection

Notifications / second

4,995

300,000 received by 1,000 clients

Delivery p50

8.82ms

average 9.18 ms

Delivery p99

18.0ms

max 23.5 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **0.1 vCPU** · Redis **0.0 vCPU** · whole server busy **8 %** · load generator busy **10 %**

    autocannon · A broadcast to 1,000 clients, 5 a second

    ```text
    $ autocannon -c 1 -d 60 -R 5 -l -m POST -b '{"name":"announcements","eventData":{"t":<now>,"type":"announcement","text":"Hello from API Maker"}}' -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" -H "content-type: application/json" "http://<server>:38246/api/system-api/bench/emit-event-ws"
    Running 60s test @ http://<server>:38246/api/system-api/bench/emit-event-ws
    1 connections

    ┌─────────┬──────┬──────┬───────┬───────┬─────────┬─────────┬───────┐
    │ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%   │ Avg     │ Stdev   │ Max   │
    ├─────────┼──────┼──────┼───────┼───────┼─────────┼─────────┼───────┤
    │ Latency │ 1 ms │ 8 ms │ 17 ms │ 19 ms │ 8.09 ms │ 4.64 ms │ 23 ms │
    └─────────┴──────┴──────┴───────┴───────┴─────────┴─────────┴───────┘
    ┌───────────┬────────┬────────┬────────┬────────┬────────┬───────┬────────┐
    │ Stat      │ 1%     │ 2.5%   │ 50%    │ 97.5%  │ Avg    │ Stdev │ Min    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼───────┼────────┤
    │ Req/Sec   │ 5      │ 5      │ 5      │ 5      │ 5      │ 0     │ 5      │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼───────┼────────┤
    │ Bytes/Sec │ 1.8 kB │ 1.8 kB │ 1.8 kB │ 1.8 kB │ 1.8 kB │ 0 B   │ 1.8 kB │
    └───────────┴────────┴────────┴────────┴────────┴────────┴───────┴────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 60

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 1            │
    ├────────────┼──────────────┤
    │ 0.01       │ 1            │
    ├────────────┼──────────────┤
    │ 0.1        │ 1            │
    ├────────────┼──────────────┤
    │ 1          │ 1            │
    ├────────────┼──────────────┤
    │ 2.5        │ 1            │
    ├────────────┼──────────────┤
    │ 10         │ 2            │
    ├────────────┼──────────────┤
    │ 25         │ 4            │
    ├────────────┼──────────────┤
    │ 50         │ 8            │
    ├────────────┼──────────────┤
    │ 75         │ 12           │
    ├────────────┼──────────────┤
    │ 90         │ 14           │
    ├────────────┼──────────────┤
    │ 97.5       │ 17           │
    ├────────────┼──────────────┤
    │ 99         │ 19           │
    ├────────────┼──────────────┤
    │ 99.9       │ 22           │
    ├────────────┼──────────────┤
    │ 99.99      │ 23           │
    ├────────────┼──────────────┤
    │ 99.999     │ 23           │
    └────────────┴──────────────┘

    305 requests in 60.06s, 108 kB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    1,000 clients subscribed, 63.07s

    ┌──────────┬─────────┬─────────┬──────────┬───────┬─────────┬─────────┬──────────┐
    │ Stat     │ 2.5%    │ 50%     │ 97.5%    │ 99%   │ Avg     │ Stdev   │ Max      │
    ├──────────┼─────────┼─────────┼──────────┼───────┼─────────┼─────────┼──────────┤
    │ Delivery │ 4.04 ms │ 8.82 ms │ 16.42 ms │ 18 ms │ 9.18 ms │ 3.46 ms │ 23.46 ms │
    └──────────┴─────────┴─────────┴──────────┴───────┴─────────┴─────────┴──────────┘
    ┌───────────┬────┬──────┬───────┬───────┬─────────┬────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%   │ 97.5% │ Avg     │ Stdev  │ Min │
    ├───────────┼────┼──────┼───────┼───────┼─────────┼────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 5,000 │ 5,000 │ 4,836.1 │ 890.39 │ 0   │
    └───────────┴────┴──────┴───────┴───────┴─────────┴────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 63

    300k notifications received in 63.07s (300,000 of 300,000 expected), 46.0 MB read
    ```

**As many as the server takes**

Calls / second

105

6,268 calls in 60 s, 10 connections

Notifications / second

103,387

6,273,000 received by 1,000 clients

Delivery p50

85.3ms

average 85.6 ms

Delivery p99

153ms

max 228 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **1.8 vCPU** · Redis **0.1 vCPU** · whole server busy **98 %** · load generator busy **65 %**

    autocannon · A broadcast to 1,000 clients, as many as the server takes

    ```text
    $ autocannon -c 10 -d 60 -w 2 -l -m POST -b '{"name":"announcements","eventData":{"t":<now>,"type":"announcement","text":"Hello from API Maker"}}' -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" -H "content-type: application/json" "http://<server>:38246/api/system-api/bench/emit-event-ws"
    Running 60s test @ http://<server>:38246/api/system-api/bench/emit-event-ws
    10 connections
    2 workers

    ┌─────────┬───────┬───────┬────────┬────────┬──────────┬──────────┬────────┐
    │ Stat    │ 2.5%  │ 50%   │ 97.5%  │ 99%    │ Avg      │ Stdev    │ Max    │
    ├─────────┼───────┼───────┼────────┼────────┼──────────┼──────────┼────────┤
    │ Latency │ 47 ms │ 94 ms │ 150 ms │ 166 ms │ 95.09 ms │ 25.46 ms │ 227 ms │
    └─────────┴───────┴───────┴────────┴────────┴──────────┴──────────┴────────┘
    ┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
    │ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg     │ Stdev   │ Min     │
    ├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
    │ Req/Sec   │ 72      │ 74      │ 102     │ 144     │ 104.47  │ 14.74   │ 72      │
    ├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
    │ Bytes/Sec │ 25.9 kB │ 26.7 kB │ 36.7 kB │ 51.9 kB │ 37.6 kB │ 5.31 kB │ 25.9 kB │
    └───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 120

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 21           │
    ├────────────┼──────────────┤
    │ 0.01       │ 21           │
    ├────────────┼──────────────┤
    │ 0.1        │ 28           │
    ├────────────┼──────────────┤
    │ 1          │ 38           │
    ├────────────┼──────────────┤
    │ 2.5        │ 47           │
    ├────────────┼──────────────┤
    │ 10         │ 63           │
    ├────────────┼──────────────┤
    │ 25         │ 79           │
    ├────────────┼──────────────┤
    │ 50         │ 94           │
    ├────────────┼──────────────┤
    │ 75         │ 110          │
    ├────────────┼──────────────┤
    │ 90         │ 127          │
    ├────────────┼──────────────┤
    │ 97.5       │ 150          │
    ├────────────┼──────────────┤
    │ 99         │ 166          │
    ├────────────┼──────────────┤
    │ 99.9       │ 195          │
    ├────────────┼──────────────┤
    │ 99.99      │ 227          │
    ├────────────┼──────────────┤
    │ 99.999     │ 227          │
    └────────────┴──────────────┘

    6k requests in 60.02s, 2.26 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    1,000 clients subscribed, 63.68s

    ┌──────────┬──────────┬──────────┬───────────┬───────────┬──────────┬──────────┬───────────┐
    │ Stat     │ 2.5%     │ 50%      │ 97.5%     │ 99%       │ Avg      │ Stdev    │ Max       │
    ├──────────┼──────────┼──────────┼───────────┼───────────┼──────────┼──────────┼───────────┤
    │ Delivery │ 38.66 ms │ 85.31 ms │ 138.24 ms │ 152.96 ms │ 85.61 ms │ 24.73 ms │ 227.71 ms │
    └──────────┴──────────┴──────────┴───────────┴───────────┴──────────┴──────────┴───────────┘
    ┌───────────┬────┬──────┬─────────┬─────────┬───────────┬──────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%     │ 97.5%   │ Avg       │ Stdev    │ Min │
    ├───────────┼────┼──────┼─────────┼─────────┼───────────┼──────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 100,764 │ 155,848 │ 100,208.6 │ 23868.95 │ 0   │
    └───────────┴────┴──────┴─────────┴─────────┴───────────┴──────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    6.27M notifications received in 63.68s (6,273,000 of 6,268,000 expected), 962.5 MB read
    ```

### Rows inserted in a table

100 clients subscribe to the insert API of a table (`SCHEMA_POST_BULK_INSERT` on `inserts_public`, `getEventData: true`) ; autocannon inserts rows of the [dataset](https://apimaker.dev/json/benchmark_dataset.json) through the [insert API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-save-single-or-multiple-api.html), and every row saved is told to each of the 100 clients, with its columns.

**50 calls a second**

Calls / second (paced)

50

3,000 calls in 60 s, 10 connections

Notifications / second

4,931

301,000 received by 100 clients

Delivery p50

25.3ms

average 25.3 ms

Delivery p99

44.4ms

max 55.3 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **0.1 vCPU** · Redis **0.0 vCPU** · MongoDB **0.0 vCPU** · whole server busy **9 %** · load generator busy **11 %**

    autocannon · Inserts told to 100 clients, 50 inserts a second

    ```text
    $ autocannon -c 10 -d 60 -R 50 -l -m POST -b '{"customer_id":1,"first_name":"BENCH","last_name":"INSERT","phone":<now>,"last_update":"2006-02-15T04:34:00.330Z","pincode":111111,"shipping_id":2,"dob":"2022-10-30T03:25:03.000Z","country":"India"}' -H "content-type: application/json" "http://<server>:38246/api/schema/bench/mongodb/am_bench/inserts_public/save-single-or-multiple"
    Running 60s test @ http://<server>:38246/api/schema/bench/mongodb/am_bench/inserts_public/save-single-or-multiple
    10 connections

    ┌─────────┬──────┬──────┬───────┬───────┬────────┬─────────┬───────┐
    │ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%   │ Avg    │ Stdev   │ Max   │
    ├─────────┼──────┼──────┼───────┼───────┼────────┼─────────┼───────┤
    │ Latency │ 1 ms │ 8 ms │ 21 ms │ 24 ms │ 8.6 ms │ 5.64 ms │ 36 ms │
    └─────────┴──────┴──────┴───────┴───────┴────────┴─────────┴───────┘
    ┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬────────┬─────────┐
    │ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg     │ Stdev  │ Min     │
    ├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
    │ Req/Sec   │ 50      │ 50      │ 50      │ 50      │ 50      │ 0      │ 50      │
    ├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
    │ Bytes/Sec │ 30.2 kB │ 30.2 kB │ 30.3 kB │ 30.3 kB │ 30.2 kB │ 2.88 B │ 30.2 kB │
    └───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴────────┴─────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 60

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 1            │
    ├────────────┼──────────────┤
    │ 0.01       │ 1            │
    ├────────────┼──────────────┤
    │ 0.1        │ 1            │
    ├────────────┼──────────────┤
    │ 1          │ 1            │
    ├────────────┼──────────────┤
    │ 2.5        │ 1            │
    ├────────────┼──────────────┤
    │ 10         │ 2            │
    ├────────────┼──────────────┤
    │ 25         │ 4            │
    ├────────────┼──────────────┤
    │ 50         │ 8            │
    ├────────────┼──────────────┤
    │ 75         │ 12           │
    ├────────────┼──────────────┤
    │ 90         │ 16           │
    ├────────────┼──────────────┤
    │ 97.5       │ 21           │
    ├────────────┼──────────────┤
    │ 99         │ 24           │
    ├────────────┼──────────────┤
    │ 99.9       │ 31           │
    ├────────────┼──────────────┤
    │ 99.99      │ 34           │
    ├────────────┼──────────────┤
    │ 99.999     │ 36           │
    └────────────┴──────────────┘

    3k requests in 60.03s, 1.81 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    100 clients subscribed, 64.04s

    ┌──────────┬──────────┬─────────┬──────────┬──────────┬──────────┬─────────┬──────────┐
    │ Stat     │ 2.5%     │ 50%     │ 97.5%    │ 99%      │ Avg      │ Stdev   │ Max      │
    ├──────────┼──────────┼─────────┼──────────┼──────────┼──────────┼─────────┼──────────┤
    │ Delivery │ 10.29 ms │ 25.3 ms │ 40.32 ms │ 44.42 ms │ 25.32 ms │ 7.56 ms │ 55.33 ms │
    └──────────┴──────────┴─────────┴──────────┴──────────┴──────────┴─────────┴──────────┘
    ┌───────────┬────┬──────┬───────┬───────┬─────────┬─────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%   │ 97.5% │ Avg     │ Stdev   │ Min │
    ├───────────┼────┼──────┼───────┼───────┼─────────┼─────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 5,000 │ 5,000 │ 4,774.2 │ 1006.74 │ 0   │
    └───────────┴────┴──────┴───────┴───────┴─────────┴─────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    301k notifications received in 64.04s (301,000 of 300,000 expected), 94.4 MB read
    ```

**As many as the server takes**

Calls / second

604

36,218 calls in 60 s, 100 connections

Notifications / second

59,275

3,631,600 received by 100 clients

Delivery p50

562ms

average 560 ms

Delivery p99

716ms

max 842 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **1.4 vCPU** · Redis **0.1 vCPU** · MongoDB **0.4 vCPU** · whole server busy **99 %** · load generator busy **39 %**

    autocannon · Inserts told to 100 clients, as many as the server takes

    ```text
    $ autocannon -c 100 -d 60 -w 4 -l -m POST -b '{"customer_id":1,"first_name":"BENCH","last_name":"INSERT","phone":<now>,"last_update":"2006-02-15T04:34:00.330Z","pincode":111111,"shipping_id":2,"dob":"2022-10-30T03:25:03.000Z","country":"India"}' -H "content-type: application/json" "http://<server>:38246/api/schema/bench/mongodb/am_bench/inserts_public/save-single-or-multiple"
    Running 60s test @ http://<server>:38246/api/schema/bench/mongodb/am_bench/inserts_public/save-single-or-multiple
    100 connections
    4 workers

    ┌─────────┬───────┬────────┬────────┬────────┬───────────┬──────────┬────────┐
    │ Stat    │ 2.5%  │ 50%    │ 97.5%  │ 99%    │ Avg       │ Stdev    │ Max    │
    ├─────────┼───────┼────────┼────────┼────────┼───────────┼──────────┼────────┤
    │ Latency │ 92 ms │ 163 ms │ 249 ms │ 286 ms │ 164.89 ms │ 39.85 ms │ 403 ms │
    └─────────┴───────┴────────┴────────┴────────┴───────────┴──────────┴────────┘
    ┌───────────┬────────┬────────┬────────┬────────┬────────┬─────────┬────────┐
    │ Stat      │ 1%     │ 2.5%   │ 50%    │ 97.5%  │ Avg    │ Stdev   │ Min    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼─────────┼────────┤
    │ Req/Sec   │ 489    │ 511    │ 605    │ 684    │ 603.64 │ 51.02   │ 489    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼─────────┼────────┤
    │ Bytes/Sec │ 296 kB │ 309 kB │ 366 kB │ 414 kB │ 365 kB │ 30.8 kB │ 296 kB │
    └───────────┴────────┴────────┴────────┴────────┴────────┴─────────┴────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 240

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 19           │
    ├────────────┼──────────────┤
    │ 0.01       │ 32           │
    ├────────────┼──────────────┤
    │ 0.1        │ 43           │
    ├────────────┼──────────────┤
    │ 1          │ 73           │
    ├────────────┼──────────────┤
    │ 2.5        │ 92           │
    ├────────────┼──────────────┤
    │ 10         │ 119          │
    ├────────────┼──────────────┤
    │ 25         │ 140          │
    ├────────────┼──────────────┤
    │ 50         │ 163          │
    ├────────────┼──────────────┤
    │ 75         │ 187          │
    ├────────────┼──────────────┤
    │ 90         │ 212          │
    ├────────────┼──────────────┤
    │ 97.5       │ 249          │
    ├────────────┼──────────────┤
    │ 99         │ 286          │
    ├────────────┼──────────────┤
    │ 99.9       │ 362          │
    ├────────────┼──────────────┤
    │ 99.99      │ 401          │
    ├────────────┼──────────────┤
    │ 99.999     │ 403          │
    └────────────┴──────────────┘

    36k requests in 60.03s, 21.9 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    100 clients subscribed, 64.27s

    ┌──────────┬───────────┬───────────┬───────────┬───────────┬───────────┬──────────┬───────────┐
    │ Stat     │ 2.5%      │ 50%       │ 97.5%     │ 99%       │ Avg       │ Stdev    │ Max       │
    ├──────────┼───────────┼───────────┼───────────┼───────────┼───────────┼──────────┼───────────┤
    │ Delivery │ 415.23 ms │ 561.66 ms │ 684.54 ms │ 715.78 ms │ 559.78 ms │ 70.38 ms │ 841.73 ms │
    └──────────┴───────────┴───────────┴───────────┴───────────┴───────────┴──────────┴───────────┘
    ┌───────────┬────┬──────┬────────┬────────┬──────────┬──────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%    │ 97.5%  │ Avg      │ Stdev    │ Min │
    ├───────────┼────┼──────┼────────┼────────┼──────────┼──────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 59,959 │ 67,002 │ 58,105.2 │ 11502.50 │ 0   │
    └───────────┴────┴──────┴────────┴────────┴──────────┴──────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    3.63M notifications received in 64.27s (3,631,600 of 3,621,800 expected), 1139.1 MB read
    ```

## With every client connected

The same runs once more, with 338,016 clients connected and waiting : what a server which is full of WebSocket clients still does.

| | No client, or 10,000 | 338,016 clients connected |
|---|--:|--:|
| A notification for one person, 1,000 a second : delivery p50 | 1.45 ms | **1.47 ms** |
| … p99 | 3.15 ms | **3.27 ms** |
| A notification for one person, as many as the server takes | 7,562 / s | **6,967 / s** |
| Get all with both tokens, 100 connections (autocannon) | 3,379 req/s | **3,006 req/s** |
| … latency p50 / p99 | 29 ms / 49 ms | **30 ms / 128 ms** |

**Notification, 1,000 a second**

Calls / second (paced)

1,000

60,000 calls in 60 s, 10 connections

Notifications / second

991

60,006 received by 338,016 clients

Delivery p50

1.47ms

average 1.56 ms

Delivery p99

3.27ms

max 26.1 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **0.3 vCPU** · Redis **0.0 vCPU** · whole server busy **22 %** · load generator busy **17 %**

    autocannon · A notification for one person, 1,000 a second, every client connected

    ```text
    $ autocannon -c 10 -d 60 -R 1000 -l -m POST -b '{"name":"order-updates","eventData":{"recipientId":"<id of a client>","t":<now>,"type":"order-updated","order_no":1001,"status":"SHIPPED"}}' -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" -H "content-type: application/json" "http://<server>:38246/api/system-api/bench/emit-event-ws"
    Running 60s test @ http://<server>:38246/api/system-api/bench/emit-event-ws
    10 connections

    ┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬───────┐
    │ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max   │
    ├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼───────┤
    │ Latency │ 0 ms │ 1 ms │ 3 ms  │ 4 ms │ 1.28 ms │ 1.18 ms │ 26 ms │
    └─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴───────┘
    ┌───────────┬────────┬────────┬────────┬────────┬────────┬───────┬────────┐
    │ Stat      │ 1%     │ 2.5%   │ 50%    │ 97.5%  │ Avg    │ Stdev │ Min    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼───────┼────────┤
    │ Req/Sec   │ 998    │ 998    │ 1,000  │ 1,001  │ 1,000  │ 0.61  │ 998    │
    ├───────────┼────────┼────────┼────────┼────────┼────────┼───────┼────────┤
    │ Bytes/Sec │ 356 kB │ 356 kB │ 357 kB │ 357 kB │ 357 kB │ 187 B │ 356 kB │
    └───────────┴────────┴────────┴────────┴────────┴────────┴───────┴────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 60

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 0            │
    ├────────────┼──────────────┤
    │ 0.01       │ 0            │
    ├────────────┼──────────────┤
    │ 0.1        │ 0            │
    ├────────────┼──────────────┤
    │ 1          │ 0            │
    ├────────────┼──────────────┤
    │ 2.5        │ 0            │
    ├────────────┼──────────────┤
    │ 10         │ 1            │
    ├────────────┼──────────────┤
    │ 25         │ 1            │
    ├────────────┼──────────────┤
    │ 50         │ 1            │
    ├────────────┼──────────────┤
    │ 75         │ 1            │
    ├────────────┼──────────────┤
    │ 90         │ 2            │
    ├────────────┼──────────────┤
    │ 97.5       │ 3            │
    ├────────────┼──────────────┤
    │ 99         │ 4            │
    ├────────────┼──────────────┤
    │ 99.9       │ 20           │
    ├────────────┼──────────────┤
    │ 99.99      │ 24           │
    ├────────────┼──────────────┤
    │ 99.999     │ 26           │
    └────────────┴──────────────┘

    61k requests in 60.05s, 21.4 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    338,016 clients subscribed, 63.56s

    ┌──────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬──────────┐
    │ Stat     │ 2.5%    │ 50%     │ 97.5%   │ 99%     │ Avg     │ Stdev   │ Max      │
    ├──────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼──────────┤
    │ Delivery │ 0.81 ms │ 1.47 ms │ 2.77 ms │ 3.27 ms │ 1.56 ms │ 0.67 ms │ 26.14 ms │
    └──────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴──────────┘
    ┌───────────┬────┬──────┬───────┬───────┬───────┬────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%   │ 97.5% │ Avg   │ Stdev  │ Min │
    ├───────────┼────┼──────┼───────┼───────┼───────┼────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 1,000 │ 1,000 │ 951.7 │ 214.15 │ 0   │
    └───────────┴────┴──────┴───────┴───────┴───────┴────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    60k notifications received in 63.56s (60,006 of 60,000 expected), 10.8 MB read
    ```

**Notification, as many as the server takes**

Calls / second

7,055

423,236 calls in 60 s, 100 connections

Notifications / second

6,967

423,336 received by 338,016 clients

Delivery p50

13.0ms

average 14.0 ms

Delivery p99

43.4ms

max 258 ms

Not delivered

0

0 calls failed

(Server during this run) API Maker **1.6 vCPU** · Redis **0.1 vCPU** · whole server busy **99 %** · load generator busy **50 %**

    autocannon · A notification for one person, as many as the server takes, every client connected

    ```text
    $ autocannon -c 100 -d 60 -w 4 -l -m POST -b '{"name":"order-updates","eventData":{"recipientId":"<id of a client>","t":<now>,"type":"order-updated","order_no":1001,"status":"SHIPPED"}}' -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" -H "content-type: application/json" "http://<server>:38246/api/system-api/bench/emit-event-ws"
    Running 60s test @ http://<server>:38246/api/system-api/bench/emit-event-ws
    100 connections
    4 workers

    ┌─────────┬──────┬───────┬───────┬───────┬──────────┬─────────┬────────┐
    │ Stat    │ 2.5% │ 50%   │ 97.5% │ 99%   │ Avg      │ Stdev   │ Max    │
    ├─────────┼──────┼───────┼───────┼───────┼──────────┼─────────┼────────┤
    │ Latency │ 8 ms │ 13 ms │ 28 ms │ 43 ms │ 13.64 ms │ 7.38 ms │ 188 ms │
    └─────────┴──────┴───────┴───────┴───────┴──────────┴─────────┴────────┘
    ┌───────────┬─────────┬─────────┬────────┬─────────┬──────────┬────────┬─────────┐
    │ Stat      │ 1%      │ 2.5%    │ 50%    │ 97.5%   │ Avg      │ Stdev  │ Min     │
    ├───────────┼─────────┼─────────┼────────┼─────────┼──────────┼────────┼─────────┤
    │ Req/Sec   │ 6,495   │ 6,539   │ 6,991  │ 7,747   │ 7,054.54 │ 296.01 │ 6,493   │
    ├───────────┼─────────┼─────────┼────────┼─────────┼──────────┼────────┼─────────┤
    │ Bytes/Sec │ 2.32 MB │ 2.33 MB │ 2.5 MB │ 2.77 MB │ 2.52 MB  │ 106 kB │ 2.32 MB │
    └───────────┴─────────┴─────────┴────────┴─────────┴──────────┴────────┴─────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 240

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 2            │
    ├────────────┼──────────────┤
    │ 0.01       │ 3            │
    ├────────────┼──────────────┤
    │ 0.1        │ 4            │
    ├────────────┼──────────────┤
    │ 1          │ 7            │
    ├────────────┼──────────────┤
    │ 2.5        │ 8            │
    ├────────────┼──────────────┤
    │ 10         │ 9            │
    ├────────────┼──────────────┤
    │ 25         │ 11           │
    ├────────────┼──────────────┤
    │ 50         │ 13           │
    ├────────────┼──────────────┤
    │ 75         │ 14           │
    ├────────────┼──────────────┤
    │ 90         │ 17           │
    ├────────────┼──────────────┤
    │ 97.5       │ 28           │
    ├────────────┼──────────────┤
    │ 99         │ 43           │
    ├────────────┼──────────────┤
    │ 99.9       │ 98           │
    ├────────────┼──────────────┤
    │ 99.99      │ 155          │
    ├────────────┼──────────────┤
    │ 99.999     │ 186          │
    └────────────┴──────────────┘

    423k requests in 60.03s, 151 MB read
    ```

    am_ws_load · what the clients received

    ```text
    $ am_ws_load listen "ws://<server>:38246/?x-am-authorization=<token>&x-am-user-authorization=<token>"
    338,016 clients subscribed, 63.77s

    ┌──────────┬─────────┬──────────┬──────────┬──────────┬───────┬─────────┬───────────┐
    │ Stat     │ 2.5%    │ 50%      │ 97.5%    │ 99%      │ Avg   │ Stdev   │ Max       │
    ├──────────┼─────────┼──────────┼──────────┼──────────┼───────┼─────────┼───────────┤
    │ Delivery │ 7.93 ms │ 12.98 ms │ 28.13 ms │ 43.42 ms │ 14 ms │ 7.29 ms │ 258.18 ms │
    └──────────┴─────────┴──────────┴──────────┴──────────┴───────┴─────────┴───────────┘
    ┌───────────┬────┬──────┬───────┬───────┬─────────┬─────────┬─────┐
    │ Stat      │ 1% │ 2.5% │ 50%   │ 97.5% │ Avg     │ Stdev   │ Min │
    ├───────────┼────┼──────┼───────┼───────┼─────────┼─────────┼─────┤
    │ Notif/Sec │ 0  │ 0    │ 6,963 │ 7,626 │ 6,774.2 │ 1329.02 │ 0   │
    └───────────┴────┴──────┴───────┴───────┴─────────┴─────────┴─────┘

    Delivery : from the moment the request is written to the moment the client reads the notification.
    # of samples: 64

    423k notifications received in 63.77s (423,336 of 423,236 expected), 76.6 MB read
    ```

**Get all with both tokens**

Requests / second

3,006

180,301 requests in 60 s

Latency p50

30ms

average 32.77 ms

Latency p99

128ms

max 374 ms

Errors

0

non-2xx, errors, timeouts

(Server during this run) API Maker **1.1 vCPU** · Redis **0.0 vCPU** · MongoDB **0.6 vCPU** · whole server busy **100 %** · load generator busy **28 %**

    autocannon · get all with both tokens · 338,016 WebSocket clients connected

    ```text
    $ autocannon -c 100 -d 60 -w 4 -l -H "x-am-authorization: <token>" -H "x-am-user-authorization: <token>" "http://<server>:38246/api/schema/bench/mongodb/am_bench/customers"
    Running 60s test @ http://<server>:38246/api/schema/bench/mongodb/am_bench/customers
    100 connections
    4 workers

    ┌─────────┬───────┬───────┬───────┬────────┬──────────┬──────────┬────────┐
    │ Stat    │ 2.5%  │ 50%   │ 97.5% │ 99%    │ Avg      │ Stdev    │ Max    │
    ├─────────┼───────┼───────┼───────┼────────┼──────────┼──────────┼────────┤
    │ Latency │ 12 ms │ 30 ms │ 73 ms │ 128 ms │ 32.77 ms │ 22.13 ms │ 374 ms │
    └─────────┴───────┴───────┴───────┴────────┴──────────┴──────────┴────────┘
    ┌───────────┬─────────┬─────────┬─────────┬─────────┬──────────┬────────┬─────────┐
    │ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg      │ Stdev  │ Min     │
    ├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼────────┼─────────┤
    │ Req/Sec   │ 2,529   │ 2,535   │ 2,973   │ 3,677   │ 3,005.57 │ 266.17 │ 2,529   │
    ├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼────────┼─────────┤
    │ Bytes/Sec │ 6.92 MB │ 6.93 MB │ 8.13 MB │ 10.1 MB │ 8.22 MB  │ 728 kB │ 6.92 MB │
    └───────────┴─────────┴─────────┴─────────┴─────────┴──────────┴────────┴─────────┘

    Req/Bytes counts sampled once per second.
    # of samples: 240

    ┌────────────┬──────────────┐
    │ Percentile │ Latency (ms) │
    ├────────────┼──────────────┤
    │ 0.001      │ 0            │
    ├────────────┼──────────────┤
    │ 0.01       │ 1            │
    ├────────────┼──────────────┤
    │ 0.1        │ 2            │
    ├────────────┼──────────────┤
    │ 1          │ 8            │
    ├────────────┼──────────────┤
    │ 2.5        │ 12           │
    ├────────────┼──────────────┤
    │ 10         │ 18           │
    ├────────────┼──────────────┤
    │ 25         │ 24           │
    ├────────────┼──────────────┤
    │ 50         │ 30           │
    ├────────────┼──────────────┤
    │ 75         │ 36           │
    ├────────────┼──────────────┤
    │ 90         │ 44           │
    ├────────────┼──────────────┤
    │ 97.5       │ 73           │
    ├────────────┼──────────────┤
    │ 99         │ 128          │
    ├────────────┼──────────────┤
    │ 99.9       │ 297          │
    ├────────────┼──────────────┤
    │ 99.99      │ 340          │
    ├────────────┼──────────────┤
    │ 99.999     │ 370          │
    └────────────┴──────────────┘

    180k requests in 60.03s, 493 MB read
    ```

## A restart

API Maker was restarted (`systemctl restart api_maker_be`) with 253,512 clients connected : the newest left first, down to 75 % of the 338,016 it held. Every client of a restarted server comes back within the same seconds and waits for its turn with its request in the kernel, about 4 KB each : a server needs that room. It takes what Redis keeps of them out first, then closes every client with the code `1001` (*Server is going away*) ; each client waits one to five seconds, as an application does, connects again with the same tokens and sends its `REGISTER` again. The server which comes back lets 256 clients in at a time and handles the messages of 256 at a time, the others wait for their turn : its memory comes back to what it was, not higher.

Clients dropped

253,512

of 253,512 connected

All back after

90.0s

the restart itself : 18.7 s

A client was away, p50

48.9s

its own wait of 1 to 5 s counted

A client was away, p99

78.2s

the longest : 86.5 s

After the restart, with the 253,512 clients back : API Maker 944 MB (1,110 MB before it), 1,075 MB of memory available. They were then told again, each for itself, 1,000 notifications a second for 60 seconds : **all 60,000 arrived**, in 1.66 ms (p50) and 3.97 ms (p99). A client whose subscription had not come back with it would have been told nothing.

### Every client leaves at once

At the end of the run, the 253,512 clients closed their connection in the same second, as when a network or a load balancer in front of the server goes. The server had closed every one of their sockets after **10.1 s**, and Redis held nothing of them any more after **13.8 s**. A socket is closed at once, and Redis is told behind it.

## Questions

### How many WebSocket connections can API Maker hold on 2 shared vCPUs and 4 GB ?

338,016 clients were connected at the same time on this server, each with both tokens and a subscription of its own, with MongoDB, Redis and two sandboxes on the same machine. Memory is what ends first : a client costs about 8.5 KB of the server in all.

### How much memory does a WebSocket client cost ?

About 8.5 KB : 3.1 KB in the API Maker process, 4.3 KB in the Linux kernel (its socket) and 1.0 KB in Redis (its subscription). Measured between 100,000 and 250,000 clients which wait, each connected with both tokens and one subscription.

### How many clients can connect each second ?

4,041 clients a second connected with both tokens, subscribed and left, 100 at a time ; 9,504 a second without a subscription. With a can user connect code on the event : 3,438 a second.

### How fast does a notification reach a client ?

At 1,000 notifications a second, each for one person among 10,000 : 1.45 ms from the HTTP call to the client (p50), 3.15 ms for 99 % of them. With as many calls as the server takes : 7,562 notifications a second.

### Do connected WebSocket clients slow the APIs down ?

Get all with both tokens answered 3,379 requests a second with no WebSocket client, and 3,006 with 338,016 clients connected and waiting. A client which waits costs memory ; its CPU is a ping a minute.
