Skip to content

Commit 3022572

Browse files
committed
set some pprof labels for different goroutines
1 parent 7a56ea7 commit 3022572

File tree

7 files changed

+48
-23
lines changed

7 files changed

+48
-23
lines changed

agreement/service.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package agreement
1919
//go:generate dbgen -i agree.sql -p agreement -n agree -o agreeInstall.go -h ../scripts/LICENSE_HEADER
2020
import (
2121
"context"
22+
"runtime/pprof"
2223
"time"
2324

2425
"github.com/algorand/go-algorand/config"
@@ -143,8 +144,12 @@ func (s *Service) Start() {
143144
input := make(chan externalEvent)
144145
output := make(chan []action)
145146
ready := make(chan externalDemuxSignals)
146-
go s.demuxLoop(ctx, input, output, ready)
147-
go s.mainLoop(input, output, ready)
147+
pprof.Do(context.Background(), pprof.Labels("worker", "agreement.demux"), func(_ context.Context) {
148+
go s.demuxLoop(ctx, input, output, ready)
149+
})
150+
pprof.Do(context.Background(), pprof.Labels("worker", "agreement.main"), func(_ context.Context) {
151+
go s.mainLoop(input, output, ready)
152+
})
148153
}
149154

150155
// Shutdown the execution of the protocol.

data/txHandler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"fmt"
2323
"io"
24+
"runtime/pprof"
2425
"sync"
2526

2627
"github.com/algorand/go-algorand/crypto"
@@ -100,7 +101,9 @@ func (handler *TxHandler) Start() {
100101
{Tag: protocol.TxnTag, MessageHandler: network.HandlerFunc(handler.processIncomingTxn)},
101102
})
102103
handler.backlogWg.Add(1)
103-
go handler.backlogWorker()
104+
pprof.Do(context.Background(), pprof.Labels("worker", "TxHandler.backlogWorker"), func(_ context.Context) {
105+
go handler.backlogWorker()
106+
})
104107
}
105108

106109
// Stop suspends the processing of incoming messages at the transaction handler

ledger/notifier.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ledger
1919
import (
2020
"context"
2121
"database/sql"
22+
"runtime/pprof"
2223
"sync"
2324

2425
"github.com/algorand/go-deadlock"
@@ -92,7 +93,9 @@ func (bn *blockNotifier) loadFromDisk(l ledgerForTracker, _ basics.Round) error
9293
bn.running = true
9394
bn.pendingBlocks = nil
9495
bn.closing.Add(1)
95-
go bn.worker()
96+
pprof.Do(context.Background(), pprof.Labels("worker", "blockNotifier"), func(_ context.Context) {
97+
go bn.worker()
98+
})
9699
return nil
97100
}
98101

network/wsNetwork.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"path"
3131
"regexp"
3232
"runtime"
33+
"runtime/pprof"
3334
"strconv"
3435
"strings"
3536
"sync"
@@ -811,7 +812,9 @@ func (wn *WebsocketNetwork) Start() {
811812
}
812813
if wn.listener != nil {
813814
wn.wg.Add(1)
814-
go wn.httpdThread()
815+
pprof.Do(context.Background(), pprof.Labels("worker", "httpdThread"), func(ctx context.Context) {
816+
go wn.httpdThread()
817+
})
815818
}
816819
wn.wg.Add(1)
817820
go wn.meshThread()
@@ -821,11 +824,13 @@ func (wn *WebsocketNetwork) Start() {
821824
wn.peersConnectivityCheckTicker.Stop()
822825
}
823826
wn.peersConnectivityCheckTicker = time.NewTicker(connectionActivityMonitorInterval)
824-
for i := 0; i < incomingThreads; i++ {
825-
wn.wg.Add(1)
826-
// We pass the peersConnectivityCheckTicker.C here so that we don't need to syncronize the access to the ticker's data structure.
827-
go wn.messageHandlerThread(wn.peersConnectivityCheckTicker.C)
828-
}
827+
pprof.Do(context.Background(), pprof.Labels("worker", "messageHandlerThread"), func(_ context.Context) {
828+
for i := 0; i < incomingThreads; i++ {
829+
wn.wg.Add(1)
830+
// We pass the peersConnectivityCheckTicker.C here so that we don't need to syncronize the access to the ticker's data structure.
831+
go wn.messageHandlerThread(wn.peersConnectivityCheckTicker.C)
832+
}
833+
})
829834
wn.wg.Add(1)
830835
go wn.broadcastThread()
831836
if wn.prioScheme != nil {

node/node.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"io/ioutil"
2525
"os"
2626
"path/filepath"
27+
"runtime/pprof"
2728
"strings"
2829
"sync"
2930
"time"
@@ -208,9 +209,11 @@ func MakeFull(log logging.Logger, rootDir string, cfg config.Local, phonebookAdd
208209
return nil, err
209210
}
210211

211-
node.cryptoPool = execpool.MakePool(node)
212-
node.lowPriorityCryptoVerificationPool = execpool.MakeBacklog(node.cryptoPool, 2*node.cryptoPool.GetParallelism(), execpool.LowPriority, node)
213-
node.highPriorityCryptoVerificationPool = execpool.MakeBacklog(node.cryptoPool, 2*node.cryptoPool.GetParallelism(), execpool.HighPriority, node)
212+
node.cryptoPool = execpool.MakePool(node, "worker", "cryptoPool")
213+
node.lowPriorityCryptoVerificationPool = execpool.MakeBacklog(node.cryptoPool, 2*node.cryptoPool.GetParallelism(),
214+
execpool.LowPriority, node, "worker", "lowPriorityCryptoVerificationPool")
215+
node.highPriorityCryptoVerificationPool = execpool.MakeBacklog(node.cryptoPool, 2*node.cryptoPool.GetParallelism(),
216+
execpool.HighPriority, node, "worker", "highPriorityCryptoVerificationPool")
214217
node.ledger, err = data.LoadLedger(node.log, ledgerPathnamePrefix, false, genesis.Proto, genalloc, node.genesisID, node.genesisHash, []ledger.BlockListener{}, cfg)
215218
if err != nil {
216219
log.Errorf("Cannot initialize ledger (%s): %v", ledgerPathnamePrefix, err)
@@ -378,8 +381,9 @@ func (node *AlgorandFullNode) startMonitoringRoutines() {
378381
node.monitoringRoutinesWaitGroup.Add(2)
379382
go node.txPoolGaugeThread(node.ctx.Done())
380383
// Delete old participation keys
381-
go node.oldKeyDeletionThread(node.ctx.Done())
382-
384+
pprof.Do(context.Background(), pprof.Labels("worker", "oldKeyDeletionThread"), func(_ context.Context) {
385+
go node.oldKeyDeletionThread(node.ctx.Done())
386+
})
383387
// TODO re-enable with configuration flag post V1
384388
//go logging.UsageLogThread(node.ctx, node.log, 100*time.Millisecond, nil)
385389
}

util/execpool/backlog.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package execpool
1818

1919
import (
2020
"context"
21+
"runtime/pprof"
2122
"sync"
2223
)
2324

@@ -46,7 +47,7 @@ type BacklogPool interface {
4647
}
4748

4849
// MakeBacklog creates a backlog
49-
func MakeBacklog(execPool ExecutionPool, backlogSize int, priority Priority, owner interface{}) BacklogPool {
50+
func MakeBacklog(execPool ExecutionPool, backlogSize int, priority Priority, owner interface{}, profLabels ...string) BacklogPool {
5051
if backlogSize < 0 {
5152
return nil
5253
}
@@ -58,7 +59,7 @@ func MakeBacklog(execPool ExecutionPool, backlogSize int, priority Priority, own
5859
bl.ctx, bl.ctxCancel = context.WithCancel(context.Background())
5960
if bl.pool == nil {
6061
// create one internally.
61-
bl.pool = MakePool(bl)
62+
bl.pool = MakePool(bl, append(profLabels, "execpool", "internal")...)
6263
}
6364
if backlogSize == 0 {
6465
// use the number of cpus in the system.
@@ -67,7 +68,9 @@ func MakeBacklog(execPool ExecutionPool, backlogSize int, priority Priority, own
6768
bl.buffer = make(chan backlogItemTask, backlogSize)
6869

6970
bl.wg.Add(1)
70-
go bl.worker()
71+
pprof.Do(context.Background(), pprof.Labels(profLabels...), func(_ context.Context) {
72+
go bl.worker()
73+
})
7174
return bl
7275
}
7376

util/execpool/pool.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package execpool
1919
import (
2020
"context"
2121
"runtime"
22+
"runtime/pprof"
2223
"sync"
2324
)
2425

@@ -68,7 +69,7 @@ type enqueuedTask struct {
6869
}
6970

7071
// MakePool creates a pool.
71-
func MakePool(owner interface{}) ExecutionPool {
72+
func MakePool(owner interface{}, profLabels ...string) ExecutionPool {
7273
p := &pool{
7374
inputs: make([]chan enqueuedTask, numPrios),
7475
numCPUs: runtime.NumCPU(),
@@ -81,10 +82,11 @@ func MakePool(owner interface{}) ExecutionPool {
8182
}
8283

8384
p.wg.Add(p.numCPUs)
84-
for i := 0; i < p.numCPUs; i++ {
85-
go p.worker()
86-
}
87-
85+
pprof.Do(context.Background(), pprof.Labels(profLabels...), func(_ context.Context) {
86+
for i := 0; i < p.numCPUs; i++ {
87+
go p.worker()
88+
}
89+
})
8890
return p
8991
}
9092

0 commit comments

Comments
 (0)