How large should a web application be?

Estimate the replica count, application size and server capacity you need from peak traffic and CPU time per request.

A web application needs enough CPU for the requests it serves at peak, and enough memory for all the processes in each replica. Tenkai runs it as replicas of one size, and the edge router spreads the requests over them. Enter your peak traffic and CPU time per request. The calculator suggests a replica count, application size and server capacity.

Size of a web application · estimate
Example CPU time per request: 5 to 20 ms for an API, or 20 to 100 ms for a server-rendered page. This is not the total response time.

Estimate

2 replicas of the Small size, on 2 servers

Servers of 2 CPU · 4 GB. At peak, each replica uses about 50% of its 1 CPU.

Replicas each size needs

  • Tiny0.1 CPU · 128 MB reserved · 0.5 CPU · 256 MB limit

    4 replicas
  • SmallSuggested0.25 CPU · 256 MB reserved · 1 CPU · 512 MB limit

    2 replicas
  • Medium0.5 CPU · 512 MB reserved · 2 CPU · 1 GB limit

    2 replicas
  • Large1 CPU · 1 GB reserved · 4 CPU · 2 GB limit

    2 replicas

How the replicas fill the servers

  • Server 1Edge node1 replica

    CPU
    Memory
  • Server 21 replica

    CPU
    Memory
  • Kept by the system and Tenkai
  • A Small replica
  • Free

What the estimate assumes

Tenkai has no benchmark of each size. Change these to match your application.

The total memory used by one replica under load, including all its processes.
The percentage of each replica's CPU limit you expect to use at peak. Leave some unused for short bursts.

Fewest replicas

Fewest replicas

A second replica answers while one restarts.

Each server

Each server
  • Only CPU limits the requests. Time spent waiting on a database or an API costs no CPU here.
  • Size databases separately. Leave room for backups too.
  • A replica can use CPU up to its limit if that CPU is available on the server.
  • For each replica, the calculator uses either its estimated peak needs or its reserved CPU and memory, whichever is larger. CPU includes the headroom set by CPU use at peak.
  • The first server keeps memory and CPU for the system and Tenkai, the others for the system.

The result is an estimate. Tenkai has no benchmark of each size, because the cost of a request depends on your code. The calculator shows what it assumes, so you can change each assumption.

How Tenkai sizes a replica

Each size gives a replica two amounts of CPU and memory:

  • Reserved: what Tenkai keeps for the replica on its server. A deployment starts only when the servers have that room for every replica.
  • Limit: the most the replica may use. Above its memory limit, the replica stops and Swarm starts it again. Above its CPU limit, it slows down.

A replica uses CPU between the two when its server has some free. The calculator counts on the limit and keeps a share of it free for bursts: 60% use at peak by default.

The edge router on the edge node sends each request to one of the replicas, on any server of the cluster. Two replicas serve about twice the requests of one, as long as the database behind them keeps up.

Measure what a request costs

Run your application on your computer, send it a steady load with a tool such as oha or k6, and watch its CPU with docker stats. Divide the CPU it uses by the requests it serves each second: 0.5 CPU at 50 requests per second is 10 ms per request.

The traffic tab of a running web application gives its requests per minute. Divide by 60 for the requests per second, and take the busiest hour as your peak.

When the estimate is wrong

  • Your requests wait. A request that waits 200 ms for a database or an API costs no CPU while it waits. The calculator ignores that time. Your database or the API may then be the limit, not the replicas.
  • One process uses one CPU. A Node.js process runs its JavaScript on one CPU. Past the Small size, its CPU limit goes unused unless your application starts several processes: choose more replicas of the Small size.
  • Memory grows with the load. A replica that caches or holds many connections uses more memory at peak. Set the memory of a replica from what it uses under load, not at rest.
  • The servers run other things. Your managed services, workers and other applications share the servers. The calculator fills the servers with this web application alone. How much memory a server needs gives what each server keeps.