Skip to content

Commit 30063ef

Browse files
committed
lb: remove "consistent_hashing", default to "rendezvous_hashing" instead
We havn't been using Consistent Hashing (`class HashRing`) ever since we hadded Rendezvous Hashing, because the latter is superior. Let's remove this obsolete feature.
1 parent 33d8c47 commit 30063ef

12 files changed

Lines changed: 10 additions & 323 deletions

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cm4all-beng-proxy (21.11) unstable; urgency=low
33
* spawn: fix memory warning timer bug
44
* io_uring: disable the iowait state
55
* lb: add whitelist for REJECT_CLIENT and TARPIT_CLIENT
6+
* lb: remove "consistent_hashing", default to "rendezvous_hashing" instead
67
* call sodium_init() on startup (to select optimized cipher implementations)
78
* fix build with glibc 2.43
89

doc/lb.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ Example::
114114

115115
- ``sticky_method``: one of:
116116

117-
- ``consistent_hashing`` (the default)
118-
119-
- ``rendezvous_hashing``
117+
- ``rendezvous_hashing`` (the default)
120118

121119
- ``cache``: an assignment cache. The advantage of that cache is that
122120
existing clients will not be reassigned when new nodes appear. The
@@ -213,8 +211,8 @@ This requires ``avahi-daemon`` to be installed and running. And, of
213211
course, it requires the pool members to publish their service.
214212

215213
If ``sticky`` is enabled on the pool, then :program:`beng-lb` uses
216-
`consistent hashing
217-
<https://en.wikipedia.org/wiki/Consistent_hashing>`__ to pick a member
214+
`rendezvous hashing
215+
<https://en.wikipedia.org/wiki/Rendezvous_hashing>`__ to pick a member
218216
(to reduce member reassignments).
219217

220218
.. _lb_protocol:

meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ executable(
786786
'src/lb/Setup.cxx',
787787
'src/lb/GotoMap.cxx',
788788
'src/lb/Branch.cxx',
789-
'src/lb/MemberHash.cxx',
790789
'src/lb/Cluster.cxx',
791790
'src/lb/TranslationHandler.cxx',
792791
'src/lb/TranslationCache.cxx',

src/lb/Cluster.cxx

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "Cluster.hxx"
66
#include "ClusterConfig.hxx"
7-
#include "MemberHash.hxx"
87
#include "Context.hxx"
98
#include "MonitorStock.hxx"
109
#include "MonitorRef.hxx"
@@ -68,9 +67,6 @@ CalculateStickyHash(std::span<const std::byte> source) noexcept
6867

6968
#ifdef HAVE_AVAHI
7069

71-
class LbCluster::StickyRing final
72-
: public MemberHashRing<ZeroconfMemberMap::iterator> {};
73-
7470
class LbCluster::ZeroconfMember final : LeakDetector {
7571
InetAddress address;
7672

@@ -424,29 +420,6 @@ LbCluster::PickNextGoodZeroconf(const Expiry now) noexcept
424420
false);
425421
}
426422

427-
inline LbCluster::ZeroconfMemberMap::const_reference
428-
LbCluster::PickZeroconfHashRing(Expiry now,
429-
sticky_hash_t sticky_hash) noexcept
430-
{
431-
assert(!active_zeroconf_members.empty());
432-
assert(sticky_ring != nullptr);
433-
434-
auto i = sticky_ring->Pick(sticky_hash);
435-
assert(i != zeroconf_members.end());
436-
437-
unsigned retries = active_zeroconf_members.size();
438-
while (true) {
439-
if (--retries == 0 ||
440-
i->second.GetFailureInfo().Check(now))
441-
return *i;
442-
443-
/* the node is known-bad; pick the next one in the ring */
444-
const auto next = sticky_ring->FindNext(sticky_hash);
445-
sticky_hash = next.first;
446-
i = next.second;
447-
}
448-
}
449-
450423
inline LbCluster::ZeroconfMemberMap::const_reference
451424
LbCluster::PickZeroconfRendezvous(Expiry now, const Arch arch,
452425
std::span<const std::byte> sticky_source) noexcept
@@ -527,9 +500,6 @@ LbCluster::PickZeroconf(const Expiry now, Arch arch,
527500
assert(config.sticky_mode != StickyMode::NONE);
528501

529502
switch (config.sticky_method) {
530-
case LbClusterConfig::StickyMethod::CONSISTENT_HASHING:
531-
return &PickZeroconfHashRing(now, sticky_hash);
532-
533503
case LbClusterConfig::StickyMethod::RENDEZVOUS_HASHING:
534504
return &PickZeroconfRendezvous(now, arch, sticky_source);
535505

@@ -563,24 +533,6 @@ LbCluster::FillActive() noexcept
563533

564534
for (auto i = zeroconf_members.begin(); i != zeroconf_members.end(); ++i)
565535
active_zeroconf_members.push_back(i);
566-
567-
switch (config.sticky_method) {
568-
case LbClusterConfig::StickyMethod::CONSISTENT_HASHING:
569-
if (sticky_ring == nullptr)
570-
/* lazy allocation */
571-
sticky_ring = std::make_unique<StickyRing>();
572-
573-
BuildMemberHashRing(*sticky_ring, active_zeroconf_members,
574-
[](ZeroconfMemberMap::const_iterator member) noexcept {
575-
return member->second.GetAddress();
576-
});
577-
578-
break;
579-
580-
case LbClusterConfig::StickyMethod::RENDEZVOUS_HASHING:
581-
case LbClusterConfig::StickyMethod::CACHE:
582-
break;
583-
}
584536
}
585537

586538
class LbCluster::ZeroconfHttpConnect final : StockGetHandler, Lease, Cancellable {

src/lb/Cluster.hxx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ class LbCluster final
7676
*/
7777
std::unique_ptr<Avahi::ServiceExplorer> explorer;
7878

79-
class StickyRing;
80-
81-
/**
82-
* For consistent hashing. It is populated by FillActive().
83-
*/
84-
std::unique_ptr<StickyRing> sticky_ring;
85-
8679
/**
8780
* @see LbClusterConfig::sticky_cache
8881
*/
@@ -207,16 +200,6 @@ private:
207200
std::span<const std::byte> sticky_source,
208201
sticky_hash_t sticky_hash) noexcept;
209202

210-
/**
211-
* Like PickZeroconf(), but pick using Consistent Hashing (via
212-
* #HashRing).
213-
*
214-
* To be called by PickZeroconf(), which has already
215-
* lazy-initialized and verified everything.
216-
*/
217-
ZeroconfMemberMap::const_reference PickZeroconfHashRing(Expiry now,
218-
sticky_hash_t sticky_hash) noexcept;
219-
220203
/**
221204
* Like PickZeroconf(), but pick using Rendezvous Hashing.
222205
*
@@ -261,7 +244,7 @@ private:
261244

262245
private:
263246
/**
264-
* Fill #active_members and #sticky_ring.
247+
* Fill #active_members.
265248
*
266249
* Zeroconf only.
267250
*/

src/lb/ClusterConfig.hxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ struct LbClusterConfig {
9999

100100
#ifdef HAVE_AVAHI
101101
enum class StickyMethod : uint_least8_t {
102-
CONSISTENT_HASHING,
103-
104102
RENDEZVOUS_HASHING,
105103

106104
/**
107105
* Enable the #StickyCache for Zeroconf?
108106
*/
109107
CACHE,
110-
} sticky_method = StickyMethod::CONSISTENT_HASHING;
108+
} sticky_method = StickyMethod::RENDEZVOUS_HASHING;
111109
#endif
112110

113111
LbSimpleHttpResponse fallback;

src/lb/ConfigParser.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ static LbClusterConfig::StickyMethod
567567
ParseStickyMethod(const char *s)
568568
{
569569
if (StringIsEqual(s, "consistent_hashing"))
570-
return LbClusterConfig::StickyMethod::CONSISTENT_HASHING;
570+
// TODO remove legacy setting
571+
return LbClusterConfig::StickyMethod::RENDEZVOUS_HASHING;
571572
else if (StringIsEqual(s, "rendezvous_hashing"))
572573
return LbClusterConfig::StickyMethod::RENDEZVOUS_HASHING;
573574
else if (StringIsEqual(s, "cache"))
@@ -602,7 +603,7 @@ LbConfigParser::Cluster::ParseLine(FileLineParser &line)
602603
#ifdef HAVE_AVAHI
603604
config.sticky_method = line.NextBool()
604605
? LbClusterConfig::StickyMethod::CACHE
605-
: LbClusterConfig::StickyMethod::CONSISTENT_HASHING;
606+
: LbClusterConfig::StickyMethod::RENDEZVOUS_HASHING;
606607
line.ExpectEnd();
607608
#else
608609
throw LineParser::Error("Zeroconf support is disabled at compile time");

src/lb/MemberHash.cxx

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

src/lb/MemberHash.hxx

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

0 commit comments

Comments
 (0)