01 · medic/cht-core
CHT Core
Making a large CouchDB deployment cheaper to run, without changing what health workers see.
Core is an offline-first framework. Each user's device holds its own copy of their data and replicates it with a CouchDB server, so care continues when the network doesn't. On large deployments, the server's map/reduce indexes become a major cost, because every document written has to pass through every view.
So I looked at the largest views on a sample of instances and asked what each one was really for. Several were expensive to keep and barely used on the server.
| View | Why it was expensive | What replaced it | PR |
|---|---|---|---|
doc_summaries_by_id |
The largest view sampled: large values for every report and contact. | Summaries calculated on demand, as offline users already did. | #10831 |
doc_by_type |
Emitted every document, but was only queried for rare types. | The most common document types are no longer indexed. | #10822 |
docs_by_id_lineage |
Emitted once for every ancestor of every document with a contact. | Two _all_docs calls: the child, then its ancestors. |
#11319 |
tasks_by_contact |
A large index of tasks that only the offline rules engine used. | Removed from the server. | #11231 |
Also under load
- Purging was exhausting the search heap. One purge query could ask Nouveau for 200,000 hits per shard, or up to 2.4 million at once on a 12-shard database. It now makes a single request capped at 20,000. #11494
- Search was a bottleneck on the sync path. In clustered Kubernetes deployments, all Nouveau traffic went to the first CouchDB node. Each node now talks to its own instance. #11126
-
Purged-document lookups slowed down as purge databases grew.
I replaced a filtered
_changesrequest with_all_docsby key. #10396 -
Moving code off direct view queries.
I added document-returning
getPageandgetAllmethods, and a phone number qualifier, tocht-datasource. #11214, #11249