[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分
- マージ済み PR(30日)
- 49
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 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 日以内に返信