Skip to content

Commit

Permalink
Fix throughput calculation when read/write is quick (#5)
Browse files Browse the repository at this point in the history
dperf can panic with the 'integer divide by zero' error. This happens in
some case with reading or writing happens in less than one second.

Calculate read/write throughput differently to avoid zero division.
  • Loading branch information
vadmeste authored Jun 13, 2022
1 parent a46da02 commit 0780163
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/dperf/run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func (d *DrivePerf) runReadTest(ctx context.Context, path string) (uint64, error
}
of.Close()

timeTakenInSeconds := time.Since(startTime).Seconds()
return d.FileSize / uint64(timeTakenInSeconds), nil
throughputInSeconds := d.FileSize * uint64(time.Second) / uint64(time.Since(startTime))
return throughputInSeconds, nil
}

// disableDirectIO - disables directio mode.
Expand Down Expand Up @@ -212,7 +212,7 @@ func (d *DrivePerf) runWriteTest(ctx context.Context, path string) (uint64, erro
return 0, fmt.Errorf("Expected to write %d, wrote %d bytes", d.FileSize, n)
}
sync()
timeTakenInSeconds := time.Since(startTime).Seconds()

return d.FileSize / uint64(timeTakenInSeconds), nil
throughputInSeconds := d.FileSize * uint64(time.Second) / uint64(time.Since(startTime))
return throughputInSeconds, nil
}

0 comments on commit 0780163

Please sign in to comment.