-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: coalesce scheduling of reads to speed up random access (#2636)
Should fix #2629, addresses #1959 1. Earlier on randomly accessing rows, each request for a row was being scheduled separately, which increased overhead, especially on large datasets. This PR coalesces take scheduling when requests are within `block_size` distance from each other. The block size is determined based on the system. 2. The binary scheduler was also scheduling decoding of all indices individually. This updates the binary scheduler so that it schedules all offsets at once. These are then processed to determine which bytes to decode like before. 3. A script we can use to compare v1 vs v2 performance is added as `test_random_access.py`. Specifically, on the lineitem dataset (same file from the issue above): - v1 query time: `0.12s` - v2 query time (before): `2.8s`. - v2 query time (after (1)): `0.54s`. - v2 query time (after (1) and (2)): `0.02s`.
- Loading branch information
Showing
3 changed files
with
139 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# SPDX-FileCopyrightText: Copyright The Lance Authors | ||
|
||
from datetime import datetime | ||
|
||
import lance | ||
import pyarrow.parquet as pq | ||
from lance.tracing import trace_to_chrome | ||
|
||
trace_to_chrome(file="/tmp/foo.trace", level="debug") | ||
|
||
# This file compares the performance of lance v1 and v2 on the lineitem dataset, | ||
# specifically for random access scans | ||
|
||
tab = pq.read_table("~/lineitemsf1.snappy.parquet") | ||
dsv1 = lance.write_dataset(tab, "/tmp/lineitem.lancev1", use_legacy_format=True) | ||
dsv2 = lance.write_dataset(tab, "/tmp/lineitem.lancev2", use_legacy_format=False) | ||
|
||
dsv1 = lance.dataset("/tmp/lineitem.lancev1") | ||
dsv2 = lance.dataset("/tmp/lineitem.lancev2") | ||
|
||
start = datetime.now() | ||
dsv1.to_table(filter="l_shipmode = 'FOB'", limit=10000) | ||
duration = (datetime.now() - start).total_seconds() | ||
print(f"V1 query time: {duration}s") | ||
|
||
start = datetime.now() | ||
dsv2.to_table(filter="l_shipmode = 'FOB'", limit=10000) | ||
duration = (datetime.now() - start).total_seconds() | ||
print(f"V2 query time: {duration}s") | ||
|
||
start = datetime.now() | ||
dsv1.take([1, 40, 100, 130, 200]) | ||
duration = (datetime.now() - start).total_seconds() | ||
print(f"V1 query time: {duration}s") | ||
|
||
start = datetime.now() | ||
dsv2.take([1, 40, 100, 130, 200]) | ||
duration = (datetime.now() - start).total_seconds() | ||
print(f"V2 query time: {duration}s") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters