Skip to content
Snippets Groups Projects
Commit 4c673df4 authored by Ubuntu's avatar Ubuntu
Browse files

allow setting threshold ram usage via flag. Fix a bug with nil interface conversion.

parent e362e550
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package posting package posting
import ( import (
"flag"
"math/rand" "math/rand"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
...@@ -31,6 +32,9 @@ import ( ...@@ -31,6 +32,9 @@ import (
"github.com/zond/gotomic" "github.com/zond/gotomic"
) )
var maxmemory = flag.Uint64("threshold_ram_mb", 3072,
"If RAM usage exceeds this, we stop the world, and flush our buffers.")
type counters struct { type counters struct {
ticker *time.Ticker ticker *time.Ticker
added uint64 added uint64
...@@ -58,7 +62,7 @@ var MIB uint64 ...@@ -58,7 +62,7 @@ var MIB uint64
func checkMemoryUsage() { func checkMemoryUsage() {
MIB = 1 << 20 MIB = 1 << 20
MAX_MEMORY = 3 * (1 << 30) MAX_MEMORY = *maxmemory * (1 << 20)
for _ = range time.Tick(5 * time.Second) { for _ = range time.Tick(5 * time.Second) {
var ms runtime.MemStats var ms runtime.MemStats
...@@ -126,6 +130,9 @@ func GetOrCreate(key []byte) *List { ...@@ -126,6 +130,9 @@ func GetOrCreate(key []byte) *List {
func processOne(k gotomic.Hashable, c *counters) { func processOne(k gotomic.Hashable, c *counters) {
ret, _ := lhmap.Delete(k) ret, _ := lhmap.Delete(k)
if ret == nil {
return
}
l := ret.(*List) l := ret.(*List)
if l == nil { if l == nil {
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment