Skip to content

Commit be50af6

Browse files
committed
Update time measurement of metrics for proposal builder in 1:n (#6268)
## Motivation This updates how timing metrics for the proposal builder are calculated.
1 parent 8ca900d commit be50af6

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

miner/metrics.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,26 @@ var proposalBuild = metrics.NewHistogramWithBuckets(
1818
).WithLabelValues()
1919

2020
type latencyTracker struct {
21-
start time.Time
22-
data time.Time
23-
tortoise time.Time
24-
txs time.Time
25-
hash time.Time
26-
publish time.Time
21+
start time.Time
22+
end time.Time
23+
24+
data time.Duration
25+
tortoise time.Duration
26+
hash time.Duration
27+
txs time.Duration
28+
publish time.Duration
2729
}
2830

2931
func (lt *latencyTracker) total() time.Duration {
30-
return lt.publish.Sub(lt.start)
32+
return lt.end.Sub(lt.start)
3133
}
3234

3335
func (lt *latencyTracker) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
34-
encoder.AddDuration("data", lt.data.Sub(lt.start))
35-
encoder.AddDuration("tortoise", lt.tortoise.Sub(lt.data))
36-
encoder.AddDuration("hash", lt.hash.Sub(lt.tortoise))
37-
encoder.AddDuration("txs", lt.txs.Sub(lt.hash))
38-
encoder.AddDuration("publish", lt.publish.Sub(lt.hash))
36+
encoder.AddDuration("data", lt.data)
37+
encoder.AddDuration("tortoise", lt.tortoise)
38+
encoder.AddDuration("hash", lt.hash)
39+
encoder.AddDuration("txs", lt.txs)
40+
encoder.AddDuration("publish", lt.publish)
3941
total := lt.total()
4042
encoder.AddDuration("total", total)
4143
// arbitrary threshold that we want to highlight as a problem

miner/proposal_builder.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ func (pb *ProposalBuilder) initSignerData(
558558
}
559559

560560
func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
561-
start := time.Now()
561+
for _, ss := range pb.signers.signers {
562+
ss.latency.start = time.Now()
563+
}
562564
if err := pb.initSharedData(ctx, lid); err != nil {
563565
return err
564566
}
@@ -571,8 +573,8 @@ func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
571573
var eg errgroup.Group
572574
eg.SetLimit(pb.cfg.workersLimit)
573575
for _, ss := range signers {
574-
ss.latency.start = start
575576
eg.Go(func() error {
577+
start := time.Now()
576578
if err := pb.initSignerData(ctx, ss, lid); err != nil {
577579
if errors.Is(err, errAtxNotAvailable) {
578580
ss.log.Debug("smesher doesn't have atx that targets this epoch",
@@ -591,14 +593,15 @@ func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
591593
)
592594
}
593595
ss.session.prev = lid
594-
ss.latency.data = time.Now()
596+
ss.latency.data = time.Since(start)
595597
return nil
596598
})
597599
}
598600
if err := eg.Wait(); err != nil {
599601
return err
600602
}
601603

604+
start := time.Now()
602605
any := false
603606
for _, ss := range signers {
604607
if n := len(ss.session.eligibilities.proofs[lid]); n == 0 {
@@ -629,14 +632,16 @@ func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
629632
return fmt.Errorf("encode votes: %w", err)
630633
}
631634
for _, ss := range signers {
632-
ss.latency.tortoise = time.Now()
635+
ss.latency.tortoise = time.Since(start)
633636
}
634637

638+
start = time.Now()
635639
meshHash := pb.decideMeshHash(ctx, lid)
636640
for _, ss := range signers {
637-
ss.latency.hash = time.Now()
641+
ss.latency.hash = time.Since(start)
638642
}
639643

644+
start = time.Now()
640645
for _, ss := range signers {
641646
proofs := ss.session.eligibilities.proofs[lid]
642647
if len(proofs) == 0 {
@@ -654,7 +659,7 @@ func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
654659
)
655660

656661
txs := pb.conState.SelectProposalTXs(lid, len(proofs))
657-
ss.latency.txs = time.Now()
662+
ss.latency.txs = time.Since(start)
658663

659664
// needs to be saved before publishing, as we will query it in handler
660665
if ss.session.ref == types.EmptyBallotID {
@@ -667,6 +672,7 @@ func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
667672
}
668673

669674
eg.Go(func() error {
675+
start := time.Now()
670676
proposal := createProposal(
671677
&ss.session,
672678
pb.shared.beacon,
@@ -686,7 +692,8 @@ func (pb *ProposalBuilder) build(ctx context.Context, lid types.LayerID) error {
686692
zap.Error(err),
687693
)
688694
} else {
689-
ss.latency.publish = time.Now()
695+
ss.latency.publish = time.Since(start)
696+
ss.latency.end = time.Now()
690697
ss.log.Info("proposal created",
691698
log.ZContext(ctx),
692699
zap.Inline(proposal),

miner/proposal_builder_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ func TestMarshalLog(t *testing.T) {
891891
require.NoError(t, session.MarshalLogObject(encoder))
892892
})
893893
t.Run("latency", func(t *testing.T) {
894-
latency := &latencyTracker{start: time.Unix(0, 0), publish: time.Unix(1000, 0)}
894+
latency := &latencyTracker{start: time.Unix(0, 0), end: time.Unix(1000, 0)}
895895
require.NoError(t, latency.MarshalLogObject(encoder))
896896
})
897897
}

0 commit comments

Comments
 (0)