Requirements and sizing
What the host needs, and the CPU, memory and disk to plan for each monthly event volume, with the PostgreSQL settings that go with each size and the queries that stay slow.
Requirements
- A Linux host with Docker Engine and the Docker Compose plugin
(
docker compose, not the olddocker-composescript). The images exist foramd64andarm64. - A domain name with an
Arecord pointing at the host. Caddy gets a Let's Encrypt certificate for it, so the host must be reachable from the internet on ports 80 and 443 while the certificate is issued and renewed. - The license key and the images that come with your contract. See Images and license key.
Add an AAAA record only after checking IPv6. A client that reaches Docker
over IPv6 is seen by Caddy as the Docker bridge gateway, unless the Docker
daemon is set up for IPv6 (for example ip6tables enabled with the userland
proxy off). Every such client would then share one rate-limit bucket.
An instance with no internet access can run from the offline package, with the limit on HTTPS described there.
Sizing
Pick the row for the number of events you expect to send in a month.
| Events per month | CPU | Memory | Disk |
|---|---|---|---|
| Up to 1 million | 2 vCPU | 4 GB | 20 GB |
| Up to 5 million | 4 vCPU | 16 GB | 80 GB |
| Up to 15 million | 8 vCPU | 32 GB | 300 GB |
What the scale test measured:
- Disk: 1.28 GB per million events (1.02 GB of table data and 0.26 GB of indexes). At 5 million events a month, a year of data is about 77 GB.
- What the disk column holds: at that rate, the disk of each row fills with
roughly 12 to 15 months of events at the top of its band (1.28 GB per million
events), before PostgreSQL's write-ahead log, backups kept on the same disk
and index rebuilds. Plan more disk to keep longer, or set
retention (for example
COHORLY_SELF_HOST_RETENTION_MONTHS=12) to cap growth. - Ingestion: 8 to 14 thousand events per second sustained on
/track. This does not limit the size you choose. - The smallest size that works for 30-day queries with a filter: 8 vCPU, 32 GB and 300 GB of disk, where filtered 30-day queries finish in under 3 seconds.
Queries that stay slow
In the scale test, a query that names one event was fast: 95th percentile up to 0.7 s over 30 days and 1.6 s over 90 days, with a warm cache. Keeping 3 or 12 months of history did not change the latency, because the events table is partitioned by month and a query reads only the months it needs.
Other queries are slower, and no size we measured serves a 90-day query with a filter in under 3 seconds:
- Filters on a property.
- The
$all_eventsselection. - A breakdown with no event chosen.
- A funnel with a filter.
- Flows.
The slowest of these took more than 110 seconds, the timeout ceiling, for a
property filter over 90 days, a filtered funnel over 90 days, a breakdown over
90 days, and flows over 30 and 90 days. A query that runs longer than
COHORLY_QUERY_TIMEOUT_MS (30 seconds by default) is cancelled and answers
504 with the code query_timeout, and one whose statement would return more
rows than COHORLY_QUERY_MAX_ROWS (100,000 by default) is stopped and answers
422 with the code query_too_large; see
Operator settings.
The first query after the database cache is cold took 24 to 84 seconds on the 90-day golden-path queries.
Limits of the test: the sizes were simulated with cgroup limits, on a machine with other containers active, on a SATA SSD, with synthetic data, and the heavy queries were measured with n between 2 and 4.
PostgreSQL settings
The compose file takes its PostgreSQL settings from .env. The scale test
recommends shared_buffers at 25% of the host's memory,
effective_cache_size at 75% and random_page_cost at 1.1.
The compose file ships three ready-made profiles that follow the first two
rules. Paste the block that matches the host into .env; the default is
small.
| Profile | Host memory | PG_SHARED_BUFFERS | PG_EFFECTIVE_CACHE_SIZE | PG_WORK_MEM | PG_MAX_CONNECTIONS | COHORLY_PG_POOL_MAX |
|---|---|---|---|---|---|---|
| small | 2 GB | 512MB | 1536MB | 8MB | 50 | 15 |
| medium | 4 to 8 GB | 1GB | 3GB | 16MB | 100 | 30 |
| large | 16 GB or more | 4GB | 12GB | 32MB | 200 | 60 |
- The
smallprofile starts the stack on a 2 GB host. That is enough to evaluate Cohorly; it is below the smallest row of the sizing table. - The 2 vCPU / 4 GB row maps to
medium, and the 4 vCPU / 16 GB row tolarge. - The
largeprofile is written for 16 GB. On the 32 GB row apply the rule:PG_SHARED_BUFFERS=8GBandPG_EFFECTIVE_CACHE_SIZE=24GB. COHORLY_PG_POOL_MAXis the pool of the API, and the error worker has its own pool (COHORLY_ERROR_WORKER_PG_POOL_MAX, default 3). Keep twice the pool value belowPG_MAX_CONNECTIONS.- Raise
PG_SHM_SIZE(default256mb) on thelargeprofile if PostgreSQL logscould not resize shared memory segment.
The compose file has no variable for random_page_cost. To set it, replace
the postgres command in a docker-compose.override.yml next to the compose
file. A command in an override replaces the one in the compose file, so
repeat every setting:
yamlservices:postgres:command:- postgres- -c- shared_buffers=${PG_SHARED_BUFFERS:-512MB}- -c- effective_cache_size=${PG_EFFECTIVE_CACHE_SIZE:-1536MB}- -c- work_mem=${PG_WORK_MEM:-8MB}- -c- max_connections=${PG_MAX_CONNECTIONS:-50}- -c- random_page_cost=1.1
Maintenance the scale test suggests
These are recommendations from the scale test, not something Cohorly does for you:
- After a restart, warm the cache with
pg_prewarm, and raiseeffective_io_concurrencyon SSD or NVMe storage. Both shorten the slow first queries. - Run
VACUUM FREEZEon the events partition of a month once that month has closed. - Run
REINDEXon a schedule for the partitions of the current month.
Event partitions are named events_pYYYY_MM.