mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Added cyclic garbage collection for a defined interval. Defaults to 24h
This commit is contained in:
parent
66b85f199c
commit
e38d8eb9fc
2
README
2
README
@ -51,7 +51,9 @@ Usage:
|
|||||||
-cache=32: cache size in MB # Cache size for LevelDB
|
-cache=32: cache size in MB # Cache size for LevelDB
|
||||||
-driver="leveldb": type of database (leveldb, sqlite)
|
-driver="leveldb": type of database (leveldb, sqlite)
|
||||||
-host="": host to bind
|
-host="": host to bind
|
||||||
|
-gc-duration="24h": Duration between forced GCs.
|
||||||
-port=6379: port to bind
|
-port=6379: port to bind
|
||||||
|
-version=false: Print version and exit.
|
||||||
|
|
||||||
To use mtredisalize with your particular world you have to modify the
|
To use mtredisalize with your particular world you have to modify the
|
||||||
world.mt of the world.
|
world.mt of the world.
|
||||||
|
39
main.go
39
main.go
@ -11,23 +11,32 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Version = "pre0.1"
|
const (
|
||||||
|
Version = "pre0.1"
|
||||||
|
GCDuration = "24h"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var port int
|
var (
|
||||||
var host string
|
port int
|
||||||
var driver string
|
host string
|
||||||
var cacheSize int
|
driver string
|
||||||
var version bool
|
cacheSize int
|
||||||
|
version bool
|
||||||
|
gcDuration string
|
||||||
|
)
|
||||||
|
|
||||||
flag.IntVar(&port, "port", 6379, "port to bind")
|
flag.IntVar(&port, "port", 6379, "port to bind")
|
||||||
flag.StringVar(&driver, "driver", "leveldb", "type of database (leveldb, sqlite)")
|
flag.StringVar(&driver, "driver", "leveldb", "type of database (leveldb, sqlite)")
|
||||||
flag.StringVar(&host, "host", "", "host to bind")
|
flag.StringVar(&host, "host", "", "host to bind")
|
||||||
flag.IntVar(&cacheSize, "cache", 32, "cache size in MB")
|
flag.IntVar(&cacheSize, "cache", 32, "cache size in MB")
|
||||||
flag.BoolVar(&version, "version", false, "Print version and exit.")
|
flag.BoolVar(&version, "version", false, "Print version and exit.")
|
||||||
|
flag.StringVar(&gcDuration, "gc-duration", GCDuration, "Duration between forced GCs.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if version {
|
if version {
|
||||||
@ -41,8 +50,15 @@ func main() {
|
|||||||
log.Fatal("Missing path to world")
|
log.Fatal("Missing path to world")
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var (
|
||||||
var backend Backend
|
err error
|
||||||
|
backend Backend
|
||||||
|
gcDur time.Duration
|
||||||
|
)
|
||||||
|
|
||||||
|
if gcDur, err = time.ParseDuration(gcDuration); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if driver == "sqlite" {
|
if driver == "sqlite" {
|
||||||
if backend, err = NewSqliteBackend(args[0]); err != nil {
|
if backend, err = NewSqliteBackend(args[0]); err != nil {
|
||||||
@ -80,6 +96,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
log.Printf("Doing garbage collection every: %s", gcDur)
|
||||||
|
gcChan := time.Tick(gcDur)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case conn := <-connChan:
|
case conn := <-connChan:
|
||||||
@ -93,6 +112,10 @@ func main() {
|
|||||||
case <-sigChan:
|
case <-sigChan:
|
||||||
log.Println("Shutting down")
|
log.Println("Shutting down")
|
||||||
return
|
return
|
||||||
|
case <-gcChan:
|
||||||
|
log.Println("Starting garbage collection.")
|
||||||
|
runtime.GC()
|
||||||
|
log.Println("Garbage collection done.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user