Skip to content

Commit

Permalink
Merge pull request #1310 from ecordell/idlepickerhashring
Browse files Browse the repository at this point in the history
balancer: rewrite the consistent hashring balancer to avoid recomputations
  • Loading branch information
ecordell authored May 18, 2023
2 parents 878f510 + 94145c0 commit 0026188
Show file tree
Hide file tree
Showing 5 changed files with 749 additions and 97 deletions.
3 changes: 1 addition & 2 deletions cmd/spicedb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
_ "google.golang.org/grpc/xds"

log "github.com/authzed/spicedb/internal/logging"
consistentbalancer "github.com/authzed/spicedb/pkg/balancer"
"github.com/authzed/spicedb/pkg/cmd"
cmdutil "github.com/authzed/spicedb/pkg/cmd/server"
"github.com/authzed/spicedb/pkg/cmd/testserver"
Expand All @@ -24,7 +23,7 @@ func main() {
kuberesolver.RegisterInCluster()

// Enable consistent hashring gRPC load balancer
balancer.Register(consistentbalancer.NewConsistentHashringBuilder(cmdutil.ConsistentHashringPicker))
balancer.Register(cmdutil.ConsistentHashringBuilder)

log.SetGlobalLogger(zerolog.New(os.Stdout))

Expand Down
9 changes: 5 additions & 4 deletions internal/testserver/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ var testResolverBuilder = &SafeManualResolverBuilder{}

func init() {
// register hashring balancer
balancer.Register(hashbalancer.NewConsistentHashringBuilder(
hashbalancer.NewConsistentHashringPickerBuilder(xxhash.Sum64, 1500, 1)),
)
balancer.Register(hashbalancer.NewConsistentHashringBuilder(xxhash.Sum64))

// Register a manual resolver.Builder that we can feed addresses for tests
// Registration is not thread safe, so we register a single resolver.Builder
Expand Down Expand Up @@ -168,7 +166,10 @@ func TestClusterWithDispatchAndCacheConfig(t testing.TB, size uint, ds datastore
combineddispatch.UpstreamAddr("test://" + prefix),
combineddispatch.PrometheusSubsystem(fmt.Sprintf("%s_%d_client_dispatch", prefix, i)),
combineddispatch.GrpcDialOpts(
grpc.WithDefaultServiceConfig(hashbalancer.BalancerServiceConfig),
grpc.WithDefaultServiceConfig((&hashbalancer.ConsistentHashringBalancerConfig{
ReplicationFactor: 1500,
Spread: 1,
}).MustToServiceConfigJSON()),
grpc.WithContextDialer(func(ctx context.Context, s string) (net.Conn, error) {
// it's possible grpc tries to dial before we have set the
// buffconn dialers, we have to return a "TempError" so that
Expand Down
Loading

0 comments on commit 0026188

Please sign in to comment.