Commit 59a13571 authored by Kirill Smelkov's avatar Kirill Smelkov

X handle FUSE request inline, instead of spawning handleOp

XXX however it does not speedup jacobsa/fuse.
parent 2f654264
...@@ -89,46 +89,50 @@ func NewFileSystemServer(fs FileSystem) fuse.Server { ...@@ -89,46 +89,50 @@ func NewFileSystemServer(fs FileSystem) fuse.Server {
} }
type fileSystemServer struct { type fileSystemServer struct {
fs FileSystem fs FileSystem
opsInFlight sync.WaitGroup serveInFlight sync.WaitGroup
} }
func (s *fileSystemServer) ServeOps(c *fuse.Connection) { func (s *fileSystemServer) ServeOps(c *fuse.Connection) {
// When we are done, we clean up by waiting for all in-flight ops then // When we are done, we clean up by waiting for all in-flight ops then
// destroying the file system. // destroying the file system.
defer func() { defer func() {
s.opsInFlight.Wait() s.serveInFlight.Wait()
s.fs.Destroy() s.fs.Destroy()
}() }()
for { s.serveInFlight.Add(1)
ctx, op, err := c.ReadOp() s.serveOps(c)
if err == io.EOF { }
break
} func (s *fileSystemServer) serveOps(c *fuse.Connection) {
defer s.serveInFlight.Done()
if err != nil {
panic(err) ctx, op, err := c.ReadOp()
} if err == io.EOF {
return
s.opsInFlight.Add(1)
if _, ok := op.(*fuseops.ForgetInodeOp); ok {
// Special case: call in this goroutine for
// forget inode ops, which may come in a
// flurry from the kernel and are generally
// cheap for the file system to handle
s.handleOp(c, ctx, op)
} else {
go s.handleOp(c, ctx, op)
}
} }
if err != nil {
panic(err)
}
// spawn .serveOps, not .handleOp to improve latency, because we
// already received FUSE request and want to handle it as fast as
// possible, i.e. now, without first putting handleOp into go scheduler
// queue. see e.g. https://github.com/golang/go/issues/15110 for details.
//
// improving FUSE request-response latency also improves IO throughput.
s.serveInFlight.Add(1)
go s.serveOps(c)
s.handleOp(c, ctx, op)
} }
func (s *fileSystemServer) handleOp( func (s *fileSystemServer) handleOp(
c *fuse.Connection, c *fuse.Connection,
ctx context.Context, ctx context.Context,
op interface{}) { op interface{}) {
defer s.opsInFlight.Done()
// Dispatch to the appropriate method. // Dispatch to the appropriate method.
var err error var err error
......
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