Skip to content

Commit

Permalink
avoid skewing values for larger object sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed May 22, 2023
1 parent 0780163 commit eea0402
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions pkg/dperf/run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,15 @@ func (d *DrivePerf) runReadTest(ctx context.Context, path string) (uint64, error
ctx: ctx,
}
n, err := io.Copy(ioutil.Discard, of)
of.Close()
if err != nil {
of.Close()
return 0, err
}
if n != int64(d.FileSize) {
of.Close()
return 0, fmt.Errorf("Expected read %d, read %d", d.FileSize, n)
}
of.Close()

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

Expand Down Expand Up @@ -173,6 +171,11 @@ type odirectWriter struct {
File *os.File
}

func (o *odirectWriter) Close() error {
fdatasync(o.File)
return o.File.Close()
}

func (o *odirectWriter) Write(buf []byte) (n int, err error) {
return o.File.Write(buf)
}
Expand All @@ -188,11 +191,6 @@ func (d *DrivePerf) runWriteTest(ctx context.Context, path string) (uint64, erro
return 0, err
}

sync := func() {
fdatasync(f)
f.Close()
}

// Write Aligned block upto a multiple of BlockSize
data := alignedBlock(int(d.BlockSize))

Expand All @@ -203,16 +201,15 @@ func (d *DrivePerf) runWriteTest(ctx context.Context, path string) (uint64, erro
}

n, err := io.CopyBuffer(of, io.LimitReader(&nullReader{ctx: ctx}, int64(d.FileSize)), data)
of.Close()
if err != nil {
sync()
return 0, err
}

if n != int64(d.FileSize) {
sync()
return 0, fmt.Errorf("Expected to write %d, wrote %d bytes", d.FileSize, n)
}
sync()

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

0 comments on commit eea0402

Please sign in to comment.