Skip to content

Commit

Permalink
chore: supporting range-read in warp test
Browse files Browse the repository at this point in the history
  • Loading branch information
raj-prince committed Nov 10, 2024
1 parent 3366f03 commit 7de2a52
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
58 changes: 55 additions & 3 deletions benchmark-script/read_operation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"flag"
"fmt"
"io"
"math"
"math/rand"
"os"
"path"
"strconv"
"syscall"
"time"


"golang.org/x/sync/errgroup"
)

Expand All @@ -30,11 +31,13 @@ var (

fNumberOfRead = flag.Int("read-count", 1, "number of read iteration")

fOutputDir = flag.String("output-dir", "", "Directory to dump the output")
fOutputDir = flag.String("output-dir", "", "Directory to dump the output")
fFilePrefix = flag.String("file-prefix", "", "Prefix file")
fReadType = flag.String("read", "read", "Whether to do sequential reads (read) or random reads (randread)")
)

var gResult *Result

func init() {
gResult = &Result{}
}
Expand Down Expand Up @@ -79,6 +82,51 @@ func readAlreadyOpenedFile(index int) (err error) {
return
}

func getRandReadPattern() []int64 {
numOfRanges := int64(math.Ceil(float64((int64(*fFileSizeMB) * 1024 * 1024) / (int64(*fBlockSizeKB) * 1024))))

Check failure on line 86 in benchmark-script/read_operation/main.go

View workflow job for this annotation

GitHub Actions / audit

calling math.Ceil on a converted integer is pointless (SA4015)
pattern := make([]int64, numOfRanges)
indices := make([]int64, numOfRanges)
for i := int64(0); i < numOfRanges; i++ {
indices[int(i)] = i
}
for i := int64(0); i < numOfRanges; i++ {
randNum := rand.Intn(len(indices))
pattern[i] = indices[randNum] * int64(*fBlockSizeKB*1024)
indices = append(indices[:randNum], indices[randNum+1:]...)
}
return pattern
}

func randReadAlreadyOpenedFile(index int) (err error) {
pattern := getRandReadPattern()
b := make([]byte, *fBlockSizeKB*1024)
for i := 0; i < *fNumberOfRead; i++ {
readStart := time.Now()

for j := 0; j < len(pattern); j++ {
offset := pattern[j]
_, _ = fileHandles[index].Seek(offset, 0)

_, err = fileHandles[index].Read(b)
if err != nil && err != io.EOF {
break
} else {
err = nil
}
}

if err != nil {
return fmt.Errorf("while reading and discarding content: %v", err)
}

readLatency := time.Since(readStart)

throughput := float64(*fFileSizeMB) / readLatency.Seconds()
gResult.Append(readLatency.Seconds(), throughput)
}
return
}

func runReadFileOperations() (err error) {
if *fDir == "" {
err = fmt.Errorf("you must set --dir flag")
Expand Down Expand Up @@ -108,7 +156,11 @@ func runReadFileOperations() (err error) {
for i := 0; i < *fNumOfThreads; i++ {
index := i
eG.Go(func() error {
err := readAlreadyOpenedFile(index)
if *fReadType == "randread" {
err = randReadAlreadyOpenedFile(index)
} else {
err = readAlreadyOpenedFile(index)
}
if err != nil {
err = fmt.Errorf("while reading file: %w", err)
return err
Expand Down
5 changes: 5 additions & 0 deletions benchmark-script/read_operation/run_warp_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
set -e
shopt -s expand_aliases

echo "Running sequential read test..."
time go run . --threads 64 --read-count 1 --file-size-mb 64 --dir /home/princer_google_com/warp-test/gcs/64M/ --file-prefix "experiment."


echo "Running random read test..."
time go run . --threads 64 --read-count 1 --file-size-mb 64 --dir /home/princer_google_com/warp-test/gcs/64M/ --file-prefix "experiment." --read "randread" --block-size-kb 8192

0 comments on commit 7de2a52

Please sign in to comment.