Skip to content

Commit

Permalink
Merge pull request #21 from nspcc-dev/zero-tps-fixes
Browse files Browse the repository at this point in the history
cmd: be carefull with counting zero TPS values
  • Loading branch information
roman-khimov authored Aug 25, 2020
2 parents d73c05a + cb85854 commit 3b477fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/internal/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type (
ErrCount int32
RPS []float64
TPS []float64
TPSPool []float64
Stats [][2]float64 // CPU, Mem
}

Expand Down Expand Up @@ -233,7 +234,13 @@ func (r *reporter) UpdateTPS(v float64) {
r.Lock()
defer r.Unlock()

r.TPS = append(r.TPS, v)
if v > 0 {
r.TPS = append(r.TPS, r.TPSPool...)
r.TPS = append(r.TPS, v)
r.TPSPool = nil
} else {
r.TPSPool = append(r.TPSPool, v)
}
}

// UpdateRes sets current resource usage by containers.
Expand Down
13 changes: 12 additions & 1 deletion cmd/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type (
waiter *sync.WaitGroup
countTxs *atomic.Int32 // stores count of completed queries
countErr *atomic.Int32
hasStarted *atomic.Bool
parsedCount int
parsedBlocks map[int]struct{}
}
Expand Down Expand Up @@ -194,6 +195,7 @@ func NewWorkers(opts ...WorkerOption) (Worker, error) {
sentOut: make(chan struct{}),
countTxs: atomic.NewInt32(0),
countErr: atomic.NewInt32(0),
hasStarted: atomic.NewBool(false),
parsedBlocks: make(map[int]struct{}),
}

Expand Down Expand Up @@ -343,6 +345,8 @@ func (d *doer) parse(ctx context.Context, startBlock int, lastTime *uint64) (las

if cnt = len(blk.Transactions); cnt < 1 {
log.Printf("empty block: %d", i)
} else if !d.hasStarted.Load() {
d.hasStarted.Store(true)
}

// Timestamp is in milliseconds so we multiply numerator by 1000 to be more precise.
Expand All @@ -354,10 +358,17 @@ func (d *doer) parse(ctx context.Context, startBlock int, lastTime *uint64) (las
// update last block timestamp
*lastTime = blk.Timestamp

// do not add zero TPS in case if there were no non-empty blocks yet
if tps == 0 {
if !d.hasStarted.Load() {
continue
}
}

// report current tps
d.tpsReporter(tps)

for i := 1; i < cnt; i++ {
for i := 0; i < cnt; i++ {
tx := blk.Transactions[i]
if len(tx.Scripts) > 0 {
if _, ok := d.dump.Hashes[tx.Hash().String()]; ok {
Expand Down

0 comments on commit 3b477fb

Please sign in to comment.