Exemplo n.º 1
0
// 初始化leveldb
func (server *GoRedisServer) initLevelDB() (err error) {
	opts := levelredis.NewOptions()
	cache := levelredis.NewLRUCache(128 * 1024 * 1024)
	opts.SetCache(cache)
	opts.SetCompression(levelredis.SnappyCompression)
	opts.SetBlockSize(8 * 1024)
	opts.SetMaxBackgroundCompactions(6)
	opts.SetWriteBufferSize(32 * 1024 * 1024)
	opts.SetMaxOpenFiles(100000)
	opts.SetCreateIfMissing(true)
	env := levelredis.NewDefaultEnv()
	env.SetBackgroundThreads(6)
	env.SetHighPriorityBackgroundThreads(2)
	opts.SetEnv(env)
	db, e1 := levelredis.Open(server.directory+"/db0", opts)
	if e1 != nil {
		return e1
	}
	server.levelRedis = levelredis.NewLevelRedis(db, false)
	server.DeferClosing(func() {
		opts.Close()
		cache.Close()
		env.Close()
		stdlog.Println("db closed")
	})
	return
}
Exemplo n.º 2
0
// 初始化主从日志
func (server *GoRedisServer) initSyncLog() error {
	opts := levelredis.NewOptions()
	cache := levelredis.NewLRUCache(32 * 1024 * 1024)
	opts.SetCache(cache)
	opts.SetCompression(levelredis.SnappyCompression)
	opts.SetBlockSize(4 * 1024)
	opts.SetMaxBackgroundCompactions(2)
	opts.SetWriteBufferSize(32 * 1024 * 1024)
	opts.SetMaxOpenFiles(100000)
	opts.SetCreateIfMissing(true)
	env := levelredis.NewDefaultEnv()
	env.SetBackgroundThreads(2)
	env.SetHighPriorityBackgroundThreads(1)
	opts.SetEnv(env)
	db, e1 := levelredis.Open(server.directory+"/synclog", opts)
	if e1 != nil {
		return e1
	}
	ldb := levelredis.NewLevelRedis(db, false)
	server.synclog = NewSyncLog(ldb, "sync")
	server.DeferClosing(func() {
		opts.Close()
		cache.Close()
		env.Close()
		stdlog.Println("synclog closed")
	})
	return nil
}