Skip to content

Commit 67e46cd

Browse files
perf: Scale read stream workers to cpu count (#2135)
1 parent 9c6aa8e commit 67e46cd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

bigframes/session/bq_caching_executor.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import annotations
1616

1717
import math
18+
import os
1819
import threading
1920
from typing import Literal, Mapping, Optional, Sequence, Tuple
2021
import warnings
@@ -58,7 +59,7 @@
5859
MAX_SUBTREE_FACTORINGS = 5
5960
_MAX_CLUSTER_COLUMNS = 4
6061
MAX_SMALL_RESULT_BYTES = 10 * 1024 * 1024 * 1024 # 10G
61-
62+
_MAX_READ_STREAMS = os.cpu_count()
6263

6364
SourceIdMapping = Mapping[str, str]
6465

@@ -323,7 +324,10 @@ def _export_gbq(
323324
self.bqclient.update_table(table, ["schema"])
324325

325326
return executor.ExecuteResult(
326-
row_iter.to_arrow_iterable(),
327+
row_iter.to_arrow_iterable(
328+
bqstorage_client=self.bqstoragereadclient,
329+
max_stream_count=_MAX_READ_STREAMS,
330+
),
327331
array_value.schema,
328332
query_job,
329333
total_bytes_processed=row_iter.total_bytes_processed,
@@ -668,7 +672,8 @@ def _execute_plan_gbq(
668672

669673
return executor.ExecuteResult(
670674
_arrow_batches=iterator.to_arrow_iterable(
671-
bqstorage_client=self.bqstoragereadclient
675+
bqstorage_client=self.bqstoragereadclient,
676+
max_stream_count=_MAX_READ_STREAMS,
672677
),
673678
schema=og_schema,
674679
query_job=query_job,

0 commit comments

Comments
 (0)