Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add free_os_memory选项 #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cmd/kingshard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"os/signal"
"path"
"runtime"
"runtime/debug"
"strings"
"syscall"
"time"

"github.com/flike/kingshard/config"
"github.com/flike/kingshard/core/golog"
Expand Down Expand Up @@ -75,6 +77,24 @@ func main() {
return
}

if len(cfg.FreeOsMemory) > 0 {
go func() {
ts, err := time.ParseDuration(cfg.FreeOsMemory)
if err != nil {
fmt.Printf("paser free_os_memory fail:%s\n", err)
return
}

tk := time.NewTicker(ts)
for {
select {
case <-tk.C:
debug.FreeOSMemory()
}
}
}()
}

//when the log file size greater than 1GB, kingshard will generate a new file
if len(cfg.LogPath) != 0 {
sysFilePath := path.Join(cfg.LogPath, sysLogName)
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ var configFileName string

//整个config文件对应的结构
type Config struct {
Addr string `yaml:"addr"`
PrometheusAddr string `yaml:"prometheus_addr"`
UserList []UserConfig `yaml:"user_list"`
FreeOsMemory string `yaml:"free_os_memory"`
Addr string `yaml:"addr"`
PrometheusAddr string `yaml:"prometheus_addr"`
UserList []UserConfig `yaml:"user_list"`

WebAddr string `yaml:"web_addr"`
WebUser string `yaml:"web_user"`
Expand Down