Skip to content

Commit

Permalink
Separate goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Aug 1, 2024
1 parent 73d5445 commit 5510494
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions hammer/hammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (h *Hammer) Run(ctx context.Context) {
go h.writeThrottle.Run(ctx)

go func() {
tick := time.NewTicker(1 * time.Second)
tick := time.NewTicker(100 * time.Millisecond)
for {
select {
case <-ctx.Done():
Expand All @@ -190,28 +190,52 @@ func (h *Hammer) Run(ctx context.Context) {
if newSize > size {
klog.V(1).Infof("Updated checkpoint from %d to %d", size, newSize)
}
now := time.Now()
totalLatency := time.Duration(0)
queueLatency := time.Duration(0)
numLeaves := 0
for {
}
}
}()

go func() {
tick := time.NewTicker(100 * time.Millisecond)
size := h.tracker.LatestConsistent.Size
for {
select {
case <-ctx.Done():
return
case <-tick.C:
}
newSize := h.tracker.LatestConsistent.Size
if newSize <= size {
continue
}
now := time.Now()
totalLatency := time.Duration(0)
queueLatency := time.Duration(0)
numLeaves := 0
var sample *leafTime
for {
if sample == nil {
l, ok := <-h.leafSampleChan
if !ok {
break
}
if l.queuedAt.After(now) {
// We've caught up with everything which happened in this "epoch"
break
}
queueLatency += l.assignedAt.Sub(l.queuedAt)
totalLatency += now.Sub(l.queuedAt)

numLeaves++
sample = &l
}
if sample.idx >= newSize || sample.queuedAt.After(now) {
break
}
queueLatency += sample.assignedAt.Sub(sample.queuedAt)
totalLatency += now.Sub(sample.queuedAt)

numLeaves++
sample = nil
}
if numLeaves > 0 {
h.integrationTime.Add(float64(totalLatency/time.Millisecond) / float64(numLeaves))
h.queueTime.Add(float64(queueLatency/time.Millisecond) / float64(numLeaves))
}
}

klog.Exitf("BAM")

Check failure on line 238 in hammer/hammer.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)
}()
}

Expand Down

0 comments on commit 5510494

Please sign in to comment.