Skip to content

Commit

Permalink
feat: Make size_limit (max run count per batch) globally configurable…
Browse files Browse the repository at this point in the history
… via env var (#1358)

### Purpose
Compression improves run throughput and memory usage, but performance is
still slower than expected for power users due to excessive threads and
small payloads. SDK users can improve the throughput for larger payloads
and higher trace counts by making the run count batch ingest config
globally configurable.

### Changes
* Created an environment variable `LANGSMITH_BATCH_INGEST_SIZE_LIMIT` to
configure run count.

* This takes precedence over the `/info` api response and any value
passed directly to the client batch ingest config.

### Tests / Benchmarks
Setting a higher run count increased compressed runs throughput by
**~80-100%** depending on run count and payload size.
  • Loading branch information
angus-langchain authored Jan 2, 2025
1 parent d6e83a7 commit 1dd32e1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions python/langsmith/_internal/_background_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)

from langsmith import schemas as ls_schemas
from langsmith import utils as ls_utils
from langsmith._internal._constants import (
_AUTO_SCALE_DOWN_NEMPTY_TRIGGER,
_AUTO_SCALE_UP_NTHREADS_LIMIT,
Expand Down Expand Up @@ -157,6 +158,21 @@ def _tracing_thread_handle_batch(
tracing_queue.task_done()


def get_size_limit_from_env() -> Optional[int]:
size_limit_str = ls_utils.get_env_var(
"BATCH_INGEST_SIZE_LIMIT",
)
if size_limit_str is not None:
try:
return int(size_limit_str)
except ValueError:
logger.warning(
f"Invalid value for BATCH_INGEST_SIZE_LIMIT: {size_limit_str}, "
"continuing with default"
)
return None


def _ensure_ingest_config(
info: ls_schemas.LangSmithInfo,
) -> ls_schemas.BatchIngestConfig:
Expand All @@ -173,6 +189,9 @@ def _ensure_ingest_config(
try:
if not info.batch_ingest_config:
return default_config
env_size_limit = get_size_limit_from_env()
if env_size_limit is not None:
info.batch_ingest_config["size_limit"] = env_size_limit
return info.batch_ingest_config
except BaseException:
return default_config
Expand Down

0 comments on commit 1dd32e1

Please sign in to comment.