tinyrelayfile
tinyrelay/internal/relay/bench_test.go/

internal/relay/bench_test.go raw
1package relay
2
3import (
4 "net/http/httptest"
5 "strconv"
6 "strings"
7 "testing"
8
9 "github.com/FelineStateMachine/tinyrelay/internal/event"
10)
11
12func BenchmarkFanout(b *testing.B) {
13 for _, count := range []int{10, 100, 1000} {
14 b.Run("clients="+strconv.Itoa(count), func(b *testing.B) {
15 r := New(testBackend{}, Config{MaxPendingBytes: 64 << 20})
16 clients := make([]*client, 0, count)
17 for i := 0; i < count; i++ {
18 c := newClient(r, nil, httptest.NewRequest("GET", "http://relay.example/", nil))
19 c.subs["all"] = subscription{filters: []event.Filter{{Kinds: []int{1}}}}
20 r.clients[c] = struct{}{}
21 clients = append(clients, c)
22 }
23 e := event.Event{ID: strings.Repeat("a", 64), Kind: 1, Content: "benchmark fanout"}
24 b.ResetTimer()
25 for i := 0; i < b.N; i++ {
26 r.BroadcastGenerated(e)
27 for _, c := range clients {
28 c.mu.Lock()
29 c.queue = c.queue[:0]
30 c.pending = 0
31 c.mu.Unlock()
32 }
33 }
34 })
35 }
36}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs