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 readzerocopy-examples
parent
694c1bf9db
commit
ac82ada21e
|
@ -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() {
|
||||
|
@ -27,7 +28,8 @@ func main() {
|
|||
}
|
||||
|
||||
cfg := &fuse.MountConfig{
|
||||
ReadOnly: *fReadOnly,
|
||||
ReadOnly: *fReadOnly,
|
||||
UseVectoredRead: *fVectored,
|
||||
}
|
||||
|
||||
if *fDebug {
|
||||
|
|
|
@ -35,8 +35,6 @@ const fileSize = 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)
|
||||
|
@ -137,7 +135,28 @@ func (fs *readBenchFS) ReadFile(ctx context.Context, op *fuseops.ReadFileOp) err
|
|||
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 > fileSize {
|
||||
return io.EOF
|
||||
}
|
||||
end := op.Offset + op.Size
|
||||
if end > fileSize {
|
||||
end = fileSize
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue