mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add cpu and mem pprof
This commit is contained in:
parent
2c7dad589d
commit
1fbb8723dc
|
@ -4,7 +4,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -48,6 +47,7 @@ var (
|
||||||
masterWhiteListOption = cmdMaster.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
|
masterWhiteListOption = cmdMaster.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
|
||||||
masterSecureKey = cmdMaster.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
|
masterSecureKey = cmdMaster.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
|
||||||
masterCpuProfile = cmdMaster.Flag.String("cpuprofile", "", "cpu profile output file")
|
masterCpuProfile = cmdMaster.Flag.String("cpuprofile", "", "cpu profile output file")
|
||||||
|
masterMemProfile = cmdMaster.Flag.String("memprofile", "", "memory profile output file")
|
||||||
|
|
||||||
masterWhiteList []string
|
masterWhiteList []string
|
||||||
)
|
)
|
||||||
|
@ -57,17 +57,8 @@ func runMaster(cmd *Command, args []string) bool {
|
||||||
*mMaxCpu = runtime.NumCPU()
|
*mMaxCpu = runtime.NumCPU()
|
||||||
}
|
}
|
||||||
runtime.GOMAXPROCS(*mMaxCpu)
|
runtime.GOMAXPROCS(*mMaxCpu)
|
||||||
if *masterCpuProfile != "" {
|
util.SetupProfiling(*masterCpuProfile, *masterMemProfile)
|
||||||
f, err := os.Create(*masterCpuProfile)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
pprof.StartCPUProfile(f)
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
OnInterrupt(func() {
|
|
||||||
pprof.StopCPUProfile()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if err := util.TestFolderWritable(*metaFolder); err != nil {
|
if err := util.TestFolderWritable(*metaFolder); err != nil {
|
||||||
glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *metaFolder, err)
|
glog.Fatalf("Check Meta Folder (-mdir) Writable %s : %s", *metaFolder, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func runMount(cmd *Command, args []string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
OnInterrupt(func() {
|
util.OnInterrupt(func() {
|
||||||
fuse.Unmount(*mountOptions.dir)
|
fuse.Unmount(*mountOptions.dir)
|
||||||
c.Close()
|
c.Close()
|
||||||
})
|
})
|
||||||
|
|
|
@ -290,7 +290,7 @@ func runServer(cmd *Command, args []string) bool {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
OnInterrupt(func() {
|
util.OnInterrupt(func() {
|
||||||
volumeServer.Shutdown()
|
volumeServer.Shutdown()
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,6 +36,8 @@ type VolumeServerOptions struct {
|
||||||
indexType *string
|
indexType *string
|
||||||
fixJpgOrientation *bool
|
fixJpgOrientation *bool
|
||||||
readRedirect *bool
|
readRedirect *bool
|
||||||
|
cpuProfile *string
|
||||||
|
memProfile *string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -54,6 +56,8 @@ func init() {
|
||||||
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb|btree] mode for memory~performance balance.")
|
v.indexType = cmdVolume.Flag.String("index", "memory", "Choose [memory|leveldb|boltdb|btree] mode for memory~performance balance.")
|
||||||
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
v.fixJpgOrientation = cmdVolume.Flag.Bool("images.fix.orientation", true, "Adjust jpg orientation when uploading.")
|
||||||
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
|
v.readRedirect = cmdVolume.Flag.Bool("read.redirect", true, "Redirect moved or non-local volumes.")
|
||||||
|
v.cpuProfile = cmdVolume.Flag.String("cpuprofile", "", "cpu profile output file")
|
||||||
|
v.memProfile = cmdVolume.Flag.String("memprofile", "", "memory profile output file")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
|
@ -75,6 +79,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
*v.maxCpu = runtime.NumCPU()
|
*v.maxCpu = runtime.NumCPU()
|
||||||
}
|
}
|
||||||
runtime.GOMAXPROCS(*v.maxCpu)
|
runtime.GOMAXPROCS(*v.maxCpu)
|
||||||
|
util.SetupProfiling(*v.cpuProfile, *v.memProfile)
|
||||||
|
|
||||||
//Set multiple folders and each folder's max volume count limit'
|
//Set multiple folders and each folder's max volume count limit'
|
||||||
v.folders = strings.Split(*volumeFolders, ",")
|
v.folders = strings.Split(*volumeFolders, ",")
|
||||||
|
@ -156,7 +161,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
OnInterrupt(func() {
|
util.OnInterrupt(func() {
|
||||||
volumeServer.Shutdown()
|
volumeServer.Shutdown()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
33
weed/util/pprof.go
Normal file
33
weed/util/pprof.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"runtime/pprof"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetupProfiling(cpuProfile, memProfile string) {
|
||||||
|
if cpuProfile != "" {
|
||||||
|
f, err := os.Create(cpuProfile)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal(err)
|
||||||
|
}
|
||||||
|
pprof.StartCPUProfile(f)
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
|
OnInterrupt(func() {
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if memProfile != "" {
|
||||||
|
f, err := os.Create(memProfile)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal(err)
|
||||||
|
}
|
||||||
|
OnInterrupt(func() {
|
||||||
|
pprof.WriteHeapProfile(f)
|
||||||
|
f.Close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
// +build !plan9
|
// +build !plan9
|
||||||
|
|
||||||
package command
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -1,6 +1,6 @@
|
||||||
// +build plan9
|
// +build plan9
|
||||||
|
|
||||||
package command
|
package util
|
||||||
|
|
||||||
func OnInterrupt(fn func()) {
|
func OnInterrupt(fn func()) {
|
||||||
}
|
}
|
Loading…
Reference in a new issue