-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: [LS-2561] Stream compress multipart runs #1316
Conversation
python/langsmith/client.py
Outdated
if self.compress_traces: | ||
self.boundary = BOUNDARY | ||
self.compressed_runs_buffer: io.BytesIO = io.BytesIO() | ||
self.compressor_writer: zstd.ZstdCompressionWriter = zstd.ZstdCompressor(level=3).stream_writer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably use the lowest level, we want to minimize cpu usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With level=1
we're only getting a compression ratio of 6.7 vs 18+, level=2
puts us around 12. I'm open to experimenting with this to see if we still OOM with level=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to copy the zstandard's BSD license somewhere:
Copyright (c) 2016, Gregory Szorc
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
python/pyproject.toml
Outdated
@@ -37,6 +37,7 @@ requests-toolbelt = "^1.0.0" | |||
|
|||
# Enabled via `langsmith_pyo3` extra: `pip install langsmith[langsmith_pyo3]`. | |||
langsmith-pyo3 = { version = "^0.1.0rc2", optional = true } | |||
zstandard = "^0.23.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like they have a conda project so should be good, but we may have to manually update our conda distro for the SDK
https://anaconda.org/conda-forge/langsmith
https://anaconda.org/conda-forge/zstandard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up. Would this issue come up when creating a new version of the sdk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya upon release. It should be straightforward to support just noting!
) | ||
|
||
if (size_limit_bytes is None or current_size < size_limit_bytes) and ( | ||
size_limit is None or client._run_count < size_limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 100?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the limit that is currently used. It also performed well in flush time benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can also be overridden by the batch ingest config
856e4a4
to
2ac7a35
Compare
_SIZE_LIMIT_BYTES = 20_971_520 # 20MB by default | ||
_AUTO_SCALE_UP_QSIZE_TRIGGER = 200 | ||
_AUTO_SCALE_UP_NTHREADS_LIMIT = 32 | ||
_AUTO_SCALE_DOWN_NEMPTY_TRIGGER = 4 | ||
_BLOCKSIZE_BYTES = 1024 * 1024 # 1MB | ||
_BOUNDARY = uuid.uuid4().hex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be unique every time? or should we hardcode it here?
Purpose
Compresses multipart runs into a buffer and streams the compressed data to the API. Compatible with https://github.com/langchain-ai/langchainplus/pull/7317