Skip to content

Commit b14649b

Browse files
committed
Remove WyHash and add more configs.
1 parent 3080d61 commit b14649b

File tree

15 files changed

+299
-519
lines changed

15 files changed

+299
-519
lines changed

configs/strategies.schema.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@
157157
"url"
158158
]
159159
},
160+
"hash_algorithm": {
161+
"type": "string",
162+
"description": "when using consistent_hash, this specifies the hash algorithm to use",
163+
"enum": [
164+
"siphash24",
165+
"siphash13"
166+
]
167+
},
168+
"hash_seed0": {
169+
"type": "integer",
170+
"description": "when using consistent_hash, this specifies the first 64 bits of the hash seed (decimal integer)",
171+
"minimum": 0
172+
},
173+
"hash_seed1": {
174+
"type": "integer",
175+
"description": "when using consistent_hash, this specifies the second 64 bits of the hash seed (decimal integer)",
176+
"minimum": 0
177+
},
178+
"hash_replicas": {
179+
"type": "integer",
180+
"description": "when using consistent_hash, this specifies the number of virtual nodes (replicas) per host",
181+
"minimum": 1
182+
},
160183
"go_direct": {
161184
"type": "boolean",
162185
"description": "wether, true/false, users of the strategy may bypass parents and go directly to the origin"

doc/admin-guide/files/parent.config.en.rst

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,8 @@ The following list shows the possible actions and their allowed values.
281281

282282
The hash algorithm used for consistent hashing can be configured via
283283
:ts:cv:`proxy.config.http.parent_proxy.consistent_hash_algorithm`. Available
284-
algorithms are ``siphash24`` (default), ``siphash13`` (faster), and ``wyhash``
285-
(fastest). See the records.yaml documentation for performance characteristics
286-
and migration considerations.
284+
algorithms are ``siphash24`` (default) and ``siphash13`` (faster).
285+
See the records.yaml documentation for details.
287286

288287
- ``latched`` - The first parent in the list is marked as primary and is
289288
always chosen until connection errors cause it to be marked down. When
@@ -325,6 +324,62 @@ The following list shows the possible actions and their allowed values.
325324

326325
- ``false`` - The default. Do not ignore the host status.
327326

327+
.. _parent-config-format-hash-algorithm:
328+
329+
``hash_algorithm``
330+
When using ``round_robin=consistent_hash``, this specifies the hash algorithm to use
331+
for this specific rule, overriding the global default set in :ts:cv:`proxy.config.http.parent_proxy.consistent_hash_algorithm`.
332+
333+
Allowed values:
334+
335+
- ``siphash24`` - SipHash-2-4 (default). Cryptographically strong, DoS-resistant.
336+
- ``siphash13`` - SipHash-1-3. ~50% faster than SipHash-2-4, still DoS-resistant.
337+
338+
Example::
339+
340+
dest_domain=. parent="p1.x.com:80,p2.x.com:80" round_robin=consistent_hash hash_algorithm=siphash13
341+
342+
.. _parent-config-format-hash-seed0:
343+
344+
``hash_seed0``
345+
When using ``round_robin=consistent_hash``, this specifies the first 64 bits of the hash seed (key).
346+
347+
- For SipHash algorithms, this is the first half of the 128-bit cryptographic key (k0)
348+
- For future 64-bit algorithms, this will be the full seed value
349+
350+
Value must be specified as a decimal integer (e.g. ``12345678901234567``). Default is ``0``.
351+
352+
Example::
353+
354+
dest_domain=. parent="p1.x.com:80,p2.x.com:80" round_robin=consistent_hash hash_seed0=1234567890
355+
356+
.. _parent-config-format-hash-seed1:
357+
358+
``hash_seed1``
359+
When using ``round_robin=consistent_hash``, this specifies the second 64 bits of the hash seed (key).
360+
361+
- For SipHash algorithms, this is the second half of the 128-bit cryptographic key (k1)
362+
- For future 64-bit algorithms, this value is ignored
363+
364+
Value must be specified as a decimal integer (e.g. ``9876543210987654321``). Default is ``0``.
365+
366+
Example::
367+
368+
dest_domain=. parent="p1.x.com:80,p2.x.com:80" round_robin=consistent_hash hash_seed0=1234567890 hash_seed1=9876543210
369+
370+
.. _parent-config-format-hash-replicas:
371+
372+
``hash_replicas``
373+
When using ``round_robin=consistent_hash``, this specifies the number of virtual nodes (replicas)
374+
per parent host on the consistent hash ring.
375+
376+
Increasing the replica count improves the distribution of requests across parent proxies but uses
377+
more memory. Must be greater than 0. Default is ``1024``.
378+
379+
Example::
380+
381+
dest_domain=. parent="p1.x.com:80,p2.x.com:80" round_robin=consistent_hash hash_replicas=2048
382+
328383
Examples
329384
========
330385

doc/admin-guide/files/records.yaml.en.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,6 @@ Parent Proxy Configuration
14831483
============== ================================================================================
14841484
``siphash24`` SipHash-2-4 (default). Cryptographically strong, DoS-resistant hash function.
14851485
``siphash13`` SipHash-1-3. ~50% faster than SipHash-2-4, still DoS-resistant.
1486-
``wyhash`` Wyhash v4.1. ~3-5x faster than SipHash-2-4, DoS-resistant.
14871486
============== ================================================================================
14881487

14891488
.. warning::
@@ -1493,6 +1492,42 @@ Parent Proxy Configuration
14931492
transition period. Plan the migration carefully and consider doing it during
14941493
low-traffic periods.
14951494

1495+
.. ts:cv:: CONFIG proxy.config.http.parent_proxy.consistent_hash_seed0 INT 0
1496+
1497+
The first 64 bits of the hash seed (key) for consistent hash parent selection.
1498+
This setting only affects parent selection when ``round_robin=consistent_hash`` is configured.
1499+
1500+
- For SipHash algorithms, this forms the first half of the 128-bit cryptographic key (k0)
1501+
- For future 64-bit hash algorithms (like XXH3), this is the full seed value
1502+
1503+
The value must be specified as a decimal integer (e.g. ``12345678901234567``). Default is ``0``.
1504+
Per-rule configuration is available in :file:`parent.config` using ``hash_seed0=<value>``.
1505+
Per-strategy configuration is available in :file:`strategies.yaml` using ``hash_seed0: <value>``.
1506+
1507+
.. ts:cv:: CONFIG proxy.config.http.parent_proxy.consistent_hash_seed1 INT 0
1508+
1509+
The second 64 bits of the hash seed (key) for consistent hash parent selection.
1510+
This setting only affects parent selection when ``round_robin=consistent_hash`` is configured.
1511+
1512+
- For SipHash algorithms, this forms the second half of the 128-bit cryptographic key (k1)
1513+
- For future 64-bit hash algorithms, this value is ignored
1514+
1515+
The value must be specified as a decimal integer (e.g. ``9876543210987654321``). Default is ``0``.
1516+
Per-rule configuration is available in :file:`parent.config` using ``hash_seed1=<value>``.
1517+
Per-strategy configuration is available in :file:`strategies.yaml` using ``hash_seed1: <value>``.
1518+
1519+
.. ts:cv:: CONFIG proxy.config.http.parent_proxy.consistent_hash_replicas INT 1024
1520+
1521+
The number of virtual nodes (replicas) per parent host on the consistent hash ring.
1522+
This setting only affects parent selection when ``round_robin=consistent_hash`` is configured.
1523+
1524+
Increasing the replica count improves the distribution of requests across parent proxies
1525+
but uses more memory. The default value of 1024 provides good distribution in most scenarios.
1526+
1527+
Must be greater than 0. Default is ``1024``.
1528+
Per-rule configuration is available in :file:`parent.config` using ``hash_replicas=<value>``.
1529+
Per-strategy configuration is available in :file:`strategies.yaml` using ``hash_replicas: <value>``.
1530+
14961531
.. ts:cv:: CONFIG proxy.config.http.parent_proxy.enable_parent_timeout_markdowns INT 0
14971532
:reloadable:
14981533
:overridable:

doc/admin-guide/files/strategies.yaml.en.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,62 @@ Each **strategy** in the list may using the following parameters:
201201
#. **parent**: Use the parent URL as set via the API :cpp:func:`TSHttpTxnParentSelectionUrlSet`.
202202
This again is likely set via an existing plugin such as the **cachekey** plugin.
203203

204+
- **hash_algorithm**: The hash algorithm used by the **consistent_hash** policy. This parameter allows
205+
per-strategy selection of the hash algorithm. If not specified, defaults to **siphash24** (or the value
206+
set in :ts:cv:`proxy.config.http.parent_proxy.consistent_hash_algorithm`). Use one of:
207+
208+
#. **siphash24**: (**default**) SipHash-2-4. Cryptographically strong, DoS-resistant hash function.
209+
#. **siphash13**: SipHash-1-3. ~50% faster than SipHash-2-4, still DoS-resistant.
210+
211+
Example:
212+
213+
.. code-block:: yaml
214+
215+
policy: consistent_hash
216+
hash_algorithm: siphash13
217+
218+
- **hash_seed0**: The first 64 bits of the hash seed (key) for the **consistent_hash** policy.
219+
220+
- For SipHash algorithms, this forms the first half of the 128-bit cryptographic key (k0)
221+
- For future 64-bit hash algorithms, this is the full seed value
222+
223+
Value must be specified as a decimal integer. Default is **0**.
224+
225+
Example:
226+
227+
.. code-block:: yaml
228+
229+
policy: consistent_hash
230+
hash_seed0: 12345678901234567
231+
232+
- **hash_seed1**: The second 64 bits of the hash seed (key) for the **consistent_hash** policy.
233+
234+
- For SipHash algorithms, this forms the second half of the 128-bit cryptographic key (k1)
235+
- For future 64-bit hash algorithms, this value is ignored
236+
237+
Value must be specified as a decimal integer. Default is **0**.
238+
239+
Example:
240+
241+
.. code-block:: yaml
242+
243+
policy: consistent_hash
244+
hash_seed0: 12345678901234567
245+
hash_seed1: 9876543210987654321
246+
247+
- **hash_replicas**: The number of virtual nodes (replicas) per host on the consistent hash ring for
248+
the **consistent_hash** policy.
249+
250+
Increasing the replica count improves the distribution of requests across hosts but uses more memory.
251+
Must be greater than 0. Default is **1024**.
252+
253+
Example:
254+
255+
.. code-block:: yaml
256+
257+
policy: consistent_hash
258+
hash_replicas: 2048
259+
204260
- **go_direct**: A boolean value indicating whether a transaction may bypass proxies and go direct to the origin. Defaults to **true**
205261
- **parent_is_proxy**: A boolean value which indicates if the groups of hosts are proxy caches or origins. **true** (default) means all the hosts used in the remap are |TS| caches. **false** means the hosts are origins that the next hop strategies may use for load balancing and/or failover.
206262
- **cache_peer_result**: A boolean value that is only used when the **policy** is 'consistent_hash' and a **peering_ring** mode is used for the strategy. When set to true, the default, all responses from upstream and peer endpoints are allowed to be cached. Setting this to false will disable caching responses received from a peer host. Only responses from upstream origins or parents will be cached for this strategy.

include/proxy/ParentConsistentHash.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ class ParentConsistentHash : public ParentSelectionStrategy
4545
bool ignore_query;
4646
int secondary_mode;
4747
ParentHashAlgorithm selected_algorithm;
48+
uint64_t hash_seed0;
49+
uint64_t hash_seed1;
4850

49-
std::unique_ptr<ATSHash64> createHashInstance(ParentHashAlgorithm algo);
51+
std::unique_ptr<ATSHash64> createHashInstance(ParentHashAlgorithm algo, uint64_t seed0, uint64_t seed1);
5052

5153
public:
5254
static const int PRIMARY = 0;

include/proxy/ParentSelection.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum class ParentRetry_t {
7373
BOTH = 3
7474
};
7575

76-
enum class ParentHashAlgorithm { SIPHASH24 = 0, SIPHASH13, WYHASH };
76+
enum class ParentHashAlgorithm { SIPHASH24 = 0, SIPHASH13 };
7777

7878
struct UnavailableServerResponseCodes {
7979
UnavailableServerResponseCodes(char *val);
@@ -166,6 +166,9 @@ class ParentRecord : public ControlBase
166166
int secondary_mode = 1;
167167
bool ignore_self_detect = false;
168168
ParentHashAlgorithm consistent_hash_algorithm = ParentHashAlgorithm::SIPHASH24;
169+
uint64_t consistent_hash_seed0 = 0;
170+
uint64_t consistent_hash_seed1 = 0;
171+
int consistent_hash_replicas = 1024; // Number of virtual nodes per host (int to match ATSConsistentHash constructor)
169172
};
170173

171174
// If the parent was set by the external customer api,

include/proxy/http/remap/NextHopConsistentHash.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ class NextHopConsistentHash : public NextHopSelectionStrategy
4646
uint64_t getHashKey(uint64_t sm_id, const HttpRequestData &hrdata, ATSHash64 *h);
4747

4848
public:
49-
NHHashKeyType hash_key = NHHashKeyType::PATH_HASH_KEY;
50-
NHHashUrlType hash_url = NHHashUrlType::REQUEST;
49+
NHHashKeyType hash_key = NHHashKeyType::PATH_HASH_KEY;
50+
NHHashUrlType hash_url = NHHashUrlType::REQUEST;
51+
std::string hash_algorithm = "siphash24"; // Default hash algorithm name
52+
uint64_t hash_seed0 = 0; // First 64 bits of hash seed
53+
uint64_t hash_seed1 = 0; // Second 64 bits of hash seed
54+
int hash_replicas = 1024; // Number of virtual nodes per host (int to match ATSConsistentHash constructor)
5155

5256
NextHopConsistentHash() = delete;
5357
NextHopConsistentHash(const std::string_view name, const NHPolicyType &policy, ts::Yaml::Map &n);

include/tscore/HashWyhash.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/proxy/ParentConsistentHash.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,23 @@
2424
#include "proxy/HostStatus.h"
2525
#include "proxy/ParentConsistentHash.h"
2626
#include "tscore/HashSip.h"
27-
#include "tscore/HashWyhash.h"
2827

2928
namespace
3029
{
3130
DbgCtl dbg_ctl_parent_select{"parent_select"};
3231
}
3332

3433
std::unique_ptr<ATSHash64>
35-
ParentConsistentHash::createHashInstance(ParentHashAlgorithm algo)
34+
ParentConsistentHash::createHashInstance(ParentHashAlgorithm algo, uint64_t seed0, uint64_t seed1)
3635
{
3736
switch (algo) {
3837
case ParentHashAlgorithm::SIPHASH24:
39-
return std::make_unique<ATSHash64Sip24>();
38+
return std::make_unique<ATSHash64Sip24>(seed0, seed1);
4039
case ParentHashAlgorithm::SIPHASH13:
41-
return std::make_unique<ATSHash64Sip13>();
42-
case ParentHashAlgorithm::WYHASH:
43-
return std::make_unique<ATSHash64Wyhash>();
40+
return std::make_unique<ATSHash64Sip13>(seed0, seed1);
4441
default:
4542
Warning("Unknown hash algorithm %d, using SipHash-2-4", static_cast<int>(algo));
46-
return std::make_unique<ATSHash64Sip24>();
43+
return std::make_unique<ATSHash64Sip24>(seed0, seed1);
4744
}
4845
}
4946

@@ -57,19 +54,21 @@ ParentConsistentHash::ParentConsistentHash(ParentRecord *parent_record)
5754
ignore_query = parent_record->ignore_query;
5855
secondary_mode = parent_record->secondary_mode;
5956
selected_algorithm = parent_record->consistent_hash_algorithm;
57+
hash_seed0 = parent_record->consistent_hash_seed0;
58+
hash_seed1 = parent_record->consistent_hash_seed1;
6059
ink_zero(foundParents);
6160

62-
hash[PRIMARY] = createHashInstance(selected_algorithm);
63-
chash[PRIMARY] = std::make_unique<ATSConsistentHash>();
61+
hash[PRIMARY] = createHashInstance(selected_algorithm, hash_seed0, hash_seed1);
62+
chash[PRIMARY] = std::make_unique<ATSConsistentHash>(parent_record->consistent_hash_replicas);
6463

6564
for (i = 0; i < parent_record->num_parents; i++) {
6665
chash[PRIMARY]->insert(&(parent_record->parents[i]), parent_record->parents[i].weight, hash[PRIMARY].get());
6766
}
6867

6968
if (parent_record->num_secondary_parents > 0) {
7069
Dbg(dbg_ctl_parent_select, "ParentConsistentHash(): initializing the secondary parents hash.");
71-
hash[SECONDARY] = createHashInstance(selected_algorithm);
72-
chash[SECONDARY] = std::make_unique<ATSConsistentHash>();
70+
hash[SECONDARY] = createHashInstance(selected_algorithm, hash_seed0, hash_seed1);
71+
chash[SECONDARY] = std::make_unique<ATSConsistentHash>(parent_record->consistent_hash_replicas);
7372

7473
for (i = 0; i < parent_record->num_secondary_parents; i++) {
7574
chash[SECONDARY]->insert(&(parent_record->secondary_parents[i]), parent_record->secondary_parents[i].weight,
@@ -155,7 +154,7 @@ void
155154
ParentConsistentHash::selectParent(bool first_call, ParentResult *result, RequestData *rdata,
156155
unsigned int /* fail_threshold ATS_UNUSED */, unsigned int retry_time)
157156
{
158-
std::unique_ptr<ATSHash64> hash = createHashInstance(selected_algorithm);
157+
std::unique_ptr<ATSHash64> hash = createHashInstance(selected_algorithm, hash_seed0, hash_seed1);
159158
ATSConsistentHash *fhash;
160159
HttpRequestData *request_info = static_cast<HttpRequestData *>(rdata);
161160
bool firstCall = first_call;

0 commit comments

Comments
 (0)