Skip to content

Commit 29dc7d3

Browse files
authored
feat: add flags for bitswap server internals (#1182)
1 parent f157694 commit 29dc7d3

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

cmd/booster-bitswap/run.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ var runCmd = &cli.Command{
7777
Usage: "the endpoints for fetching one or more custom BadBits list instead of the default one at https://badbits.dwebops.pub/denylist.json",
7878
Value: cli.NewStringSlice("https://badbits.dwebops.pub/denylist.json"),
7979
},
80+
&cli.IntFlag{
81+
Name: "engine-blockstore-worker-count",
82+
Usage: "number of threads for blockstore operations. Used to throttle the number of concurrent requests to the block store",
83+
Value: 128,
84+
},
85+
&cli.IntFlag{
86+
Name: "engine-task-worker-count",
87+
Usage: "number of worker threads used for preparing and packaging responses before they are sent out. This number should generally be equal to task-worker-count",
88+
Value: 128,
89+
},
90+
&cli.IntFlag{
91+
Name: "max-outstanding-bytes-per-peer",
92+
Usage: "maximum number of bytes (across all tasks) pending to be processed and sent to any individual peer (default 32MiB)",
93+
Value: 32 << 20,
94+
},
95+
&cli.IntFlag{
96+
Name: "target-message-size",
97+
Usage: "target size of messages for bitswap to batch messages, actual size may vary depending on the queue (default 1MiB)",
98+
Value: 1 << 20,
99+
},
100+
&cli.IntFlag{
101+
Name: "task-worker-count",
102+
Usage: "Number of threads (goroutines) sending outgoing messages. Throttles the number of concurrent send operations",
103+
Value: 128,
104+
},
80105
},
81106
Action: func(cctx *cli.Context) error {
82107
if cctx.Bool("pprof") {
@@ -143,7 +168,13 @@ var runCmd = &cli.Command{
143168

144169
// Start the bitswap server
145170
log.Infof("Starting booster-bitswap node on port %d", port)
146-
err = server.Start(ctx, proxyAddrInfo)
171+
err = server.Start(ctx, proxyAddrInfo, &BitswapServerOptions{
172+
EngineBlockstoreWorkerCount: cctx.Int("engine-blockstore-worker-count"),
173+
EngineTaskWorkerCount: cctx.Int("engine-task-worker-count"),
174+
MaxOutstandingBytesPerPeer: cctx.Int("max-outstanding-bytes-per-peer"),
175+
TargetMessageSize: cctx.Int("target-message-size"),
176+
TaskWorkerCount: cctx.Int("task-worker-count"),
177+
})
147178
if err != nil {
148179
return err
149180
}

cmd/booster-bitswap/server.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ type BitswapServer struct {
2929
host host.Host
3030
}
3131

32+
type BitswapServerOptions struct {
33+
EngineBlockstoreWorkerCount int
34+
EngineTaskWorkerCount int
35+
TaskWorkerCount int
36+
TargetMessageSize int
37+
MaxOutstandingBytesPerPeer int
38+
}
39+
3240
func NewBitswapServer(
3341
remoteStore blockstore.Blockstore,
3442
host host.Host,
@@ -39,7 +47,7 @@ func NewBitswapServer(
3947

4048
const protectTag = "bitswap-server-to-proxy"
4149

42-
func (s *BitswapServer) Start(ctx context.Context, proxy *peer.AddrInfo) error {
50+
func (s *BitswapServer) Start(ctx context.Context, proxy *peer.AddrInfo, opts *BitswapServerOptions) error {
4351
s.ctx, s.cancel = context.WithCancel(ctx)
4452
s.proxy = proxy
4553

@@ -63,7 +71,11 @@ func (s *BitswapServer) Start(ctx context.Context, proxy *peer.AddrInfo) error {
6371
return err
6472
}
6573
bsopts := []server.Option{
66-
server.MaxOutstandingBytesPerPeer(1 << 20),
74+
server.EngineBlockstoreWorkerCount(opts.EngineBlockstoreWorkerCount),
75+
server.EngineTaskWorkerCount(opts.EngineTaskWorkerCount),
76+
server.MaxOutstandingBytesPerPeer(opts.MaxOutstandingBytesPerPeer),
77+
server.TaskWorkerCount(opts.TaskWorkerCount),
78+
server.WithTargetMessageSize(opts.TargetMessageSize),
6779
server.WithPeerBlockRequestFilter(func(p peer.ID, c cid.Cid) bool {
6880
fulfill, err := s.filter.FulfillRequest(p, c)
6981
// peer request filter expects a true if the request should be fulfilled, so

docker/devnet/booster-bitswap/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ fi
2121

2222
echo Starting booster-bitswap...
2323
export GOLOG_LOG_LEVEL=remote-blockstore=debug,booster=debug,engine=debug,bitswap-server=debug
24-
exec booster-bitswap --vv run --api-boost=$BOOST_API_INFO --tracing
24+
exec booster-bitswap --vv run --api-boost=$BOOST_API_INFO --tracing --engine-blockstore-worker-count=64 --engine-task-worker-count=64 --max-outstanding-bytes-per-peer=8388608 --target-message-size=524288 --task-worker-count=64

0 commit comments

Comments
 (0)