jrushford commented on PR #12567: URL: https://github.com/apache/trafficserver/pull/12567#issuecomment-3408706497
@PSUdaemon this is relevant to strategies also as it uses the SipHash-2-4 for its consistent hash used for parent selection. You might consider a PR for strategies.yaml. I believe that strategies will deprecate parent selection in the future. Regards Jrushford > On Oct 15, 2025, at 4:43 PM, Phil Sorber ***@***.***> wrote: > > Configurable Hash Algorithm for Consistent Hash Parent Selection > > Overview > > Makes the hash algorithm used in consistent hash parent selection configurable at startup, adding two faster alternatives to the existing SipHash-2-4 implementation. > > Motivation > > The current implementation hard-codes SipHash-2-4 for consistent hash parent selection. While secure and DoS-resistant, it may not be optimal for all deployments. This change > allows operators to choose faster algorithms based on their specific performance requirements and threat models. > > Changes > > New Hash Implementations (Zero Dependencies) > > SipHash Template (include/tscore/HashSip.h) > > Template-based implementation: ATSHashSip<c_rounds, d_rounds> > SipHash-1-3 (type alias ATSHash64Sip13): ~50% faster than SipHash-2-4 > SipHash-2-4 (type alias ATSHash64Sip24): Existing algorithm, now template-based > License: CC0 (public domain, ASF Category A) > Zero code duplication between variants > Header-only template with compile-time optimization > HashWyhash (include/tscore/HashWyhash.h, src/tscore/HashWyhash.cc) > > Wyhash v4.1: ~3-5x faster than SipHash-2-4 > License: Unlicense (public domain, ASF Category A) > DoS-resistant, processes 32-byte blocks > Uses seed=0 for deterministic behavior > Configuration Infrastructure > > New Configuration Variable: > proxy.config.http.parent_proxy.consistent_hash_algorithm: siphash24 > Values: siphash24 (default), siphash13, wyhash > Only affects round_robin=consistent_hash in parent.config > Requires restart to take effect > Implementation: > Added ParentHashAlgorithm enum to ParentSelection.h > Factory pattern in ParentConsistentHash::createHashInstance() > Config reading in ParentRecord::Init() > Registered in RecordsConfig.cc > Testing > > 745 assertions, all passing: > > Unit Tests (44 assertions) > test_HashAlgorithms.cc: Comprehensive tests for HashSip13 and Wyhash > Tests: determinism, empty input, single byte, block boundaries, incremental updates, URL patterns, clear/reuse > Integration Tests (14 assertions) > test_ParentHashConfig.cc: Config parsing and validation > Tests: valid inputs, invalid input fallback, case sensitivity, backward compatibility > Related Tests (687 assertions) > test_NextHopConsistentHash: 111 assertions > test_NextHopRoundRobin: 55 assertions > test_NextHopStrategyFactory: 521 assertions > Documentation > > records.yaml.en.rst > Full configuration documentation > Performance characteristics for each algorithm > Migration warning about request redistribution > parent.config.en.rst > Hash algorithm reference in consistent_hash section > Cross-reference to records.yaml for details > Backward Compatibility > > Fully backward compatible: > > Default remains siphash24 (existing behavior unchanged) > All hash implementations use seed=0 for deterministic behavior across restarts > Existing tests pass with no regressions > No changes to parent selection logic, only hash implementations > Migration Consideration: > > Changing the hash algorithm will cause requests to be redistributed differently across parent proxies. This can lead to cache churn and increased origin load during the > transition. Plan migrations carefully and consider doing them during low-traffic periods. > > Performance Characteristics > > Algorithm Speed vs SipHash-2-4 Compression Rounds Finalization Rounds DoS Resistant > siphash24 Baseline (1.0x) 2 4 ✅ Yes > siphash13 ~1.5x faster 1 3 ✅ Yes > wyhash ~3-5x faster N/A (different design) N/A ✅ Yes > Implementation Highlights > > Template-Based SipHash: Uses ATSHashSip<c_rounds, d_rounds> template to eliminate code duplication between SipHash variants. Type aliases ATSHash64Sip24 and ATSHash64Sip13 > provide convenient access. Compiler optimizes loops at compile time for zero runtime overhead. > Deterministic Seeding: All hash implementations use seed=0 to ensure consistent parent selection across server restarts, preventing cache churn. > Factory Pattern: ParentConsistentHash::createHashInstance() selects hash algorithm based on config, with fallback to SipHash-2-4 for unknown values. > Future Work > > Phase 2: Add XXH3 if an external dependency is acceptable > Phase 3: Implement per-parent-set hash configuration with configurable seed values > Testing Instructions > > Build with changes: cmake --build build > Run hash tests: ./build/src/tscore/test_tscore "[HashSip13]" "[HashWyhash]" > Run config tests: ./build/src/proxy/unit_tests/test_proxy > Verify default: Check that proxy.config.http.parent_proxy.consistent_hash_algorithm defaults to siphash24 in configs/records.yaml.default.in > Configuration Example > > Global hash algorithm setting (in records.yaml): > > http: > parent_proxy: > consistent_hash_algorithm: wyhash # or siphash24, siphash13 > > Parent selection rule (in parent.config): > # The hash algorithm configured in records.yaml will be used > dest_domain=example.com parent=p1:80,p2:80 round_robin=consistent_hash > > Note: The hash algorithm is a global setting that affects all parent selections using round_robin=consistent_hash. It cannot be configured per-parent-set in this > implementation. Future work (Phase 3) may add per-parent-set hash configuration. > You can view, comment on, or merge this pull request online at: > > https://github.com/apache/trafficserver/pull/12567 > > Commit Summary > > 2c2958b <https://github.com/apache/trafficserver/pull/12567/commits/2c2958b9770a263435ccc0c55fe41b72687e7955> Make Parent Selection Hash configurable and add SipHash-1-3 and Wyhash v4.1. > File Changes (18 files <https://github.com/apache/trafficserver/pull/12567/files>) > M configs/records.yaml.default.in <https://github.com/apache/trafficserver/pull/12567/files#diff-affcd842cfc7c0042d8cbbffe060ba55fdc86ea6ba24de6c153a8e63031e7ff0> (1) > M doc/admin-guide/files/parent.config.en.rst <https://github.com/apache/trafficserver/pull/12567/files#diff-7f9a068d0b54d44f0557c429b66e2f229708402322286905ae4bf9b3fda6c1af> (7) > M doc/admin-guide/files/records.yaml.en.rst <https://github.com/apache/trafficserver/pull/12567/files#diff-c5a18890739578dc24c5a0a9c004687cc10c6230ee79171b9859068488844da2> (22) > M include/proxy/ParentConsistentHash.h <https://github.com/apache/trafficserver/pull/12567/files#diff-5f5923553ad86283b2e545d3a252ed249e844be7973af0e1fd88bb6a1e9ef370> (7) > M include/proxy/ParentSelection.h <https://github.com/apache/trafficserver/pull/12567/files#diff-7df2b8d1aa5392fb343682168b5dacf8db20d139127f218045aa8357988e6337> (3) > M include/tscore/HashSip.h <https://github.com/apache/trafficserver/pull/12567/files#diff-6006b1fc412abe59901bf6e2e5defafbd42c6a0b2dce09afd94a620281f67d09> (141) > A include/tscore/HashWyhash.h <https://github.com/apache/trafficserver/pull/12567/files#diff-a0c8b645863c77b28149a2d1072c321b5736bfb24b0a16da6200dc4fefbdd604> (44) > M src/proxy/CMakeLists.txt <https://github.com/apache/trafficserver/pull/12567/files#diff-d301c1243a9d9a52322d574e4015d92ef438625a04799e7359ed4adb870138bc> (4) > M src/proxy/ParentConsistentHash.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-f4b0c14114ea8ec3f5562d55734e37929903c49e604ae453b9936ca3b7f5c59e> (59) > M src/proxy/ParentSelection.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-933f021a3253f9464e7b819a98d807545eb2168036845767e1187462734694ec> (19) > A src/proxy/unit_tests/CMakeLists.txt <https://github.com/apache/trafficserver/pull/12567/files#diff-ed70e22d49d23efe968358f2d63967bc0366d28ea87e8f99888446077a89d717> (33) > A src/proxy/unit_tests/main.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-a3deee0cb6f4f7c41a3842afd9b4d48498a77f7302ab4237500cabf08bbe2081> (51) > A src/proxy/unit_tests/test_ParentHashConfig.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-6f9ac9424d4e88c2e29acc911041f37a450762aae901f2c87255af277bf4d59a> (65) > M src/records/RecordsConfig.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-3f54b3a6f3cd459bda3c05bcd5ba17251e8554ca20f03e3d92538c4c5b632055> (2) > M src/tscore/CMakeLists.txt <https://github.com/apache/trafficserver/pull/12567/files#diff-72a35fcae8828cb09bdd982a2bbfedfe104d9585e1b651dd2c03b8f0e02d54d7> (3) > D src/tscore/HashSip.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-ea2c7612e3dc3539c0af3e57fe57929c5b9156fcc4a238fd5262a91737228c0e> (141) > A src/tscore/HashWyhash.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-68772f9b2b93c4c6026d7116e800b881edcd30ecb906824b653ab406d079cef2> (154) > A src/tscore/unit_tests/test_HashAlgorithms.cc <https://github.com/apache/trafficserver/pull/12567/files#diff-84d5a9fcfd320e5afd6b224fdcea6c259902808cf40f182a932ffa684d197c8a> (308) > Patch Links: > > https://github.com/apache/trafficserver/pull/12567.patch > https://github.com/apache/trafficserver/pull/12567.diff > — > Reply to this email directly, view it on GitHub <https://github.com/apache/trafficserver/pull/12567>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABCXE3SPEAXZOTOXAGHLLVD3X3EZ5AVCNFSM6AAAAACJJ2M5BOVHI2DSMVQWIX3LMV43ASLTON2WKOZTGUYTSNZYGMZDONY>. > You are receiving this because you are subscribed to this thread. > -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
