From 2e6a3c7b160e499d91e990d9c65dab9ff1fd6be7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 14 Nov 2018 22:48:54 -0800 Subject: [PATCH] reduce memory usage --- weed/command/mount.go | 6 +++++- weed/command/mount_std.go | 2 ++ weed/filesys/dirty_page.go | 8 ++++++++ weed/filesys/filehandle.go | 9 +++++++++ weed/filesys/wfs.go | 5 ++--- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/weed/command/mount.go b/weed/command/mount.go index 952dcdfcb..3442b8e97 100644 --- a/weed/command/mount.go +++ b/weed/command/mount.go @@ -20,7 +20,9 @@ type MountOptions struct { } var ( - mountOptions MountOptions + mountOptions MountOptions + mountCpuProfile *string + mountMemProfile *string ) func init() { @@ -35,6 +37,8 @@ func init() { mountOptions.ttlSec = cmdMount.Flag.Int("ttl", 0, "file ttl in seconds") mountOptions.chunkSizeLimitMB = cmdMount.Flag.Int("chunkSizeLimitMB", 16, "local write buffer size, also chunk large files") mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center") + mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file") + mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file") } var cmdMount = &Command{ diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go index 0bc0ddd53..6bb4a300e 100644 --- a/weed/command/mount_std.go +++ b/weed/command/mount_std.go @@ -28,6 +28,8 @@ func runMount(cmd *Command, args []string) bool { fuse.Unmount(*mountOptions.dir) + util.SetupProfiling(*mountCpuProfile, *mountMemProfile) + c, err := fuse.Mount( *mountOptions.dir, fuse.VolumeName("SeaweedFS"), diff --git a/weed/filesys/dirty_page.go b/weed/filesys/dirty_page.go index 858858a30..91a952421 100644 --- a/weed/filesys/dirty_page.go +++ b/weed/filesys/dirty_page.go @@ -28,6 +28,14 @@ func newDirtyPages(file *File) *ContinuousDirtyPages { } } +func (pages *ContinuousDirtyPages) InitializeToFile(file *File) *ContinuousDirtyPages { + if len(pages.Data) != int(file.wfs.option.ChunkSizeLimit) { + pages.Data = make([]byte, file.wfs.option.ChunkSizeLimit) + } + pages.f = file + return pages +} + func (pages *ContinuousDirtyPages) AddPage(ctx context.Context, offset int64, data []byte) (chunks []*filer_pb.FileChunk, err error) { pages.lock.Lock() diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index b15aa68d9..78ae5d342 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -37,6 +37,15 @@ func newFileHandle(file *File, uid, gid uint32) *FileHandle { } } +func (fh *FileHandle) InitializeToFile(file *File, uid, gid uint32) *FileHandle { + newHandle := &FileHandle{ + f: file, + dirtyPages: fh.dirtyPages.InitializeToFile(file), + Uid: uid, + Gid: gid, + } + return newHandle +} var _ = fs.Handle(&FileHandle{}) // var _ = fs.HandleReadAller(&FileHandle{}) diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go index 4520f2eb5..eca74d1d6 100644 --- a/weed/filesys/wfs.go +++ b/weed/filesys/wfs.go @@ -72,15 +72,14 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32) (fileHandle *FileHand return wfs.handles[index] } - fileHandle = newFileHandle(file, uid, gid) - if found && wfs.handles[index] != nil { glog.V(4).Infoln(fullpath, "reuse previous fileHandle id", index) - wfs.handles[index] = fileHandle + wfs.handles[index].InitializeToFile(file, uid, gid) fileHandle.handle = uint64(index) return } + fileHandle = newFileHandle(file, uid, gid) for i, h := range wfs.handles { if h == nil { wfs.handles[i] = fileHandle