Commit a3a68a84 authored by Kirill Smelkov's avatar Kirill Smelkov

X github.com/jacobsa/fuse vs github.com/hanwen/go-fuse

Out of the box github.com/jacobsa/fuse turned out to be ~ 1.6x slower
than github.com/hanwen/go-fuse.

with github.com/hanwen/go-fuse:

	.../github.com/hanwen/go-fuse/example/benchmark-read-throughput$ md5sum ~/mnt/tmp/file.txt
	f4cbd65f70761c9c5306d9301422af02  /home/kirr/mnt/tmp/file.txt

	.../github.com/hanwen/go-fuse/example/benchmark-read-throughput$ go run readbench.go -bs 128 -limit 30000 ~/mnt/tmp/file.txt
	block size 128 kb: 30000.4 MB in 9.704823906s: 3091.29 MBs/s

with github.com/jacobsa/fuse

	.../github.com/hanwen/go-fuse/example/benchmark-read-throughput$ md5sum ~/mnt/tmp/hello
	f4cbd65f70761c9c5306d9301422af02  /home/kirr/mnt/tmp/hello

	.../github.com/hanwen/go-fuse/example/benchmark-read-throughput$ go run readbench.go -bs 128 -limit 30000 ~/mnt/tmp/hello
	block size 128 kb: 30000.4 MB in 15.701199318s: 1910.71 MBs/s

See also go-fuse@0aff2383

See also https://github.com/hanwen/go-fuse/issues/192#issuecomment-338198877
parent cd395961
...@@ -17,8 +17,10 @@ package hellofs ...@@ -17,8 +17,10 @@ package hellofs
import ( import (
"context" "context"
"io" "io"
"io/ioutil"
"os" "os"
"strings" //"strings"
"bytes"
"github.com/jacobsa/fuse" "github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseops" "github.com/jacobsa/fuse/fuseops"
...@@ -66,7 +68,18 @@ type inodeInfo struct { ...@@ -66,7 +68,18 @@ type inodeInfo struct {
} }
// We have a fixed directory structure. // We have a fixed directory structure.
var gInodeInfo = map[fuseops.InodeID]inodeInfo{ var gInodeInfo map[fuseops.InodeID]inodeInfo
var data []byte
func init() {
var err error
data, err = ioutil.ReadFile("/boot/initrd.img-4.16.0-2-amd64")
if err != nil {
panic(err)
}
gInodeInfo = map[fuseops.InodeID]inodeInfo{
// root // root
rootInode: inodeInfo{ rootInode: inodeInfo{
attributes: fuseops.InodeAttributes{ attributes: fuseops.InodeAttributes{
...@@ -95,7 +108,8 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{ ...@@ -95,7 +108,8 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{
attributes: fuseops.InodeAttributes{ attributes: fuseops.InodeAttributes{
Nlink: 1, Nlink: 1,
Mode: 0444, Mode: 0444,
Size: uint64(len("Hello, world!")), //Size: uint64(len("Hello, world!")),
Size: uint64(len(data)),
}, },
}, },
...@@ -121,9 +135,11 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{ ...@@ -121,9 +135,11 @@ var gInodeInfo = map[fuseops.InodeID]inodeInfo{
attributes: fuseops.InodeAttributes{ attributes: fuseops.InodeAttributes{
Nlink: 1, Nlink: 1,
Mode: 0444, Mode: 0444,
Size: uint64(len("Hello, world!")), //Size: uint64(len("Hello, world!")),
Size: uint64(len(data)),
}, },
}, },
}
} }
func findChildInode( func findChildInode(
...@@ -254,8 +270,28 @@ func (fs *helloFS) OpenFile( ...@@ -254,8 +270,28 @@ func (fs *helloFS) OpenFile(
func (fs *helloFS) ReadFile( func (fs *helloFS) ReadFile(
ctx context.Context, ctx context.Context,
op *fuseops.ReadFileOp) (err error) { op *fuseops.ReadFileOp) (err error) {
ldata := int64(len(data))
if op.Offset >= ldata {
op.BytesRead = 0
return nil
}
end := op.Offset + int64(len(op.Dst))
if end > ldata {
end = ldata
}
op.BytesRead = copy(op.Dst, data[op.Offset:end])
return nil
// Let io.ReaderAt deal with the semantics. // Let io.ReaderAt deal with the semantics.
reader := strings.NewReader("Hello, world!") //reader := strings.NewReader("Hello, world!")
reader := bytes.NewReader(data)
op.BytesRead, err = reader.ReadAt(op.Dst, op.Offset) op.BytesRead, err = reader.ReadAt(op.Dst, op.Offset)
......
package main
import (
"context"
"flag"
"log"
"os"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/samples/hellofs"
"github.com/jacobsa/timeutil"
)
func main() {
flag.Parse()
if len(flag.Args()) != 1 {
log.Fatalf("usage: %s <mntpt>", os.Args[0])
}
mntpt := flag.Args()[0]
server, err := hellofs.NewHelloFS(timeutil.RealClock())
if err != nil {
log.Fatal(err)
}
mfs, err := fuse.Mount(mntpt, server, &fuse.MountConfig{})
if err != nil {
log.Fatal(err)
}
err = mfs.Join(context.Background())
if err != nil {
log.Fatal(err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment