Repository navigation
Description
Company
ClickHouse
Component
Knowledge (documents)
Describe the situation
The sources read of ops.incidents (server/knowledge/store/sources.py::failing_sources) takes a source's last-turn status from the detail of its sync state row in loom.code_index_state. That detail also holds the source's map of mined documents, up to LOOM_KNOWLEDGE_SOURCE_MAX_DOCUMENTS entries (50,000 by default, at most 200,000). So each read parses every one of the org's source states whole, and its cost grows with the org's mined documents, not with its failing sources: about 23 ms and 54 MB read per million mined entries over merged parts. Each sync turn writes a new version of its source's state, and mining another when its map changes, so between merges FINAL reads every unmerged version: three versions of 20 sources read 234 MB with a 253 MB memory peak, against 62 MB and 88 MB merged, in about the same time. The statement also reads the org's code-index state rows in the granules it selects, which share the table.
At the op's 250 ms p99 budget and the default cap, an org past about 200 sources passes the budget on each call that misses the 60 s cache, once a minute per org and reach in each process. Past about 1,700 such sources (extrapolated), the read passes its 2 s bound (LOOM_READINESS_CHECK_TIMEOUT_S): every answer reads sources: unread, while each process still runs a 2 s statement per org and reach every minute. At 200,000 entries a source, the two figures are about 50 and 430 sources.
Does it reproduce on the latest release or main?
Yes, on main: the statement is _failing_sources_sql in server/knowledge/store/sources.py as merged in #2134. Measured on clickhouse-local over the production DDL, not on a running server.
How to reproduce
measure_sources.py N DOCS [VERSIONS] from the body of #2134 builds one org's N sources, each with DOCS entries in its mined map, beside 50 code-index state rows of 200 KB, and runs the statement with no collection clause on clickhouse-local over the production DDL (tests/unit/clickhouse_local.py::ddl). Five runs each, no deployment's data:
| Sources | Entries a source | Time | Read | Memory peak |
|---|---|---|---|---|
| 20 | 50,000 | 33–39 ms | 62 MB | 88 MB |
| 100 | 50,000 | 120–126 ms | 272 MB | 153 MB |
| 400 | 50,000 | 444–473 ms | 1,076 MB | 388 MB |
| 20, 3 unmerged versions each | 50,000 | 31–53 ms | 234 MB | 253 MB |
Expected performance
The read costs the same whatever the size of the mined map: a source's status kept where the read does not parse the map, such as its own column or a small state row written with each turn. A change to the write path keeps builds N-1 and N side by side: a state an N-1 replica wrote has no such field until N syncs it again.
Environment
ClickHouse local 26.7.3.19 on a laptop; no loom report, since it was not measured on a server.
Related issues and pull requests
Caused by: #2134
Additional context
An agent found this while reviewing #2134 and measured it on clickhouse-local; no person has reproduced it on a server. The read is cached for 60 s per org and reach, so the cost is paid once a minute per org, reach and process, not on every call.
Redaction
- I removed tokens, keys, passwords and personal or customer data from everything above.
Activity