> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenetlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sizing

> Measured /deidentify throughput and latency per document size on c9g.xlarge, how many detect replicas to run for your peak, the conditions behind the numbers, and how to scale with CPU target tracking or an HPA.

**Sizing rule**: one detect replica per 4-vCPU Graviton node, at least two, and enough replicas that your peak documents per second — weighted by document size — stays under the measured per-replica throughput below.

## When to use it

Before your first production deploy, and whenever your traffic mix shifts toward longer documents. Throughput falls roughly linearly with document length, so size on characters, not request count.

## Measured throughput

Measured in AWS with 2 detect tasks on `c9g.xlarge` (one 4-thread worker per task), calling `POST /deidentify` — detection plus vault writes to Aurora — on synthetic medical-note-shaped text. "Saturated" is the highest throughput reached as concurrency increased.

| Document size | Saturated throughput per replica | p95 latency |
| - | - | - |
| 150 characters | \~29 docs/s | — |
| 2,000 characters | \~3.3 docs/s | — |
| 5,250 characters | \~1.26 docs/s | \~1.6 s at light load (1 request per replica); \~3.1 s at saturation |
| 16,000 characters | \~0.40 docs/s | — |

For comparison, the engine alone, in process, one request at a time on `c9g.xlarge`, takes **p50 775 ms, p95 \~860–910 ms** on a 5,250-character document. The difference to the service numbers is network, the vault and queueing.

> [!NOTE]
>
> **What these numbers are, and aren't.** They were measured on an earlier image, through an internal load balancer — before callers reached the services through VPC Lattice. Lattice adds a little to every request, and a TLS handshake whenever the client opens a new connection. Re-measure on the image you deploy, with your own traffic, before you commit to capacity: entity density and text shape move these numbers too.

## How many replicas

```text theme={null}
replicas = max(2, ceil(peak_docs_per_s(size) / per_replica_docs_per_s(size) / 0.6) + 1)
```

* Divide by **0.6** to keep replicas near the 60% CPU autoscaling target rather than at saturation, where p95 roughly doubles (5,250 characters: 1.6 s → 3.1 s).
* **+1** keeps capacity during a rollout and through an AZ loss — rollouts take one replica out at a time.
* Mixed traffic: sum `peak_docs_per_s ÷ per_replica_docs_per_s` across document sizes before dividing.

Example: 2 docs/s of 5,250-character documents at peak → `2 / 1.26 / 0.6 = 2.6` → 3, plus 1 → **4 detect replicas**.

Rehydration does no model inference on the request path. Two small replicas are enough for most workloads.

## Instances

| | Default | Notes |
| - | - | - |
| Instance type, ECS | `c9g.xlarge` (4 vCPU, arm64) | `c8g.xlarge` where C9g isn't offered. The numbers above are for `c9g.xlarge`. |
| Instance type, EKS | `c8g.xlarge` (the chart's preferred node) | Graviton5 (`c9g`) nodes hit a [VPC CNI network policy agent bug](https://github.com/aws/aws-network-policy-agent/issues/686) that can leave rehydrate callers blocked. Throughput on `c8g` isn't in the table above — measure it. |
| Detect task / pod | ECS: `cpu 4096`, memory 3 GiB reserved / 4 GiB limit. EKS: CPU `3500m` request / `4` limit, memory `3Gi` / `4Gi`. | One 4-thread worker; one replica per node. |
| Rehydrate | ECS: `cpu 1024`, memory 3 GiB / 4 GiB. EKS: CPU `1` / `2`, memory `3Gi` / `4Gi`. | Memory matches detect because both load the model before they're ready. |
| Nodes on EKS | Four `c8g.xlarge` with rehydration on (two per AZ); two without | Each detect pod fills a node, and rehydrate's zone spread needs a free node in each AZ. |
| Platform | ECS on EC2, or EKS managed node groups | Fargate isn't supported. |

## Scaling

* **ECS (CloudFormation, Terraform):** target tracking on CPU is on by default — `DetectCpuTargetPercent` / `detect_cpu_target_percent` = `60`, between `DetectDesiredCount` and `DetectMaxCount` (`2`–`10`). 60% is of the task's 4096 units (2.4 vCPU). The ASG's managed scaling adds instances (`AsgMaxSize`, default `12`).
* **EKS (Helm):** `detect.autoscaling.enabled=true` adds an HPA, target 60% CPU, `2`–`10` replicas. HPA utilization is measured against the **request**, so 60% of `3500m` is 2.1 cores. You need Karpenter or Cluster Autoscaler for new pods to get nodes.
* **Don't scale on memory.** The worker's memory is dominated by the model and is flat with load.

Turn my traffic numbers into a replica count and autoscaling settings.

Size a Tenet PII Engine (Enterprise) detect service for my workload using the measured numbers on [https://docs.tenetlabs.com/pii-engine/operate/sizing](https://docs.tenetlabs.com/pii-engine/operate/sizing.md). Do not invent other benchmark numbers.

Ask me for: platform (EKS Helm or ECS CloudFormation/Terraform); peak documents per second; the distribution of document lengths in characters (or a sample file I can point you at — then compute the distribution with a script, never printing the text); Region (to check c9g.xlarge availability with `aws ec2 describe-instance-type-offerings`).

1. Group my documents by length around the measured sizes, using the per-replica throughput of the nearest one (150 characters: 29, 2,000: 3.3, 5,250: 1.26, 16,000: 0.40 docs/s per replica on c9g.xlarge). Flag anything above 16,000 characters as outside the measured range.
2. Compute replicas = max(2, ceil(Σ peak\_docs\_per\_s(size)/throughput(size) / 0.6) + 1). Show the arithmetic.
3. Produce the exact settings: Helm values (detect.replicaCount, detect.autoscaling.minReplicas/maxReplicas, and the node count: one c8g.xlarge per detect pod plus two for rehydrate) or CloudFormation/Terraform inputs (DetectDesiredCount/detect\_desired\_count, DetectMaxCount/detect\_max\_count, AsgMaxSize/asg\_max\_size ≥ DetectMaxCount + RehydrateDesiredCount).
4. State the conditions the numbers were measured under (an earlier image, c9g.xlarge, before VPC Lattice; EKS defaults to c8g.xlarge, which wasn't measured) and recommend a load test of the image I deploy on my own traffic, through VPC Lattice with reused connections, before production.

## Gotchas

* **A replica fills its node.** Rollouts replace in place, so capacity drops by one replica (ECS: by half at the default 50% minimum healthy) during a deploy. [Upgrades](https://docs.tenetlabs.com/pii-engine/operate/upgrades.md#capacity-during-a-rollout).
* **Latency grows with queueing, not just size.** Past saturation, extra concurrency only adds wait time: throughput stays flat while p95 keeps climbing. In the measurement, documents of 2,000 characters and up saturated at about 2 in-flight requests per replica — cap client concurrency near that.
* **Reuse connections.** A client that opens a new connection per request pays a TLS handshake each time. The `tenet-pii-lattice` client keeps one connection open per client.
* **Usage records show your real length mix.** The counts-only usage records report documents by length per hour. [Monitoring](https://docs.tenetlabs.com/pii-engine/operate/monitoring.md#usage-records).

## Links

* [Monitoring](https://docs.tenetlabs.com/pii-engine/operate/monitoring.md)
* [Upgrades](https://docs.tenetlabs.com/pii-engine/operate/upgrades.md)
* [Deploy on EKS with Helm](https://docs.tenetlabs.com/pii-engine/deploy/eks-helm.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.