Skip to content

Speed limits and connection limits

katana limits speed per user. Every user on a node gets one token bucket, and every byte of payload that user moves, in either direction and over TCP or UDP, is paid for from it. The rate comes from your panel, and a single key in the katana config can override it for the whole node.

This page explains where a user’s rate comes from, how the bucket enforces it, when a change takes effect, and which fixed connection limits protect a node. Read it when you set up plans with speed limits, when a user reports a speed that does not match their plan, or when you size a busy node.

Most of the time the panel sets the limits and you leave katana alone: give the user or their plan a speed limit in the panel, and katana applies it on the next poll. To cap every user of a node at the same speed instead, set speed_limit in [node.api]:

/etc/katana/config.toml
[log]
level = "info"
[[node]]
panel_type = "NewV2board"
[node.api]
host = "https://panel.example.com"
node_id = 1
key = "replace-with-the-panel-key"
node_type = "V2ray"
speed_limit = 50 # Mbps; every user on this node runs at 50 Mbps
[node.controller]
listen_ip = "0.0.0.0"
update_periodic = 60
[node.controller.cert]
mode = "file"
cert_file = "/etc/katana/cert/fullchain.pem"
key_file = "/etc/katana/cert/privkey.pem"

With this file, each user on node 1 gets a bucket of 50 Mbps, which is 6,250,000 bytes per second, whatever the panel says about them. Check the file with katana --test -c /etc/katana/config.toml before you start katana with it or save it over the file a running katana watches.

Two keys in [node.api] relate to limits. The rest of [node.api] is described in Config file.

Key Type Default Description
speed_limit float 0 Speed limit in Mbps for every user of this node. A value greater than 0 replaces every user’s panel limit, even when the panel limit is lower. 0 or a negative value keeps the panel’s limits. Decimals are allowed, for example 12.5.
device_limit integer 0 Has no effect. The panel’s device limits are enforced with [node.controller] enable_device_limit.

speed_limit must be a number. A quoted value, such as speed_limit = "50", is a parse error: katana refuses to start with it, and a hot reload that contains it is rejected while katana keeps its current config. katana --test names the line and column:

configuration error: config parse error: TOML parse error at line 12, column 15

A misspelt key, such as speedlimit, is rejected the same way, because [node.api] refuses unknown fields.

You do not need to restart katana after you change speed_limit on a running node. Save the file, and the hot reload applies the new value at once without dropping any connection. When a change takes effect explains how the new rate reaches open connections. Limits you change in the panel do not need a restart either; katana picks them up on the next poll.

katana works out one rate per user from two sources:

Source Where it is set Unit on the wire Panels
User limit The user (or their plan) in the panel; on helium, one limit for every user of the node Mbps (helium: bytes per second) Xboard / V2board, helium
Local override speed_limit in [node.api] Mbps All

katana reads the user limit from the speed_limit field of each user in the UniProxy user list. It is a whole number of Mbps, and 0 means unlimited. katana reads no node-level speed limit from the UniProxy node config.

The rules for combining them:

  1. Convert to bytes per second. katana treats a megabit as 1,000,000 bits, so 1 Mbps is 125,000 bytes per second. helium’s limits are already in bytes per second. The result is rounded down to a whole byte. A value of 0 or less becomes 0, which means unlimited.
  2. Apply the local override. If speed_limit is greater than 0, it replaces the user limit. Otherwise the user limit stands, and a user limit of 0 means the user is unlimited.
User limit speed_limit Effective rate
20 Mbps 0 20 Mbps = 2,500,000 B/s
0 0 unlimited
-1 0 unlimited
20 Mbps 100 100 Mbps = 12,500,000 B/s
0 12.5 12.5 Mbps = 1,562,500 B/s

The fourth row is the one that surprises people: the override is not a ceiling. It replaces the panel’s numbers, so a user whose plan says 20 Mbps runs at 100 Mbps on that node.

Each user on a node has exactly one token bucket, holding bytes:

  • It refills at the user’s rate.
  • It holds at most one second of that rate. A 50 Mbps user can bank 6,250,000 bytes and no more, however long they were idle, so after a quiet period they get at most one extra second’s worth of data before the rate applies.
  • It starts full when the user first gets a limit. When the rate changes, the bucket keeps what the user had earned, up to one second of the new rate, and keeps any debt; a user whose limit is removed has any debt forgiven.
  • Every flow of that user shares it: all their connections, both directions, TCP streams and UDP packets alike. The limit is on the total, so a 50 Mbps user who uploads and downloads at the same time gets 50 Mbps between the two, not 50 Mbps each way.

The bucket belongs to the node, so a user on two [[node]] entries of the same katana process has two separate buckets. Their panel limit applies on each node independently.

A transfer may start whenever the bucket is not in debt. After it moves, katana charges its full size, even when that is more than the bucket holds. The balance then goes negative, and every later transfer of that user, on any connection, waits until the refill has paid the debt back.

flowchart TB
  A["a transfer is ready to move"] --> B{"is the user's bucket in debt?"}
  B -- "yes" --> W["wait until the refill repays the debt"]
  W --> B
  B -- "no" --> M["move the bytes"]
  M --> C["charge their full size; the balance may go negative"]
  C --> R["refill at the user's rate, up to one second of rate"]
  R --> A

For example, take a rate of 10,000 bytes per second and a full bucket. A single 30,000-byte write passes at once: 10,000 bytes come out of the bucket and 20,000 become debt. The next transfer, upload or download, waits two seconds. Over time the user moves 10,000 bytes per second, exactly the limit. A waiting transfer looks at the bucket again at least once a second, so a raised or removed limit is felt within a second.

This is why the limit does not depend on chunk size. A scheme that waited for “enough tokens” before each chunk would have to let a chunk larger than the whole bucket through after one refill period, so large reads would run faster than the limit. With debt, the long-run average respects the rate however the bytes were chunked. The price is that a single transfer can overshoot for a moment; the transfers after it pay for that.

The bucket charges payload: the bytes a flow carries after the inbound protocol has removed its framing and encryption, and before the outbound protocol adds its own. So the limit does not change with the inbound protocol or transport, and TLS, WebSocket or VMess overhead does not count against it.

  • Bytes the user sends and bytes they receive go through the same bucket.
  • A UDP association is routed packet by packet. A packet that is blocked is dropped; every packet that leaves, and every reply, is paced like stream bytes.

The traffic katana reports to the panel is counted differently, as the bytes of each connection on the wire; Traffic reporting describes it.

katana polls the panel every update_periodic seconds (60 by default). When a user’s effective rate differs from the last poll, katana sets the new rate on that user’s bucket. It does not drop any of their connections: every flow of the user, whether already open or opened later, runs at the new rate from then on. A user whose rate did not change keeps their bucket as it is.

A change to speed_limit in the config file takes the same path, without waiting for the next poll. When a hot reload changes speed_limit, katana builds a new panel client for the node and reads the node and its users from the panel at once, in full, and every user whose effective rate changes gets the new rate as described above. This includes a Hysteria 2 node that you describe locally. If the panel cannot be reached at that moment, the new rate reaches every user on the first poll that gets an answer. An edit that also changes a setting that drops connections, such as the certificate or the route, drops every connection on the node; Hot reload lists what each key does.

A user who leaves the panel’s user list is handled differently: katana refuses their new flows at once and ends the flows they already have.

On top of per-user limits, each node has a fixed set of connection guardrails. They are constants in the code, not settings, except the count of failed gRPC streams. They are sized far above normal traffic and exist to keep a scan, a flood of idle clients or a stuck peer from exhausting memory or file descriptors.

The limits below apply to the TCP-based node types: every node type but Hysteria 2. “Per node” covers the node’s TCP port and, when handoff_dir is set, its handoff socket together: a handed-over connection takes its place from the same pool as one accepted on the port.

Guardrail Value Scope When it is reached
Live connections 4,194,304 per node A new socket is accepted and closed at once. The place is held for the whole connection, including every stream a gRPC connection carries.
Concurrent handshakes 204,800 per node A new socket is accepted and closed at once.
Protocol handshake deadline 10 s per stream A client that has not completed its protocol handshake after 10 seconds is disconnected.
Relay idle timeout 300 s per connection A connection whose relay carried nothing in either direction for 300 seconds is closed.
Idle gRPC connection 30 s per gRPC connection A gRPC connection with no open stream for 30 seconds is closed with a GOAWAY.
Failed gRPC streams 8 in a row per gRPC connection The connection is closed. carrier_max_failures in [node.controller] sets the count; see Device limits and IP bans.
AnyTLS streams 256 per AnyTLS connection A stream opened past that is closed at once; the connection and its other streams continue.
Outbound links per UDP association 64 per UDP association An association opens one link for each outbound it sends through, not one per destination. Opening a 65th closes the one sent to least recently.

A Hysteria 2 node serves QUIC on its one UDP listener and has its own limits instead:

Guardrail Value Scope When it is reached
QUIC connections 262,144 per node A new connection’s handshake is refused.
Live circuits 4,194,304 per node Counts proxy streams and UDP sessions together, for their whole life. A new proxy stream is reset and a new UDP session’s packets are dropped; the client’s other streams continue.
Open streams 65,536 per QUIC connection QUIC withholds stream credit, so the client waits before it opens another stream.
UDP sessions 256 per QUIC connection Packets that would start a 257th session are dropped.
QUIC idle timeout 30 s per QUIC connection A connection that carries no packets for 30 seconds is closed.

None of these limits is per user. There is no setting to lower them for one user or raise them for a node.

Refusals by the guardrails are logged by the runtime at debug level, one line each, for example:

dropping inbound connection; live connection limit reached
dropping inbound connection; handshake limit reached
inbound handshake timed out after 10s
hysteria2: refusing a connection; the listener is full or stopping
hysteria2: refusing a stream; the listener is at its circuit limit

They are hidden at the default info level. To see the lines of the TCP-based node types, set [log] level = "info,etemenanki_supervisor=debug"; the Hysteria 2 lines come from etemenanki_protocols. katana applies a new level without a restart.

Symptom Likely cause What to do
Every user on a node has the same speed, whatever their plan speed_limit is set in [node.api], which replaces every panel limit Set speed_limit = 0 and save the file. The hot reload applies it; no restart is needed.
A changed speed_limit has no effect The reload was rejected and katana kept its current config. A value that does not parse, such as a quoted one, logs config reload failed, keeping current: …; a node in the same file that does not build, such as one with an unknown node_type, logs reload: node …: …; keeping current config Run katana --test -c /etc/katana/config.toml, fix the error it prints, and save the file again.
A user’s speed is half the plan in each direction during a large upload and download The limit covers both directions together This is intended; set the plan’s limit for combined traffic.
A user can connect from more devices than their plan allows enable_device_limit is off, or the panel gives the user no device limit Turn on enable_device_limit where katana sees client addresses; see Device limits and IP bans.