pubsub scales linearly with clients, so 2 pub=13ps and 4 sub=17ps

main
Bel LaPointe 2025-12-10 13:51:59 -07:00
parent 959e326329
commit 90a3256b7b
1 changed files with 17 additions and 16 deletions

View File

@ -221,23 +221,23 @@ func run(ctx context.Context) error {
) )
}) })
go with.Every(ctx, 1, func() { for i := 0; i < 2; i++ {
for i := 0; i < 2; i++ { topic := fmt.Sprintf("topic_%d", i)
topic := fmt.Sprintf("topic_%d", i) go with.Every(ctx, 1, func() {
if err := pub(topic, 1); err != nil { if err := pub(topic, 1); err != nil {
log.Printf("failed pub: %v", err) log.Printf("failed pub: %v", err)
} else { } else {
pubs.Add(1) pubs.Add(1)
} }
} })
}) }
with.Every(ctx, 1, func() { for i := 0; i < 2; i++ {
if err := func() error { topic := fmt.Sprintf("topic_%d", i)
for i := 0; i < 2; i++ { for j := 0; j < 2; j++ {
topic := fmt.Sprintf("topic_%d", i) group := fmt.Sprintf("group_%d", i)
for j := 0; j < 2; j++ { go with.Every(ctx, 1, func() {
group := fmt.Sprintf("group_%d", i) if err := func() error {
if partition, offset, _, err := sub(topic, group); err != nil { if partition, offset, _, err := sub(topic, group); err != nil {
return fmt.Errorf("failed sub: %w", err) return fmt.Errorf("failed sub: %w", err)
} else if partition == -1 { } else if partition == -1 {
@ -247,14 +247,15 @@ func run(ctx context.Context) error {
subs.Add(1) subs.Add(1)
lastCommit = fmt.Sprintf("%s/%s/%d@%d", topic, group, partition, offset) lastCommit = fmt.Sprintf("%s/%s/%d@%d", topic, group, partition, offset)
} }
return nil
}(); err != nil {
log.Printf("failed subs: %v", err)
} }
} })
return nil
}(); err != nil {
log.Printf("failed subs: %v", err)
} }
}) }
<-ctx.Done()
return ctx.Err() return ctx.Err()
}) })
} }