|
26 | 26 | ) |
27 | 27 | from ._compat import cached_property |
28 | 28 | from ._version import __version__ |
| 29 | +from ._constants import DEFAULT_API_POOL_SHARDS, DEFAULT_TRANSFER_POOL_SHARDS, DEFAULT_BACKGROUND_POOL_SHARDS |
29 | 30 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
30 | 31 | from ._exceptions import RunloopError, APIStatusError |
31 | 32 | from ._base_client import ( |
@@ -96,6 +97,11 @@ def __init__( |
96 | 97 | # Enables HTTP/2 multiplexing and avoids ConnectTimeout storms under high concurrency. |
97 | 98 | # Set to False to create a private connection pool (old behavior). |
98 | 99 | shared_http_pool: bool = True, |
| 100 | + # Sharded H2 pools by workload (API / long-polls / transfers). Each shard ≈ |
| 101 | + # one H2 connection; requests round-robin per client from a random offset. |
| 102 | + api_pool_shards: int = DEFAULT_API_POOL_SHARDS, |
| 103 | + background_pool_shards: int = DEFAULT_BACKGROUND_POOL_SHARDS, |
| 104 | + transfer_pool_shards: int = DEFAULT_TRANSFER_POOL_SHARDS, |
99 | 105 | # Enable or disable schema validation for data returned by the API. |
100 | 106 | # When enabled an error APIResponseValidationError is raised |
101 | 107 | # if the API responds with invalid data for the expected schema. |
@@ -142,6 +148,9 @@ def __init__( |
142 | 148 | custom_query=default_query, |
143 | 149 | _strict_response_validation=_strict_response_validation, |
144 | 150 | shared_http_pool=shared_http_pool, |
| 151 | + api_pool_shards=api_pool_shards, |
| 152 | + background_pool_shards=background_pool_shards, |
| 153 | + transfer_pool_shards=transfer_pool_shards, |
145 | 154 | ) |
146 | 155 |
|
147 | 156 | self._idempotency_header = "x-request-id" |
@@ -284,6 +293,9 @@ def copy( |
284 | 293 | timeout: float | Timeout | None | NotGiven = not_given, |
285 | 294 | http_client: httpx.Client | None = None, |
286 | 295 | shared_http_pool: bool | None = None, |
| 296 | + api_pool_shards: int | None = None, |
| 297 | + background_pool_shards: int | None = None, |
| 298 | + transfer_pool_shards: int | None = None, |
287 | 299 | max_retries: int | NotGiven = not_given, |
288 | 300 | default_headers: Mapping[str, str] | None = None, |
289 | 301 | set_default_headers: Mapping[str, str] | None = None, |
@@ -325,6 +337,13 @@ def copy( |
325 | 337 | timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, |
326 | 338 | http_client=http_client, |
327 | 339 | shared_http_pool=resolved_shared, |
| 340 | + api_pool_shards=(api_pool_shards if api_pool_shards is not None else self._api_pool_shards), |
| 341 | + background_pool_shards=( |
| 342 | + background_pool_shards if background_pool_shards is not None else self._background_pool_shards |
| 343 | + ), |
| 344 | + transfer_pool_shards=( |
| 345 | + transfer_pool_shards if transfer_pool_shards is not None else self._transfer_pool_shards |
| 346 | + ), |
328 | 347 | max_retries=max_retries if is_given(max_retries) else self.max_retries, |
329 | 348 | default_headers=headers, |
330 | 349 | default_query=params, |
@@ -390,6 +409,11 @@ def __init__( |
390 | 409 | # Enables HTTP/2 multiplexing and avoids ConnectTimeout storms under high concurrency. |
391 | 410 | # Set to False to create a private connection pool (old behavior). |
392 | 411 | shared_http_pool: bool = True, |
| 412 | + # Sharded H2 pools by workload (API / long-polls / transfers). Each shard ≈ |
| 413 | + # one H2 connection; requests round-robin per client from a random offset. |
| 414 | + api_pool_shards: int = DEFAULT_API_POOL_SHARDS, |
| 415 | + background_pool_shards: int = DEFAULT_BACKGROUND_POOL_SHARDS, |
| 416 | + transfer_pool_shards: int = DEFAULT_TRANSFER_POOL_SHARDS, |
393 | 417 | # Enable or disable schema validation for data returned by the API. |
394 | 418 | # When enabled an error APIResponseValidationError is raised |
395 | 419 | # if the API responds with invalid data for the expected schema. |
@@ -436,6 +460,9 @@ def __init__( |
436 | 460 | custom_query=default_query, |
437 | 461 | _strict_response_validation=_strict_response_validation, |
438 | 462 | shared_http_pool=shared_http_pool, |
| 463 | + api_pool_shards=api_pool_shards, |
| 464 | + background_pool_shards=background_pool_shards, |
| 465 | + transfer_pool_shards=transfer_pool_shards, |
439 | 466 | ) |
440 | 467 |
|
441 | 468 | self._idempotency_header = "x-request-id" |
@@ -578,6 +605,9 @@ def copy( |
578 | 605 | timeout: float | Timeout | None | NotGiven = not_given, |
579 | 606 | http_client: httpx.AsyncClient | None = None, |
580 | 607 | shared_http_pool: bool | None = None, |
| 608 | + api_pool_shards: int | None = None, |
| 609 | + background_pool_shards: int | None = None, |
| 610 | + transfer_pool_shards: int | None = None, |
581 | 611 | max_retries: int | NotGiven = not_given, |
582 | 612 | default_headers: Mapping[str, str] | None = None, |
583 | 613 | set_default_headers: Mapping[str, str] | None = None, |
@@ -619,6 +649,13 @@ def copy( |
619 | 649 | timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, |
620 | 650 | http_client=http_client, |
621 | 651 | shared_http_pool=resolved_shared, |
| 652 | + api_pool_shards=(api_pool_shards if api_pool_shards is not None else self._api_pool_shards), |
| 653 | + background_pool_shards=( |
| 654 | + background_pool_shards if background_pool_shards is not None else self._background_pool_shards |
| 655 | + ), |
| 656 | + transfer_pool_shards=( |
| 657 | + transfer_pool_shards if transfer_pool_shards is not None else self._transfer_pool_shards |
| 658 | + ), |
622 | 659 | max_retries=max_retries if is_given(max_retries) else self.max_retries, |
623 | 660 | default_headers=headers, |
624 | 661 | default_query=params, |
|
0 commit comments