[Bug] BanyanDB stream query on a hot entity scans all its rows despite a small limit

オープン
#14,261 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@hanahmily がすでに取り組んでいます。

2026年11月23日 から。

評価

この issue はまだ評価されていません。

説明

bug
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 (100663296 bytes).
  • Group sw_recordsLog, stream log, shardNum: 2, 1-day segments. The entity is service_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
email 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 orderBy removed, 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:

  1. Its memory charge should follow offset + limit plus a bounded number of cursors, not the number of rows the series has in the range.
  2. A hot service's 6h or 24h log query, a common OAP UI action, should not fail with RESOURCE_EXHAUSTED.
How to reproduce
  1. 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.
  2. Send service_id = <hot>, ORDER BY timestamp DESC, limit 20 for 1h, 2h, 4h, 5h and 6h ranges.
  3. Latency grows with the range, and the query fails with per_query_limit at around 200k matched rows under the 96 MiB per-query allowance.
  4. 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 streamVecScan in banyand/stream/query_vectorized.go says the scan emits every matching row and does not stop at MaxElementSize; 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 DESC merge 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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/skywalking のほかの issue

apache/skywalking の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。