Add vectored read to readbenchfs

You can now run `./readbenchfs --mount_point dir --vectored` and then
`dd if=dir/test of=/dev/null iflag=direct bs=1M status=progress` to test
vectored read speed.

My results with GOMAXPROCS=1:
- Before vectored read patch: 390 MB/s read
- Non-vectored read after vectored read patch: 830 MB/s read
- Vectored read: 1200 MB/s read
geesefs-0-30-9
Vitaliy Filippov 2021-08-31 12:43:16 +03:00
parent fcabfc89e9
commit 513d4815ce
2 changed files with 27 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import (
var fMountPoint = flag.String("mount_point", "", "Path to mount point.")
var fReadOnly = flag.Bool("read_only", false, "Mount in read-only mode.")
var fVectored = flag.Bool("vectored", false, "Use vectored read.")
var fDebug = flag.Bool("debug", false, "Enable debug logging.")
func main() {
@ -28,6 +29,7 @@ func main() {
cfg := &fuse.MountConfig{
ReadOnly: *fReadOnly,
UseVectoredRead: *fVectored,
}
if *fDebug {

View File

@ -34,14 +34,12 @@ const FILE_SIZE = 1024*1024*1024*1024
var _ fuseutil.FileSystem = &readBenchFS{}
// Create a file system that mirrors an existing physical path, in a readonly mode
func NewReadBenchServer() (server fuse.Server, err error) {
// 1 GB of random data to exceed CPU cache
buf := make([]byte, 1024*1024*1024)
rand.Read(buf)
server = fuseutil.NewFileSystemServer(&readBenchFS{
buf: buf,
buf: buf,
})
return
}
@ -150,7 +148,30 @@ func (fs *readBenchFS) ReadFile(
copy(op.Dst[pos-op.Offset : ], fs.buf[s : ])
pos = op.Offset+e
}
//op.Data = [][]byte{ contents[op.Offset : end] }
op.BytesRead = int(end-op.Offset)
return nil
}
func (fs *readBenchFS) VectoredRead(
ctx context.Context,
op *fuseops.VectoredReadOp) error {
if op.Offset > FILE_SIZE {
return io.EOF
}
end := op.Offset+op.Size
if end > FILE_SIZE {
end = FILE_SIZE
}
buflen := int64(len(fs.buf))
for pos := op.Offset; pos < end; {
s := pos % buflen
e := buflen
if e-s > end-pos {
e = s+end-pos
}
op.Data = append(op.Data, fs.buf[s : e])
pos = op.Offset+e
}
op.BytesRead = int(end-op.Offset)
return nil
}