[Bug] BanyanDB stream query on a hot entity scans all its rows despite a small limit
维护者通常 1 天内回复
@hanahmily 已经在做这个了。
开始于 2026年11月23日。
评估
这个 Issue 还没有评估数据。
描述
Search before asking
- I had searched in the issues and found no similar issues.
Apache SkyWalking Component
BanyanDB (apache/skywalking-banyandb)
What happened
On a Kubernetes cluster, a log query for a hot service gets slower as the time range grows, even with limit 20. From a 5-hour range up, it fails with query memory pool exhausted. A cold service with the same query stays at a few milliseconds whatever the range.
Environment:
- BanyanDB
8d577edf(2026-11-18, after apache/skywalking-banyandb#1483). It includes apache/skywalking-banyandb#1433, the fix for #14165. - Cluster mode on Kubernetes: 2 liaison, 2 hot, 2 warm and 1 cold data nodes. Data node limits: 4 CPU, 4 GiB memory. Per-query allowance: 96 MiB (
100663296bytes). - Group
sw_recordsLog, streamlog,shardNum: 2, 1-day segments. The entity isservice_id + service_instance_id.
Data distribution over the last hour: 90,381 rows across 22 services, very skewed.
| service | share | rows / hour |
|---|---|---|
| otel-demo::frontend-proxy | 48.5% | ~44,000 |
| otel-demo::product-catalog | 15.4% | ~14,000 |
| otel-demo::cart | 4.4% | ~4,000 |
| otel-demo::payment | 0.32% | ~290 |
| otel-demo::email | 0.16% | ~146 |
Query, shaped like OAP's log query: service_id = X, ORDER BY timestamp DESC, limit 20, projecting service_id, service_instance_id, timestamp, content_type, unique_id, endpoint_id, trace_id, content, tags. Each value is the p50 of 20 runs after 2 warm-up runs. These are client-side numbers through kubectl port-forward, so each one includes about 70 ms of network round trip (the "absent key" row is that floor).
| service | 1h | 2h | 3h | 4h | 5h | 6h | 24h |
|---|---|---|---|---|---|---|---|
| frontend-proxy (48%) | 215 ms | 409 ms | 669 ms | 966 ms | FAIL | FAIL | FAIL |
| product-catalog (15%) | 120 ms | 344 ms | 1,120 ms | ||||
| cart (4.4%) | 89 ms | 150 ms | 398 ms | ||||
| payment (0.32%) | 80 ms | 85 ms | 93 ms | ||||
| email (0.16%) | 79 ms | 81 ms | 84 ms | ||||
| absent key | 75 ms | 73 ms | 73 ms |
Every successful query returns exactly 20 rows. The cost follows how many rows the entity has in the range, not the limit. frontend-proxy fails between 4h (~176k rows) and 5h (~220k rows):
rpc error: code = ResourceExhausted desc = query memory pool exhausted: code: STATUS_RESOURCE_EXHAUSTED,
msg: execute the query plan for stream log: stream query on node data-hot-1:17912:
scan on node data-hot-1:17912 failed: code: STATUS_RESOURCE_EXHAUSTED,
msg: query memory pool exhausted: per_query_limit (limit 100663296 bytes, used 97115920, requested 4603598)
Server-side trace (trace: true, 3h range, limit 20):
| service | stream-grpc total | data-hot-0 | data-hot-1 | warm-0 / warm-1 |
|---|---|---|---|---|
| frontend-proxy | 432.3 ms | 11.9 ms (series matched=0) | 418.0 ms (series matched=1) | 10.3 ms |
| 7.2 ms | 4.3 ms (series matched=1) | 0.9 ms (series matched=0) | 0.1 ms |
The two queries differ by about 60 times on the server. Almost all of frontend-proxy's time is on data-hot-1.
Other variants we tried for frontend-proxy:
- With
orderByremoved, it still fails at 6h and 24h (used 100433919, requested 1220999). - With the projection cut to
service_id, timestamp, it still fails at 6h and 24h. So the memory is not driven by the projected columns; the time spent and the memory charged both follow the hot series' row count. - The 24h range also fails under every variant. Smaller services slow down in proportion: product-catalog takes 1.12 s at 24h, about 13 times email.
Because the hot entity is one series, the whole load lands on one shard and one node (hot-1) while hot-0 stays idle. Adding shards does not help this case.
What you expected to happen
A limit N query ordered by time should stop once it has the top N rows. Its latency and memory should stay close to the cold-service case, whatever the entity's data volume and the time range:
- Its memory charge should follow
offset + limitplus a bounded number of cursors, not the number of rows the series has in the range. - A hot service's 6h or 24h log query, a common OAP UI action, should not fail with RESOURCE_EXHAUSTED.
How to reproduce
- Use a stream with a low-cardinality entity (for example
sw_recordsLog/log), and write one entity at about 40k rows per hour (around 12 rows per second) for 6 hours or more. - Send
service_id = <hot>,ORDER BY timestamp DESC,limit 20for 1h, 2h, 4h, 5h and 6h ranges. - Latency grows with the range, and the query fails with
per_query_limitat around 200k matched rows under the 96 MiB per-query allowance. - Compare with a cold entity (around 150 rows per hour) and the same query: it stays at a few milliseconds on the server.
Anything else
This happens every time once the time range is past about 5h for frontend-proxy.
Relation to #14165: #14165 (fixed by apache/skywalking-banyandb#1433) made the lease refund a block's charge once its cursor is released and a batch's charge once the merge prunes it. The cluster runs a build with that fix, and the query still fails. So the refund is not enough here:
- The comment on
streamVecScaninbanyand/stream/query_vectorized.gosays the scan emits every matching row and does not stop atMaxElementSize; top-N is applied after the merge. That would explain why latency grows linearly (we see it from 1h to 4h): every block of the hot series in the range is decoded even when only 20 rows are kept. - We suspect the memory comes from how the parts are laid out. An
ORDER BY ts DESCmerge has to keep the current block of every part (and every segment) that overlaps the range. A hot series has large blocks (the failing request asked for ~4.6–6.5 MB for one block), so a dozen or so overlapping parts reach the 96 MiB allowance. We could not inspect the part layout on the data node, so this is not confirmed.
Possible directions:
- Use block metadata (
minTimestamp/maxTimestamp) to stop early: once N rows are held, skip blocks or parts whose time range cannot beat the current Nth row. - Read parts in time order for a single series instead of opening a cursor on every part at the same time.
Are you willing to submit a pull request to fix on your own?
- Yes I am willing to submit a pull request on my own!
Code of Conduct
- I agree to follow this project's Code of Conduct
- 主要语言
- Java
- 星标
- 25k
- 派生
- 6.6k
- 平均合并
- 10 小时 45 分钟
- 30 天内合并 PR
- 49
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/skywalking 的其他 Issue
-
[Bug] [BanyanDB] timestamp.ParseDuration silently drops everything after "d"可能已有人在做 @soujasK 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 83/100
apache/skywalking#14287 ·
维护者通常 1 天内回复
-
[BanyanDB] Let trace queries exclude the raw span from results可能已有人在做 @hanahmily 今天认领。 未关闭enhancement
apache/skywalking#14288 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[BanyanDB] Data race and nil-pointer panic: measure write during standalone shutdown after segment close可能已有人在做 @hanahmily 今天认领。 未关闭bug
apache/skywalking#14285 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
apache/skywalking#14283 · 1 条评论 ·
维护者通常 1 天内回复
-
[BanyanDB] Store trace binary tags only in core storage, not in secondary index (sidx)可能已有人在做 @hanahmily 今天认领。 未关闭enhancement
apache/skywalking#14282 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 apache/skywalking 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
testng-team/testng#3672 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 78/100
eclipse-edc/IdentityHub#1296 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
cloudfoundry/uaa#4194 ·
维护者通常 1 天内回复
-
area: ui priority: medium
难度 2/5 1-3 小时 新手友好度 83/100
tetsuji16/microProject#1721 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复