Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overlapping checker #32

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions loadtest/cmd/backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -218,6 +230,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{}{}
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions loadtest/cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
})
Expand Down
16 changes: 10 additions & 6 deletions loadtest/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading