optimization code for init

This commit is contained in:
s_jqzhang 2019-01-22 09:32:37 +08:00
parent ea75a6a748
commit c51cfc73e7

View File

@ -4,6 +4,8 @@ import (
"crypto/md5"
"crypto/rand"
"encoding/base64"
"github.com/syndtr/goleveldb/leveldb/filter"
"github.com/syndtr/goleveldb/leveldb/opt"
"runtime"
"errors"
@ -18,24 +20,24 @@ import (
_ "net/http/pprof"
"net/smtp"
"net/url"
"os"
"os/signal"
"path"
"path/filepath"
"reflect"
"regexp"
"runtime/debug"
"strconv"
"syscall"
"sync"
"os"
"regexp"
"strings"
"sync"
"sync/atomic"
"syscall"
"time"
"unsafe"
"github.com/json-iterator/go"
"github.com/deckarep/golang-set"
"github.com/astaxie/beego/httplib"
"github.com/deckarep/golang-set"
"github.com/json-iterator/go"
log "github.com/sjqzhang/seelog"
"github.com/syndtr/goleveldb/leveldb"
)
@ -235,7 +237,9 @@ type GloablConfig struct {
func NewServer() *Server {
var (
ldb *leveldb.DB
server *Server
err error
)
server = &Server{
@ -269,6 +273,18 @@ func NewServer() *Server {
server.curDate = server.util.GetToDay()
o := &opt.Options{
Filter: filter.NewBloomFilter(128),
}
ldb, err = leveldb.OpenFile(CONST_LEVELDB_FILE_NAME, o)
if err != nil {
log.Error(err)
panic(err)
}
server.ldb = ldb
return server
}
@ -2723,7 +2739,6 @@ func init() {
func (this *Server) initComponent(is_reload bool) {
var (
err error
ldb *leveldb.DB
ip string
stat map[string]interface{}
data []byte
@ -2751,14 +2766,7 @@ func (this *Server) initComponent(is_reload bool) {
}
}
Config().Peers = peers
if !is_reload {
ldb, err = leveldb.OpenFile(CONST_LEVELDB_FILE_NAME, nil)
if err != nil {
log.Error(err)
panic(err)
}
server.ldb = ldb
}
FormatStatInfo := func() {
@ -2882,5 +2890,9 @@ func (this *Server) Main() {
}
func main() {
//server.ldb.Has()
server.Main()
}