From 72147da3a80f2ee8a6826a45bb33c5afa40190fb Mon Sep 17 00:00:00 2001 From: castaneai Date: Tue, 5 Nov 2024 18:17:44 +0900 Subject: [PATCH 1/2] fix overlapping checker --- loadtest/cmd/backend/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/loadtest/cmd/backend/main.go b/loadtest/cmd/backend/main.go index 71f34c7..2ac00be 100644 --- a/loadtest/cmd/backend/main.go +++ b/loadtest/cmd/backend/main.go @@ -218,6 +218,8 @@ func (a *assignerWithOverlappingChecker) Assign(ctx context.Context, matches []* for _, ticket := range match.Tickets { if _, ok := ticketIDMap[ticket.Id]; ok { a.overlappingWithin.Add(ctx, 1) + } else { + ticketIDMap[ticket.Id] = struct{}{} } } } From 361393992972884cc54663623a38e8093cd05cc3 Mon Sep 17 00:00:00 2001 From: castaneai Date: Tue, 5 Nov 2024 18:18:28 +0900 Subject: [PATCH 2/2] loadtest: redis read-replica support --- loadtest/cmd/backend/main.go | 12 ++++++++++++ loadtest/cmd/frontend/main.go | 20 ++++++++++++++++---- loadtest/skaffold.yaml | 16 ++++++++++------ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/loadtest/cmd/backend/main.go b/loadtest/cmd/backend/main.go index 2ac00be..250f617 100644 --- a/loadtest/cmd/backend/main.go +++ b/loadtest/cmd/backend/main.go @@ -31,11 +31,13 @@ import ( const ( minimatchComponentKey = attribute.Key("component") + roleKey = attribute.Key("role") ) type config struct { RedisAddr string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"` AssignmentRedisAddr string `envconfig:"REDIS_ADDR_ASSIGNMENT"` + RedisAddrReadReplica string `envconfig:"REDIS_ADDR_READ_REPLICA"` TickRate time.Duration `envconfig:"TICK_RATE" default:"1s"` TicketCacheTTL time.Duration `envconfig:"TICKET_CACHE_TTL" default:"10s"` OverlappingCheckRedisAddr string `envconfig:"OVERLAPPING_CHECK_REDIS_ADDR"` @@ -119,6 +121,16 @@ func newRedisStateStore(conf *config) (statestore.BackendStore, error) { } opts = append(opts, statestore.WithSeparatedAssignmentRedis(asRedis)) } + if conf.RedisAddrReadReplica != "" { + replica, err := rueidisotel.NewClient(rueidis.ClientOption{ + InitAddress: []string{conf.RedisAddrReadReplica}, + DisableCache: true, + }, rueidisotel.MetricAttrs(minimatchComponentKey.String("backend"), roleKey.String("replica"))) + if err != nil { + return nil, fmt.Errorf("failed to new read-replica redis client: %w", err) + } + opts = append(opts, statestore.WithRedisReadReplicaClient(replica)) + } locker, err := rueidislock.NewLocker(rueidislock.LockerOption{ ClientOption: copt, ExtendInterval: 200 * time.Millisecond, diff --git a/loadtest/cmd/frontend/main.go b/loadtest/cmd/frontend/main.go index 7586e8f..132e9bf 100644 --- a/loadtest/cmd/frontend/main.go +++ b/loadtest/cmd/frontend/main.go @@ -31,13 +31,15 @@ import ( const ( minimatchComponentKey = attribute.Key("component") + roleKey = attribute.Key("role") ) type config struct { - RedisAddr string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"` - AssignmentRedisAddr string `envconfig:"REDIS_ADDR_ASSIGNMENT"` - Port string `envconfig:"PORT" default:"50504"` - TicketCacheTTL time.Duration `envconfig:"TICKET_CACHE_TTL" default:"10s"` + RedisAddr string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"` + AssignmentRedisAddr string `envconfig:"REDIS_ADDR_ASSIGNMENT"` + RedisAddrReadReplica string `envconfig:"REDIS_ADDR_READ_REPLICA"` + Port string `envconfig:"PORT" default:"50504"` + TicketCacheTTL time.Duration `envconfig:"TICKET_CACHE_TTL" default:"10s"` } func main() { @@ -102,6 +104,16 @@ func newRedisStateStore(conf *config) (statestore.FrontendStore, error) { } opts = append(opts, statestore.WithSeparatedAssignmentRedis(asRedis)) } + if conf.RedisAddrReadReplica != "" { + replica, err := rueidisotel.NewClient(rueidis.ClientOption{ + InitAddress: []string{conf.RedisAddrReadReplica}, + DisableCache: true, + }, rueidisotel.MetricAttrs(minimatchComponentKey.String("backend"), roleKey.String("replica"))) + if err != nil { + return nil, fmt.Errorf("failed to new read-replica redis client: %w", err) + } + opts = append(opts, statestore.WithRedisReadReplicaClient(replica)) + } locker, err := rueidislock.NewLocker(rueidislock.LockerOption{ ClientOption: copt, }) diff --git a/loadtest/skaffold.yaml b/loadtest/skaffold.yaml index 58a0da4..11331e1 100644 --- a/loadtest/skaffold.yaml +++ b/loadtest/skaffold.yaml @@ -33,17 +33,21 @@ deploy: frontend.deployment.replicas: 1 frontend.deployment.env: - name: REDIS_ADDR - value: "10.23.1.3:6379" -# - name: REDIS_ADDR_ASSIGNMENT -# value: "10.23.1.11:6379" + value: "10.23.1.21:6379" + - name: REDIS_ADDR_ASSIGNMENT + value: "10.23.1.11:6379" + - name: REDIS_ADDR_READ_REPLICA + value: "10.23.1.20:6379" backend.deployment.replicas: 1 backend.deployment.env: - name: REDIS_ADDR - value: "10.23.1.3:6379" + value: "10.23.1.21:6379" - name: OVERLAPPING_CHECK_REDIS_ADDR value: "10.23.1.11:6379" -# - name: REDIS_ADDR_ASSIGNMENT -# value: "10.23.1.11:6379" + - name: REDIS_ADDR_ASSIGNMENT + value: "10.23.1.11:6379" + - name: REDIS_ADDR_READ_REPLICA + value: "10.23.1.20:6379" - name: TICK_RATE value: "100ms" podMonitor.enabled: true