Skip to content

Commit daa2008

Browse files
committed
feat: prep for the demo
- add SIM_MAX_TOPICS - add maxPeers to config.go - fix readme steps - fix AddPeerEnter - fix tracing in test-discovery-states - add reset-env
1 parent d9168a1 commit daa2008

File tree

8 files changed

+64
-34
lines changed

8 files changed

+64
-34
lines changed

README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ Common setup for all the scenarios:
126126

127127
- run `task start-env`
128128
- run `task start-am-dbg`
129-
- visit Grafana at http://localhost:3000/dashboard/import
130-
- import `assets/sim-grafana.dashboard.json`
131-
- or `task gen-grafana-dashboard` and provide machine IDs via `GRAFANA_IDS`
132-
- switch TTY
129+
- set up Grafana
130+
- visit http://localhost:3000/connections/datasources/new
131+
- login admin/admin, skip
132+
- add a Prometheus data source http://prometheus:9090
133+
- visit http://localhost:3000/dashboard/import
134+
- login admin/admin, skip
135+
- paste import [`assets/sim-grafana.dashboard.json`](https://raw.githubusercontent.com/pancsta/go-libp2p-pubsub-benchmark/main/assets/sim-grafana.dashboard.json)
136+
- or `task gen-grafana-dashboard` and provide machine IDs via `GRAFANA_IDS`
137+
- switch TTY
133138
- run `task start-sim`
134139
- visit the first TTY for am-dbg history
135140
- requires `SIM_AM_DEBUG=1`
136-
- visit the Grafana dashboard at http://localhost:3000/d/f4ac0cf1-0f3d-4b41-9e04-d6b0e68b49bc/?orgId=1&refresh=5s&from=now-5m&to=now
141+
- visit the Grafana dashboard
137142
- requires `SIM_METRICS=1`
138143

139144
## Benchmarking a custom implementation
@@ -156,11 +161,16 @@ Common setup for all the scenarios:
156161

157162
- replace `sim.env` and `internal/sim/config.go` with `sim.yml`
158163
- allow for env overrides
164+
- abstract discovery
165+
- fix DHT lag
166+
- enable mDNS
159167
- reimplement more things as machines
160168
- gossipsub, score, topic
161169
- fix benchmark failures
170+
- fix pubsub "Topic not found" err
162171
- replace `bench.env` and all the benchmark repo defs with `bench.yml`
163172
- allow for env overrides
164173
- bind [universal connectivity UI](https://github.com/libp2p/universal-connectivity/tree/main/go-peer) to see the traffic
165174
- needs a list of topics, doesn't need a msg form
166175
- subtract `time.Sleep()` from benchmark results
176+
- "delivered/missed msgs" metrics should also be averaged, not just counters

Taskfile.yml

+15-10
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ tasks:
2121

2222
test-discovery-states:
2323
cmds:
24-
- pushd $REPOS_PATH/states; go test -test.run "^\QTestSimpleDiscovery" -v *.go
25-
dotenv: ['nodebug.env']
24+
- pushd $REPOS_PATH/states;
25+
go test -test.run "^\QTestSimpleDiscovery" -v *.go
2626

2727
test-discovery-origin:
2828
cmds:
29-
- pushd $REPOS_PATH/origin; go test -test.run "^\QTestSimpleDiscovery" -v *.go
30-
dotenv: ['nodebug.env']
29+
- pushd $REPOS_PATH/origin;
30+
go test -test.run "^\QTestSimpleDiscovery" -v *.go
3131

3232
bench-pdf:
3333
cmds:
@@ -121,19 +121,24 @@ tasks:
121121
start-env:
122122
desc: Starts the docker environment (prometheus, grafana, pushgateway, jaeger)
123123
cmds:
124-
- |
125-
docker-compose --file config/docker-compose.yml \
126-
--project-name go-libp2p-pubsub-benchmark \
124+
- docker-compose --file config/docker-compose.yml
125+
--project-name go-libp2p-pubsub-benchmark
127126
up -d
128127

129128
stop-env:
130129
desc: Stops the docker environment (prometheus, grafana, pushgateway, jaeger)
131130
cmds:
132-
- |
133-
docker-compose --file config/docker-compose.yml \
134-
--project-name go-libp2p-pubsub-benchmark \
131+
- docker-compose --file config/docker-compose.yml
132+
--project-name go-libp2p-pubsub-benchmark
135133
down
136134

135+
reset-env:
136+
desc: Stops the docker environment (prometheus, grafana, pushgateway, jaeger)
137+
cmds:
138+
- docker-compose --file config/docker-compose.yml
139+
--project-name go-libp2p-pubsub-benchmark
140+
down -v
141+
137142
gen-grafana-dashboard:
138143
desc: Generate a Grafana dashboard for the simulator and first 3 hosts
139144
dir: scripts

cmd/sim/cmd_sim.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
func main() {
2020
// load .env
21-
_ = godotenv.Load("sim.env", ".env")
21+
_ = godotenv.Load(".env", "sim.env")
2222

2323
// init the simulator
2424
ctx := context.Background()
@@ -29,14 +29,20 @@ func main() {
2929
}
3030

3131
// parse max peers
32-
maxPeers := 30
3332
if os.Getenv("SIM_MAX_PEERS") != "" {
3433
v, err := strconv.Atoi(os.Getenv("SIM_MAX_PEERS"))
3534
if err == nil {
36-
maxPeers = v
35+
s.MaxPeers = v
36+
}
37+
}
38+
39+
// parse max topics
40+
if os.Getenv("SIM_MAX_TOPICS") != "" {
41+
v, err := strconv.Atoi(os.Getenv("SIM_MAX_TOPICS"))
42+
if err == nil {
43+
s.MaxTopics = v
3744
}
3845
}
39-
s.MaxPeers = maxPeers
4046

4147
// parse duration
4248
duration := 5 * time.Minute

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
module github.com/pancsta/go-libp2p-pubsub-benchmark
22

3-
replace github.com/pancsta/go-libp2p-pubsub => ../go-libp2p-pubsub
4-
53
go 1.22.3
64

75
require (
86
github.com/brianvoe/gofakeit/v7 v7.0.2
97
github.com/joho/godotenv v1.5.1
108
github.com/libp2p/go-libp2p v0.35.0
119
github.com/libp2p/go-libp2p-kad-dht v0.25.2
12-
github.com/pancsta/asyncmachine-go v0.6.0
13-
github.com/pancsta/go-libp2p-pubsub v0.11.3
10+
github.com/pancsta/asyncmachine-go v0.6.2
11+
github.com/pancsta/go-libp2p-pubsub v0.11.4
1412
github.com/prometheus/client_golang v1.19.1
1513
github.com/samber/lo v1.39.0
1614
github.com/sourcegraph/conc v0.3.0

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr
319319
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
320320
github.com/pancsta/asyncmachine-go v0.6.0 h1:5gqvELRyjULDqOSoMFZ2K0KOoYzVCL28/UQUIByPl04=
321321
github.com/pancsta/asyncmachine-go v0.6.0/go.mod h1:hoG7VB315eqgnRvVfZQQcw7B7CrJMkwqNNHH8N+7CGs=
322+
github.com/pancsta/asyncmachine-go v0.6.1/go.mod h1:hoG7VB315eqgnRvVfZQQcw7B7CrJMkwqNNHH8N+7CGs=
323+
github.com/pancsta/asyncmachine-go v0.6.2/go.mod h1:hoG7VB315eqgnRvVfZQQcw7B7CrJMkwqNNHH8N+7CGs=
324+
github.com/pancsta/go-libp2p-pubsub v0.11.4/go.mod h1:owZ/Fi/draxxvWwljUejC9bTfHwdKqOWd16JirWs058=
322325
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
323326
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
324327
github.com/pion/datachannel v1.5.6 h1:1IxKJntfSlYkpUj8LlYRSWpYiTTC02nUrOE8T3DqGeg=

internal/sim/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828

2929
maxHistoryEntries = 1000
3030
maxTopics = 20
31+
maxPeers = 30
3132
maxTopicPerPeer = 15
3233
maxPeersPerTopic = 10
3334
maxFriendsPerPeer = 10

internal/sim/sim.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Sim struct {
5656
promUrl string
5757
discServer *mockDiscoveryServer
5858
MaxPeers int
59+
MaxTopics int
5960
}
6061

6162
func NewSim(ctx context.Context, exportMetrics, debugAM bool) (*Sim, error) {
@@ -67,7 +68,9 @@ func NewSim(ctx context.Context, exportMetrics, debugAM bool) (*Sim, error) {
6768
exportMetrics: exportMetrics,
6869
promUrl: promUrl,
6970
debugAM: debugAM,
70-
MaxPeers: 30,
71+
// config to override
72+
MaxPeers: maxPeers,
73+
MaxTopics: maxTopics,
7174
}
7275

7376
opts := &am.Opts{}
@@ -179,6 +182,10 @@ func (s *Sim) StartState(e *am.Event) {
179182
// return
180183
// }
181184

185+
if printMetrics {
186+
// TODO print config
187+
}
188+
182189
s.discServer = newMockDiscoveryServer()
183190

184191
// init the initial simulation
@@ -256,15 +263,14 @@ func (s *Sim) HeartbeatState(e *am.Event) {
256263
}
257264

258265
func (s *Sim) AddPeerEnter(e *am.Event) bool {
259-
_, ok := e.Args["amount"].(int)
260-
return ok && len(s.peers) < s.MaxPeers
266+
return len(s.peers) < s.MaxPeers
261267
}
262268

263269
func (s *Sim) AddPeerState(e *am.Event) {
264270
s.Mach.Remove1(ss.AddPeer, nil)
265271

266-
amount := e.Args["amount"].(int)
267-
if amount == 0 {
272+
amount, ok := e.Args["amount"].(int)
273+
if !ok {
268274
amount = 1
269275
}
270276

@@ -329,7 +335,7 @@ func (s *Sim) AddTopicEnter(e *am.Event) bool {
329335
p := s.pickRandPeerCond(func(p *Peer) bool {
330336
return len(p.simTopics) < maxTopicPerPeer
331337
})
332-
return len(s.topics) < maxTopics && p != nil
338+
return len(s.topics) < s.MaxTopics && p != nil
333339
}
334340

335341
func (s *Sim) AddTopicState(e *am.Event) {
@@ -342,7 +348,7 @@ func (s *Sim) AddTopicState(e *am.Event) {
342348

343349
// add N topics
344350
for i := 0; i < amount; i++ {
345-
if len(s.topics) >= maxTopics {
351+
if len(s.topics) >= s.MaxTopics {
346352
break
347353
}
348354

@@ -440,7 +446,6 @@ func (s *Sim) AddRandomFriendState(e *am.Event) {
440446
p2.simTopicJoined[randTopic] = time.Now()
441447
p2.mach.Add1(ssp.JoiningTopic, am.A{"Topic.id": randTopic})
442448
}
443-
s.Mach.Log("Added friend: %s + %s", p1.id, p2.id)
444449
}
445450

446451
// GCState does various periodic cleanups.
@@ -456,6 +461,7 @@ func (s *Sim) GCState(e *am.Event) {
456461
s.Mach.Log("Friend not found: %s", fid)
457462
continue
458463
}
464+
459465
if len(lo.Intersect(p1.simTopics, p2.simTopics)) > 0 {
460466
newFriends = append(newFriends, fid)
461467
} else {
@@ -464,6 +470,7 @@ func (s *Sim) GCState(e *am.Event) {
464470
s.Mach.Log("Removed friend: %s - %s", p1.id, p2.id)
465471
}
466472
}
473+
467474
p1.simFriends = newFriends
468475
}
469476

@@ -825,7 +832,7 @@ func (s *Sim) topicPeerChange(topic string, amount int) {
825832
s.Mach.Eval("topicPeerChange", func() {
826833
t, ok := s.topics[topic]
827834
if !ok {
828-
s.Mach.Log("Error: topic not found", topic)
835+
s.Mach.Log("Error: topic not found %s", topic)
829836
return
830837
}
831838
t.peersCount += amount
@@ -842,7 +849,7 @@ func (s *Sim) topicMsgs(topic string, amount int) {
842849
s.Mach.Eval("topicPeerChange", func() {
843850
t, ok := s.topics[topic]
844851
if !ok {
845-
s.Mach.Log("Error: topic not found", topic)
852+
s.Mach.Log("Error: topic not found %s", topic)
846853
return
847854
}
848855
t.msgsLog = append(t.msgsLog, TopicMsgsLog{time.Now(), amount})

pkg/psmon/psmon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewPSMon(endpoint string, newOtelProvider NewOtelProviderFn) *PSMon {
5858
isSim := strings.HasSuffix(os.Args[0], "sim") ||
5959
strings.HasSuffix(os.Args[0], "sim_go")
6060
if !isSim {
61-
_ = godotenv.Load("bench.env", ".env")
61+
_ = godotenv.Load(".env", "bench.env")
6262
}
6363

6464
// load .env

0 commit comments

Comments
 (0)