Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
ring_hash LB: cap ring size to 4096 with channel arg to override (grp…
Browse files Browse the repository at this point in the history
…c#31692)

* ring_hash LB: cap ring size to 4096 with channel arg to override

* change default max_ring_size value to 4096 in LB policy config
  • Loading branch information
markdroth authored Dec 7, 2022
1 parent 4e90f43 commit a34f9e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/grpc/impl/codegen/grpc_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ typedef struct {
"grpc.service_config_disable_resolution"
/** LB policy name. */
#define GRPC_ARG_LB_POLICY_NAME "grpc.lb_policy_name"
/** Cap for ring size in the ring_hash LB policy. The min and max ring size
values set in the LB policy config will be capped to this value.
Default is 4096. */
#define GRPC_ARG_RING_HASH_LB_RING_SIZE_CAP "grpc.lb.ring_hash.ring_size_cap"
/** The grpc_socket_mutator instance that set the socket options. A pointer. */
#define GRPC_ARG_SOCKET_MUTATOR "grpc.socket_mutator"
/** The grpc_socket_factory instance to create and bind sockets. A pointer. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class RingHashLbConfig : public LoadBalancingPolicy::Config {
// ring_hash LB policy
//

constexpr size_t kRingSizeCapDefault = 4096;

class RingHash : public LoadBalancingPolicy {
public:
explicit RingHash(Args args);
Expand Down Expand Up @@ -518,8 +520,12 @@ RingHash::RingHashSubchannelList::RingHashSubchannelList(
// weights aren't provided, all hosts should get an equal number of hashes. In
// the case where this number exceeds the max_ring_size, it's scaled back down
// to fit.
const size_t min_ring_size = policy->config_->min_ring_size();
const size_t max_ring_size = policy->config_->max_ring_size();
const size_t ring_size_cap = args.GetInt(GRPC_ARG_RING_HASH_LB_RING_SIZE_CAP)
.value_or(kRingSizeCapDefault);
const size_t min_ring_size =
std::min(policy->config_->min_ring_size(), ring_size_cap);
const size_t max_ring_size =
std::min(policy->config_->max_ring_size(), ring_size_cap);
const double scale = std::min(
std::ceil(min_normalized_weight * min_ring_size) / min_normalized_weight,
static_cast<double>(max_ring_size));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ UniqueTypeName RequestHashAttributeName();
// hash size validity.
struct RingHashConfig {
uint64_t min_ring_size = 1024;
uint64_t max_ring_size = 8388608;
uint64_t max_ring_size = 4096;

static const JsonLoaderInterface* JsonLoader(const JsonArgs&);
void JsonPostLoad(const Json& json, const JsonArgs&,
Expand Down

0 comments on commit a34f9e1

Please sign in to comment.