Skip to content

Commit 31b8560

Browse files
authored
Make IOPerDrive Configurable (#7)
Signed-off-by: Zhou Ting <[email protected]>
1 parent c746362 commit 31b8560

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Examples:
5050
Flags:
5151
-b, --blocksize string read/write block size (default "4MiB")
5252
-f, --filesize string amount of data to read/write per drive (default "1GiB")
53+
-i, --ioperdrive int number of concurrent I/O per drive (default 4)
5354
-h, --help help for dperf
5455
--serial run tests one by one, instead of all at once.
5556
--version version for dperf

cmd/cmd.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ const alignSize = 4096
4242

4343
// flags
4444
var (
45-
serial = false
46-
verbose = false
47-
blockSize = "4MiB"
48-
fileSize = "1GiB"
49-
cpuNode = 0
45+
serial = false
46+
verbose = false
47+
blockSize = "4MiB"
48+
fileSize = "1GiB"
49+
cpuNode = 0
50+
ioPerDrive = 4
5051
)
5152

5253
var dperfCmd = &cobra.Command{
@@ -123,11 +124,16 @@ $ dperf --serial /mnt/drive{1..6}
123124
return fmt.Errorf("Invalid filesize must multiples of 4k: %d", fs)
124125
}
125126

127+
if ioPerDrive <= 0 {
128+
return fmt.Errorf("Invalid ioperdrive must greater than 0: %d", ioPerDrive)
129+
}
130+
126131
perf := &dperf.DrivePerf{
127-
Serial: serial,
128-
BlockSize: bs,
129-
FileSize: fs,
130-
Verbose: verbose,
132+
Serial: serial,
133+
BlockSize: bs,
134+
FileSize: fs,
135+
Verbose: verbose,
136+
IOPerDrive: ioPerDrive,
131137
}
132138
paths := make([]string, 0, len(args))
133139
for _, arg := range args {
@@ -175,6 +181,8 @@ func init() {
175181
"filesize", "f", fileSize, "amount of data to read/write per drive")
176182
dperfCmd.PersistentFlags().IntVarP(&cpuNode,
177183
"cpunode", "c", -1, "execute on a specific CPU node, defaults to all CPU nodes")
184+
dperfCmd.PersistentFlags().IntVarP(&ioPerDrive,
185+
"ioperdrive", "i", ioPerDrive, "number of concurrent I/O per drive, default is 4")
178186

179187
dperfCmd.PersistentFlags().MarkHidden("alsologtostderr")
180188
dperfCmd.PersistentFlags().MarkHidden("add_dir_header")

pkg/dperf/perf.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ import (
3030

3131
// DrivePerf options
3232
type DrivePerf struct {
33-
Serial bool
34-
Verbose bool
35-
BlockSize uint64
36-
FileSize uint64
33+
Serial bool
34+
Verbose bool
35+
BlockSize uint64
36+
FileSize uint64
37+
IOPerDrive int
3738
}
3839

3940
// mustGetUUID - get a random UUID.
@@ -46,15 +47,13 @@ func mustGetUUID() string {
4647
return u.String()
4748
}
4849

49-
const ioPerDrive = 4 // number of concurrent I/O per drive
50-
5150
func (d *DrivePerf) runTests(ctx context.Context, path string, testUUID string) (dr *DrivePerfResult) {
52-
writeThroughputs := make([]uint64, ioPerDrive)
53-
readThroughputs := make([]uint64, ioPerDrive)
54-
errs := make([]error, ioPerDrive)
51+
writeThroughputs := make([]uint64, d.IOPerDrive)
52+
readThroughputs := make([]uint64, d.IOPerDrive)
53+
errs := make([]error, d.IOPerDrive)
5554

56-
dataBuffers := make([][]byte, ioPerDrive)
57-
for i := 0; i < ioPerDrive; i++ {
55+
dataBuffers := make([][]byte, d.IOPerDrive)
56+
for i := 0; i < d.IOPerDrive; i++ {
5857
// Read Aligned block upto a multiple of BlockSize
5958
dataBuffers[i] = directio.AlignedBlock(int(d.BlockSize))
6059
}
@@ -64,8 +63,8 @@ func (d *DrivePerf) runTests(ctx context.Context, path string, testUUID string)
6463
defer os.RemoveAll(testUUIDPath)
6564

6665
var wg sync.WaitGroup
67-
wg.Add(ioPerDrive)
68-
for i := 0; i < ioPerDrive; i++ {
66+
wg.Add(int(d.IOPerDrive))
67+
for i := 0; i < int(d.IOPerDrive); i++ {
6968
go func(idx int) {
7069
defer wg.Done()
7170
iopath := testPath + "-" + strconv.Itoa(idx)
@@ -79,8 +78,8 @@ func (d *DrivePerf) runTests(ctx context.Context, path string, testUUID string)
7978
}
8079
wg.Wait()
8180

82-
wg.Add(ioPerDrive)
83-
for i := 0; i < ioPerDrive; i++ {
81+
wg.Add(d.IOPerDrive)
82+
for i := 0; i < d.IOPerDrive; i++ {
8483
go func(idx int) {
8584
defer wg.Done()
8685
iopath := testPath + "-" + strconv.Itoa(idx)

0 commit comments

Comments
 (0)