Table of Contents

Class TransportRateLimits

Namespace
MailFathom.Infrastructure.Security.Transport
Assembly
MailFathom.Infrastructure.dll

How much traffic one process serves on a transport surface, and how much of it one user may spend.

public sealed class TransportRateLimits
Inheritance
TransportRateLimits
Inherited Members

Remarks

Three controls rather than one, because they bound different resources. The process-wide concurrency limit bounds what the process is doing at any instant — database connections, CPU, open response streams — and is shared by every caller of that surface, since a machine has one set of them. The per-user concurrency limit bounds how much of that one user may hold at once, so one user's burst leaves permits for everybody else. The token bucket bounds how often one user may ask, so a client that goes into a loop spends its own user's capacity rather than everyone's.

The numbers are the deployment's and the allowance is each user's. Every user is given a bucket and a concurrency allowance of the configured size, independently of every other user; nothing about a user, a credential, or an organization carries a number of its own. Every credential one user holds spends that user's one allowance, so holding a second credential buys no second bucket.

Nothing here names a surface. The same numbers describe every bounded endpoint, and each surface is given an instance of its own, so what one endpoint is configured to permit says nothing about another and no endpoint's traffic reaches another's limiters.

All three are in-process. Nothing here coordinates across instances, so a deployment running several processes enforces these numbers once per process rather than once in total, and none of it is protection against a distributed flood. The controls exist so that one misbehaving caller cannot exhaust the resources of the process it is talking to.

Queue limits default to zero throughout. A queued request is a request holding memory and a connection while it waits for capacity that is already gone, which turns an overload into a slower, larger overload; refusing it immediately tells the client to back off while the server is still healthy. A deployment that would rather absorb a short burst can configure a bounded queue, and bounded is the only shape available.

A caller queue costs more than it looks like it does, which is why RequestQueueLimit is bounded by MaxConcurrentRequests rather than only by its own range. The concurrency limiters are acquired before the bucket, so a request waiting for its user's tokens has already taken a concurrency permit and holds it until the next replenishment — up to an hour away. Keeping the queue smaller than the permit count is what stops one user out of capacity from parking every permit the surface has and refusing everyone else through a limit that is supposed to be their own.

Properties

ConcurrencyQueueLimit

Gets how many requests wait for a process-wide concurrency slot before the rest are refused.

Default

Gets the limits a deployment that configures nothing runs under.

MaxConcurrentRequests

Gets how many requests the process serves at once on this surface, across every user.

MaxConcurrentRequestsPerUser

Gets how many requests one user may have served at once on this surface.

ReplenishmentPeriod

Gets how often a user's spent capacity is restored.

RequestQueueLimit

Gets how many of one user's requests wait for capacity before the rest are refused.

TokenCapacity

Gets the largest burst one user may spend at once.

TokensPerReplenishmentPeriod

Gets how much of that burst one user gets back each ReplenishmentPeriod.

Methods

Create(int, int, int, int, int, TimeSpan, int)

Creates the limits a transport surface runs under.