diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-12-30 00:51:44 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-12-30 00:51:44 -0800 |
| commit | 0388d421d2a50ce4c3368457ab850a982744ea7b (patch) | |
| tree | ecfdaf67d9a40e74167c963bc6f44d772c39a827 /weed/filesys/filehandle.go | |
| parent | 55f7d8f80105f907e704600ec163c02c995ff9c3 (diff) | |
| download | seaweedfs-0388d421d2a50ce4c3368457ab850a982744ea7b.tar.xz seaweedfs-0388d421d2a50ce4c3368457ab850a982744ea7b.zip | |
caching visible intervals for read
speeds up 4x in single thread mode
speeds up 30% in 32 threads mode
Diffstat (limited to 'weed/filesys/filehandle.go')
| -rw-r--r-- | weed/filesys/filehandle.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index a11fb06c6..8e1d6fadd 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -1,14 +1,14 @@ package filesys import ( - "github.com/seaweedfs/fuse" - "github.com/seaweedfs/fuse/fs" "context" "fmt" "github.com/chrislusf/seaweedfs/weed/filer2" "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/util" + "github.com/seaweedfs/fuse" + "github.com/seaweedfs/fuse/fs" "net/http" "strings" "sync" @@ -58,7 +58,11 @@ func (fh *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fus buff := make([]byte, req.Size) - chunkViews := filer2.ViewFromChunks(fh.f.entry.Chunks, req.Offset, req.Size) + if fh.f.entryViewCache == nil { + fh.f.entryViewCache = filer2.NonOverlappingVisibleIntervals(fh.f.entry.Chunks) + } + + chunkViews := filer2.ViewFromVisibleIntervals(fh.f.entryViewCache, req.Offset, req.Size) var vids []string for _, chunkView := range chunkViews { @@ -154,6 +158,7 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *f for _, chunk := range chunks { fh.f.entry.Chunks = append(fh.f.entry.Chunks, chunk) + fh.f.entryViewCache = nil glog.V(1).Infof("uploaded %s/%s to %s [%d,%d)", fh.f.dir.Path, fh.f.Name, chunk.FileId, chunk.Offset, chunk.Offset+int64(chunk.Size)) fh.dirtyMetadata = true } @@ -188,6 +193,7 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error { } if chunk != nil { fh.f.entry.Chunks = append(fh.f.entry.Chunks, chunk) + fh.f.entryViewCache = nil } if !fh.dirtyMetadata { |
