From e185dc86466da1e1163b3720d0a4c10dbf288132 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Sat, 28 Nov 2026 03:21:37 +0800 Subject: [PATCH] perf: raise the default Blob V2 direct-read threshold to 32 MiB (#5248) Enterprise SDKs use an inclusive 32 MiB default for eligible Blob V2 direct reads. The paired field comparison with the 10 MiB SDK default measured higher direct-read latency at 10 and 16 MiB. At 32 MiB, the interval for the latency difference spanned zero. [SDK version used in the field comparison](https://github.com/lancedb/lancedb/pull/5247) The earlier mixed-load test measured lower Plan Executor cache pressure with direct reads enabled at the 10 MiB cutoff. That result covers the tested size mix. With the 32 MiB cutoff, reads from 10 MiB up to (but excluding) 32 MiB go through the proxy, so the impact on executor traffic and cache pressure depends on the workload's size distribution. The existing internal override still takes precedence. Direct reads keep the 16 MiB part size. The Node binding test verifies proxy routing one byte below the default and two contiguous object-store ranges with a matching SHA-256 at exactly 32 MiB. --- docs/web/management/table.mdx | 5 +++ nodejs/__test__/blob_open.test.ts | 59 ++++++++++++++++---------- python/python/lancedb/table.py | 30 ++++++------- rust/lancedb/src/remote/client.rs | 5 +-- rust/lancedb/src/remote/table/blobs.rs | 2 +- rust/lancedb/src/table.rs | 41 +++++++++--------- 6 files changed, 78 insertions(+), 64 deletions(-) diff --git a/docs/web/management/table.mdx b/docs/web/management/table.mdx index 9c836c9d3..23e666cc8 100644 --- a/docs/web/management/table.mdx +++ b/docs/web/management/table.mdx @@ -830,6 +830,11 @@ The other fetch methods load bytes directly: slice per request, in order. A request list can repeat a row to read more than one slice of that blob. +On Enterprise clusters with direct Blob reads enabled, the SDK's default +threshold for eligible Blob V2 payloads or ranges is **32 MiB (inclusive)**. +Smaller reads go through LanceDB. Direct reads use parts of up to 16 MiB and +require the client to reach the object-store endpoint as well as LanceDB. + {BlobApiFetch} diff --git a/nodejs/__test__/blob_open.test.ts b/nodejs/__test__/blob_open.test.ts index 34d1c764c..e3959617d 100644 --- a/nodejs/__test__/blob_open.test.ts +++ b/nodejs/__test__/blob_open.test.ts @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright The LanceDB Authors +import { createHash } from "node:crypto"; import { createServer } from "node:http"; import type { AddressInfo } from "node:net"; import { @@ -14,6 +15,11 @@ jest.setTimeout(15000); const IDENTITY = `v1:${"a".repeat(64)}`; const MIB = 1024 * 1024; +const DIRECT_READ_BYTES = BigInt(32 * MIB); + +function sha256(bytes: Buffer) { + return createHash("sha256").update(bytes).digest("hex"); +} function descriptor(size: bigint): BlobDescriptor { return { @@ -54,22 +60,24 @@ async function withOpenServer( state: { directStatus: number; blobLocationsCalls: number; - objectCalls: number; + objectRanges: string[]; proxyCalls: number; lastLocationBody: Record | undefined; }, + payload: Buffer, ) => Promise, - size: bigint = 10n * BigInt(MIB), + size: bigint = DIRECT_READ_BYTES, ) { let port = 0; const state = { directStatus: 200, blobLocationsCalls: 0, - objectCalls: 0, + objectRanges: [] as string[], proxyCalls: 0, lastLocationBody: undefined as Record | undefined, }; const payload = Buffer.alloc(Number(size), 0x61); + payload.fill(0x62, Math.floor(payload.length / 2)); const server = createServer(async (req, res) => { const url = req.url ?? ""; if (url === "/v1/table/test/describe/") { @@ -117,8 +125,8 @@ async function withOpenServer( return; } if (url.startsWith("/object")) { - state.objectCalls++; const range = req.headers.range ?? ""; + state.objectRanges.push(range); const match = /^bytes=(\d+)-(\d+)$/.exec(range); if (match === null) { res.writeHead(416).end(); @@ -169,7 +177,7 @@ async function withOpenServer( }); const table = await db.openTable("test"); try { - await run(db, table, state); + await run(db, table, state, payload); } finally { await new Promise((resolve) => { server.closeAllConnections(); @@ -179,19 +187,25 @@ async function withOpenServer( } describe("openBlobFile", () => { - it("opens a large descriptor through the direct resolver and reads bytes", async () => { - await withOpenServer(async (_db, table, state) => { - const handle = (await table.openBlobFile(descriptor(10n * BigInt(MIB))))!; + it("routes reads at the inclusive default direct threshold", async () => { + await withOpenServer(async (_db, table, state, payload) => { + const handle = (await table.openBlobFile(descriptor(DIRECT_READ_BYTES)))!; expect(handle).not.toBeNull(); - // Below the per-read threshold the same handle stays on the proxy. - expect(await handle.readRange(0n, 4n)).toEqual(Buffer.alloc(4, 0x61)); + const below = await handle.readRange(0n, DIRECT_READ_BYTES - 1n); + expect(below.length).toBe(payload.length - 1); + expect(sha256(below)).toBe(sha256(payload.subarray(0, -1))); expect(state.proxyCalls).toBe(1); - expect(state.objectCalls).toBe(0); - const large = await handle.readRange(0n, 10n * BigInt(MIB)); - expect(large.length).toBe(10 * MIB); - expect(large.equals(Buffer.alloc(10 * MIB, 0x61))).toBe(true); + expect(state.objectRanges).toEqual([]); + + const exact = await handle.readRange(0n, DIRECT_READ_BYTES); + expect(exact.length).toBe(payload.length); + expect(sha256(exact)).toBe(sha256(payload)); + const partBytes = 16 * MIB; + expect(state.objectRanges.sort()).toEqual([ + `bytes=0-${partBytes - 1}`, + `bytes=${partBytes}-${2 * partBytes - 1}`, + ]); expect(state.blobLocationsCalls).toBe(1); - expect(state.objectCalls).toBe(1); expect(state.proxyCalls).toBe(1); expect(state.lastLocationBody).toMatchObject({ version: 46, @@ -209,15 +223,14 @@ describe("openBlobFile", () => { }); it("falls back to the proxy when the resolver returns 503", async () => { - await withOpenServer(async (_db, table, state) => { + await withOpenServer(async (_db, table, state, payload) => { state.directStatus = 503; - const handle = (await table.openBlobFile(descriptor(10n * BigInt(MIB))))!; + const handle = (await table.openBlobFile(descriptor(DIRECT_READ_BYTES)))!; expect(handle).not.toBeNull(); - const large = await handle.readRange(0n, 10n * BigInt(MIB)); - expect(large.length).toBe(10 * MIB); - expect(large.equals(Buffer.alloc(10 * MIB, 0x61))).toBe(true); + const large = await handle.readRange(0n, DIRECT_READ_BYTES); + expect(large.equals(payload)).toBe(true); expect(state.blobLocationsCalls).toBe(1); - expect(state.objectCalls).toBe(0); + expect(state.objectRanges).toEqual([]); expect(state.proxyCalls).toBe(1); await handle.close(); }); @@ -228,7 +241,7 @@ describe("openBlobFile", () => { const handle = (await table.openBlobFile(descriptor(BigInt(MIB))))!; expect(await handle.readRange(0n, 4n)).toEqual(Buffer.alloc(4, 0x61)); expect(state.blobLocationsCalls).toBe(0); - expect(state.objectCalls).toBe(0); + expect(state.objectRanges).toEqual([]); expect(state.proxyCalls).toBe(1); await handle.close(); }, BigInt(MIB)); @@ -239,7 +252,7 @@ describe("openBlobFile", () => { const handles = []; for await (const handle of table.openBlobFiles([ null, - descriptor(10n * BigInt(MIB)), + descriptor(DIRECT_READ_BYTES), null, ])) { handles.push(handle); diff --git a/python/python/lancedb/table.py b/python/python/lancedb/table.py index d7486af09..e325e7361 100644 --- a/python/python/lancedb/table.py +++ b/python/python/lancedb/table.py @@ -2887,11 +2887,11 @@ class Table(ABC): ``table.take_offsets(offsets, with_row_id=True)`` first and pass the resulting ``_rowid`` values. - On Enterprise clusters that enable direct Blob reads, large values and - ranges may be fetched from short-lived object-store URLs. The client then - needs network access to the object-store endpoint, including private - endpoint routing, DNS, TLS trust and egress rules, in addition to the - LanceDB endpoint. Small reads stay on the LanceDB proxy. + On Enterprise clusters that enable direct Blob reads, eligible Blob V2 + values of at least 32 MiB may use short-lived object-store URLs. + Smaller values go through LanceDB. Direct reads also require + network access to the object store, including endpoint routing, DNS, + TLS trust, and egress rules. Blobs inside lists cannot be fetched by row id yet. LanceDB Enterprise limits each request to 1024 row IDs and 64 MiB of blob @@ -2926,11 +2926,11 @@ class Table(ABC): One missing or deleted row ID rejects the entire batch; no partial results are returned. - On Enterprise clusters that enable direct Blob reads, large values and - ranges may be fetched from short-lived object-store URLs. The client then - needs network access to the object-store endpoint, including private - endpoint routing, DNS, TLS trust and egress rules, in addition to the - LanceDB endpoint. Small reads stay on the LanceDB proxy. + On Enterprise clusters that enable direct Blob reads, eligible Blob V2 + ranges of at least 32 MiB may use short-lived object-store URLs. + Smaller ranges go through LanceDB. Direct reads also require + network access to the object store, including endpoint routing, DNS, + TLS trust, and egress rules. Row IDs can be obtained from a query with ``with_row_id(True)``. LanceDB Enterprise uses the batched endpoint when the server advertises support, partitioning at 1024 ranges and 64 MiB, including individual @@ -2959,11 +2959,11 @@ class Table(ABC): ``buffer_size`` controls sequential read-ahead in bytes (default 512 KiB). Set it to 0 for sparse reads. Explicit range reads bypass this buffer. - On Enterprise clusters that enable direct Blob reads, large values and - ranges may be fetched from short-lived object-store URLs. The client then - needs network access to the object-store endpoint, including private - endpoint routing, DNS, TLS trust and egress rules, in addition to the - LanceDB endpoint. Small reads stay on the LanceDB proxy. + On Enterprise clusters that enable direct Blob reads, eligible Blob V2 + reads of at least 32 MiB may use short-lived object-store URLs. + Smaller reads go through LanceDB. Direct reads also require + network access to the object store, including endpoint routing, DNS, + TLS trust, and egress rules. ``_rowid`` values stay valid after compaction when the table has stable row ids. One missing or deleted row ID rejects the entire batch; no partial diff --git a/rust/lancedb/src/remote/client.rs b/rust/lancedb/src/remote/client.rs index c9e9e9516..d900ecc65 100644 --- a/rust/lancedb/src/remote/client.rs +++ b/rust/lancedb/src/remote/client.rs @@ -29,9 +29,8 @@ const REQUEST_ID_HEADER: HeaderName = HeaderName::from_static("x-request-id"); const DEFAULT_BLOB_REQUEST_CONCURRENCY: usize = 8; const OBJECT_STORE_POOL_IDLE_TIMEOUT: Duration = Duration::from_secs(30); const OBJECT_STORE_MAX_ATTEMPTS: u8 = 2; -/// M1 prototype routing threshold for direct Blob reads. It stays internal -/// until the acceptance benchmark establishes the right default. -const DEFAULT_BLOB_PRESIGN_THRESHOLD_BYTES: u64 = 10 * 1024 * 1024; +/// Minimum logical read size for presigned Blob V2 reads by default. +const DEFAULT_BLOB_PRESIGN_THRESHOLD_BYTES: u64 = 32 * 1024 * 1024; pub fn redact_sensitive_headers(headers: &mut HeaderMap) { const SENSITIVE_HEADERS: [&str; 5] = [ diff --git a/rust/lancedb/src/remote/table/blobs.rs b/rust/lancedb/src/remote/table/blobs.rs index e21f60c89..553306a94 100644 --- a/rust/lancedb/src/remote/table/blobs.rs +++ b/rust/lancedb/src/remote/table/blobs.rs @@ -5653,7 +5653,7 @@ mod tests { } #[tokio::test] - async fn direct_blob_file_translates_physical_offsets_and_preserves_nulls() { + async fn direct_blob_file_honors_internal_threshold_and_translates_physical_offsets() { let object_requests = Arc::new(StdMutex::new(Vec::new())); let captured = object_requests.clone(); let table = diff --git a/rust/lancedb/src/table.rs b/rust/lancedb/src/table.rs index 296061e64..cdb28ff13 100644 --- a/rust/lancedb/src/table.rs +++ b/rust/lancedb/src/table.rs @@ -1552,12 +1552,11 @@ impl Table { /// # } /// ``` /// - /// On LanceDB Enterprise clusters that enable direct Blob reads, large - /// values and individual ranges may be fetched from short-lived object-store - /// URLs instead of the LanceDB proxy. Clients then need network access to - /// the object-store endpoint, including private endpoint routing, DNS, TLS - /// trust and egress rules, in addition to the LanceDB endpoint. Small reads - /// stay on the LanceDB proxy. + /// On LanceDB Enterprise clusters that enable direct Blob reads, eligible + /// Blob V2 values of at least 32 MiB may use short-lived object-store URLs. + /// Smaller values go through LanceDB. Direct reads also require + /// network access to the object store, including endpoint routing, DNS, + /// TLS trust, and egress rules. /// Blobs inside lists cannot be fetched by row id. Returns /// [`Error::InvalidInput`] for those paths, when the column does not exist, /// or when it is not a blob column. Returns [`Error::NotSupported`] on @@ -1609,12 +1608,11 @@ impl Table { /// # } /// ``` /// - /// On LanceDB Enterprise clusters that enable direct Blob reads, large - /// values and individual ranges may be fetched from short-lived object-store - /// URLs instead of the LanceDB proxy. Clients then need network access to - /// the object-store endpoint, including private endpoint routing, DNS, TLS - /// trust and egress rules, in addition to the LanceDB endpoint. Small reads - /// stay on the LanceDB proxy. + /// On LanceDB Enterprise clusters that enable direct Blob reads, eligible + /// Blob V2 ranges of at least 32 MiB may use short-lived object-store URLs. + /// Smaller ranges go through LanceDB. Direct reads also require + /// network access to the object store, including endpoint routing, DNS, + /// TLS trust, and egress rules. /// Returns an error when a range is invalid, a requested row id does not /// exist, or the column is not a blob column. Returns /// [`Error::NotSupported`] on table types without blob support. @@ -1642,12 +1640,11 @@ impl Table { /// `ClientConfig::blob_request_concurrency` or the /// `LANCE_CLIENT_BLOB_REQUEST_CONCURRENCY` environment variable to tune it. /// - /// On LanceDB Enterprise clusters that enable direct Blob reads, large - /// values and individual ranges may be fetched from short-lived object-store - /// URLs instead of the LanceDB proxy. Clients then need network access to - /// the object-store endpoint, including private endpoint routing, DNS, TLS - /// trust and egress rules, in addition to the LanceDB endpoint. Small reads - /// stay on the LanceDB proxy. + /// On LanceDB Enterprise clusters that enable direct Blob reads, eligible + /// Blob V2 reads of at least 32 MiB may use short-lived object-store URLs. + /// Smaller reads go through LanceDB. Direct reads also require + /// network access to the object store, including endpoint routing, DNS, + /// TLS trust, and egress rules. /// `_rowid` values stay valid after compaction when the table has stable /// row ids. One missing or deleted row id rejects the whole request; no /// partial handles are returned. @@ -1675,10 +1672,10 @@ impl Table { /// /// The descriptor carries its table version, branch, column and row identity. /// Opening does not materialize the payload or change this table's checkout. - /// On Enterprise clusters that enable direct Blob reads, large range reads - /// may use a short-lived object-store URL; the client needs network access - /// to that endpoint in addition to the LanceDB endpoint. Small reads stay - /// on the authenticated LanceDB byte-range endpoint. + /// On Enterprise clusters that enable direct Blob reads, eligible Blob V2 + /// ranges of at least 32 MiB may use a short-lived object-store URL. + /// Direct reads require network access to the object-store endpoint. + /// Smaller ranges go through the authenticated LanceDB byte-range endpoint. /// /// ``` /// use lancedb::{Table, blob::BlobDescriptor};