Last active
August 12, 2021 15:56
-
-
Save pfreixes/ace228abf03d809772a542469f88da37 to your computer and use it in GitHub Desktop.
Test for checking maximum throughput of random reads over a 40GB file stored in a SSD disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"os" | |
"sync" | |
"time" | |
) | |
const ( | |
FILE_SIZE int64 = 42949672960 | |
BUCKET_SIZE int64 = 512 | |
BUCKETS int64 = FILE_SIZE / BUCKET_SIZE | |
Megabyte = 1 << 20 | |
GOROUTINES int64 = 64 | |
READ_BUCKETS int64 = 100_000 | |
) | |
func main() { | |
fd, err := syscall.Open("file.bin", syscall.O_RDONLY, 0) | |
if err != nil { | |
panic(err) | |
} | |
_, _, e := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), syscall.F_NOCACHE, 1) | |
if e != 0 { | |
panic("Failed trying to disable the cache") | |
} | |
r := rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) | |
var wg sync.WaitGroup | |
start := time.Now() | |
// start N goroutines | |
for i := int64(0); i < GOROUTINES; i++ { | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
var offset int64 | |
b := make([]byte, BUCKET_SIZE) | |
// read random buckets | |
for j := int64(0); j < READ_BUCKETS; j++ { | |
offset = r.Int63n(BUCKETS) * BUCKET_SIZE | |
if _, err := syscall.Pread(fd, b, offset); err != nil { | |
panic(fmt.Sprintf("%v %v", offset, err)) | |
} | |
} | |
}() | |
} | |
wg.Wait() | |
elapsed := float64(time.Since(start)/ time.Second) | |
fmt.Printf("Total time in seconds %f\n", elapsed) | |
fmt.Printf("Block throughput %f blocks/second\n", float64(READ_BUCKETS * GOROUTINES) / elapsed) | |
fmt.Printf("Read throughput %f MB/second\n", float64((READ_BUCKETS * BUCKET_SIZE * GOROUTINES) / Megabyte) / elapsed) | |
} |
Author
pfreixes
commented
Aug 1, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment