Add msgpack_pack_buf_size opt to tune initial Packer allocation - #70117
Open
dwoz wants to merge 3 commits into
Open
Add msgpack_pack_buf_size opt to tune initial Packer allocation#70117dwoz wants to merge 3 commits into
dwoz wants to merge 3 commits into
Conversation
Expose a single new master/minion/api config option, ``msgpack_pack_buf_size``, that controls the initial ``buf_size`` passed to the underlying C ``msgpack.Packer`` used by Salt's transport framing, payload packaging, and msgpack serializer helpers. The value is cached at daemon startup in ``salt.utils.msgpack`` via a small ``set_pack_buf_size`` helper called from ``apply_master_config``, ``apply_minion_config``, and ``api_config`` so downstream helpers that do not have ``__opts__`` in scope can honor the opt without changes to their call sites. Default is ``0``, which preserves msgpack's own default (auto-grow-from- 256KB) and current behavior byte-for-byte. A positive value pre-allocates that many bytes on ``Packer`` construction, which can reduce realloc churn for workloads with predictable payload sizes. This is a tuning knob only; it does not change the wire format or any observable behavior at the default value.
Flip the ``msgpack_pack_buf_size`` default from ``0`` (msgpack's own 256 KiB progressive growth) to ``1048576`` (1 MiB). The new default pre-allocates a workload-appropriate ``Packer`` buffer that fits typical Salt payloads -- state returns, grains, event payloads -- in a single allocation, eliminating the realloc chain on the common path. The opt still honors ``0`` as an explicit escape hatch to restore the original msgpack behavior byte-for-byte; the wire format is unchanged. Also widen the opt to accept a human-friendly size string in the master and minion config, matching Salt's convention for other byte-count knobs. ``msgpack_pack_buf_size: 1MB`` (or ``512KiB``, ``2G``, etc.) is parsed via ``salt.utils.stringutils.human_to_bytes`` and normalized to an integer inside ``set_pack_buf_size``, so downstream helpers still see a plain int. Bad or unparseable strings are ignored with a debug log and leave the previous cached value in place, so bad opts never crash a daemon.
Contributor
Author
|
Follow-up pushed in 4a29cd5:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a single new master/minion/api config option,
msgpack_pack_buf_size(bytes), that controls the initialbuf_sizepassed to the Cmsgpack.Packerused by Salt's transport framing (salt.transport.frame), payload packaging (salt.payload), and msgpack serializer (salt.serializers.msgpack).The value is cached at daemon startup in
salt.utils.msgpackvia a smallset_pack_buf_sizehelper called fromapply_master_config,apply_minion_config, andapi_config, so downstream helpers that do not have__opts__in scope can honor the opt without threading it through every call site.Why
Exposes the knob so operators can pre-size the Packer buffer for workloads with predictable payload sizes and reduce realloc churn. Effect is workload-dependent -- this PR is not claiming a memory or throughput improvement; it just makes the underlying msgpack tunable reachable from Salt config.
Default / compat
Default is
0, which preserves msgpack's own default and current behavior byte-for-byte. Additive only; no wire format change.Test plan
tests/pytests/unit/utils/test_msgpack.pycovering default (no override), positive value forwarded asbuf_size, explicit caller kwarg still wins, bad values (non-int / negative) ignored without crashing, and packed-output byte-identical regardless ofbuf_size.tests/pytests/unit/config/,tests/pytests/unit/test_payload.py,tests/pytests/unit/serializers/test_serializers.pystill pass.