upsert_points deep-clones the whole request on every call, not only on retry
@NullSense がすでに取り組んでいます。
2026年11月24日 から。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- grpc, rust
- 領域
- backend, database, performance
調査の方向性
The clone sits in upsert_points in src/qdrant_client/points.rs, inside the closure passed to with_points_client, and the retry lives in ChannelPool::with_channel. Start by reading how that closure is called and how tonic consumes the request, then run the counting-allocator reproduction from the issue against a local Qdrant. Done means the per-call allocations drop without changing retry behaviour, with the chosen design (encoded Bytes, FnOnce path, or an owned variant) justified.
索引モデルが issue の本文から書いたものです。
説明
Qdrant::upsert_points deep-clones the whole UpsertPoints request on every call, including the first attempt, even when no retry happens.
Version: qdrant-client 1.20.0 (same code on master today).
https://github.com/qdrant/rust-client/blob/v1.20.0/src/qdrant_client/points.rs#L103-L112
pub async fn upsert_points(&self, request: impl Into<UpsertPoints>) -> QdrantResult<PointsOperationResponse> {
let request = &request.into();
self.with_points_client(|mut points_api| async move {
Ok(points_api.upsert(request.clone()).await?.into_inner())
})
.await
}
ChannelPool::with_channel takes an Fn and calls it once, then a second time only on Internal/Unavailable/Cancelled/Unknown. The request.clone() sits inside the closure, so the happy path pays for a full copy of every vector, sparse vector and payload Value in the batch. For large write batches that copy is as big as the request itself.
Reproduction
Against a local Qdrant v1.20.2, 256 points with 768-dim dense vectors and a ~1 KB payload each. It compares Qdrant::upsert_points with the generated PointsClient::upsert, which takes the same request by value:
[dependencies]
qdrant-client = "=1.20.0"
tokio = { version = "1", features = ["rt", "macros"] }
serde_json = "1"
use std::alloc::{GlobalAlloc, Layout, System};
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use qdrant_client::qdrant::points_client::PointsClient;
use qdrant_client::qdrant::{CreateCollectionBuilder, Distance, PointStruct, UpsertPointsBuilder, VectorParamsBuilder};
use qdrant_client::{Payload, Qdrant};
struct Counting;
static BYTES: AtomicUsize = AtomicUsize::new(0);
static COUNT: AtomicUsize = AtomicUsize::new(0);
unsafe impl GlobalAlloc for Counting {
unsafe fn alloc(&self, l: Layout) -> *mut u8 {
BYTES.fetch_add(l.size(), Relaxed);
COUNT.fetch_add(1, Relaxed);
System.alloc(l)
}
unsafe fn dealloc(&self, p: *mut u8, l: Layout) { System.dealloc(p, l) }
}
#[global_allocator]
static A: Counting = Counting;
const DIM: usize = 768;
fn points(start: u64, n: u64) -> Vec<PointStruct> {
(start..start + n)
.map(|i| {
let payload = Payload::try_from(serde_json::json!({
"text": "x".repeat(1000), "path": format!("src/file_{i}.rs"), "line": i,
})).unwrap();
PointStruct::new(i, vec![0.1f32; DIM], payload)
})
.collect()
}
fn snapshot() -> (usize, usize) { (BYTES.load(Relaxed), COUNT.load(Relaxed)) }
#[tokio::main(flavor = "current_thread")]
async fn main() {
let url = std::env::args().nth(1).unwrap(); // e.g. http://localhost:6334
let client = Qdrant::from_url(&url).build().unwrap();
let _ = client.delete_collection("repro").await;
client.create_collection(CreateCollectionBuilder::new("repro")
.vectors_config(VectorParamsBuilder::new(DIM as u64, Distance::Cosine))).await.unwrap();
let mut raw = PointsClient::connect(url.clone()).await.unwrap();
for round in 0..3u64 {
let base = round * 10_000;
let req = UpsertPointsBuilder::new("repro", points(base, 256)).wait(true).build();
let (b0, c0) = snapshot();
client.upsert_points(req).await.unwrap();
let (b1, c1) = snapshot();
let req = UpsertPointsBuilder::new("repro", points(base + 5_000, 256)).wait(true).build();
let (b2, c2) = snapshot();
raw.upsert(req).await.unwrap();
let (b3, c3) = snapshot();
println!("round {round}: Qdrant::upsert_points {:.2} MB / {} allocs | PointsClient::upsert {:.2} MB / {} allocs",
(b1 - b0) as f64 / 1e6, c1 - c0, (b3 - b2) as f64 / 1e6, c3 - c2);
}
}
Release build, counting allocator (not DHAT), measured locally:
round 0: Qdrant::upsert_points 5.47 MB / 1901 allocs | PointsClient::upsert 4.21 MB / 62 allocs
round 1: Qdrant::upsert_points 5.41 MB / 1836 allocs | PointsClient::upsert 4.20 MB / 40 allocs
round 2: Qdrant::upsert_points 5.41 MB / 1836 allocs | PointsClient::upsert 4.20 MB / 40 allocs
That's about 1.2 MB and ~1,800 extra allocations per 256-point batch, roughly 7 allocations per point, all from the clone.
Real workload
In a document indexer that writes chunk embeddings to Qdrant, over a run of 1,551 documents, measured with DHAT: this clone was 1.28 GB in 4.37 M allocations, the largest allocation site on the Qdrant write path.
Suggested fix
Clone-on-retry alone doesn't work as written: tonic consumes the request and the returned Status doesn't give it back, so a copy has to exist before the first attempt. Some options:
- Encode the request once (
prost::Message::encode_to_vecintoBytes) and send it through a pass-through codec. A retry resends the sameBytes, which is a refcount bump. This keeps the current retry behaviour with no deep clone. - Give
with_channelanFnOncepath for callers that don't want the reconnect retry (a per-call option or a client config flag), so the request is moved into the single attempt. - At minimum, a variant like
upsert_points_ownedthat skips the retry and moves the request, documented as such.
The same request.clone() inside with_points_client appears in the other points methods too (update_batch, update_vectors, and so on), and upsert_points_chunked does points.clone() followed by chunk.to_vec(), which copies the points twice. Upsert is just where it costs the most for us.
- 主要言語
- Rust
- スター
- 425
- フォーク
- 89
- 平均マージ
- 2時間 48分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
qdrant/rust-client のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
qdrant/rust-client#320 ·
-
Option to set TLS domain name and :authority origin (client behind a tunnel/proxy)再び着手できるかも @inamdarmihir が 36 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
qdrant/rust-client#306 · コメント 1 件 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
qdrant/rust-client#289 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 30/100
qdrant/rust-client#272 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
qdrant/rust-client#267 · コメント 1 件 · リアクション 2 件 ·
qdrant/rust-client の issue をすべて見る
似ている issue
-
app bug session
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
marketing
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
macOS autosubmit enable passes unsupported --wait to launchctl bootout対応中かも @iqdoctor が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
junhoyeo/tokscale#1713 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信