forked from tent/setdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
50 lines (42 loc) · 902 Bytes
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"github.com/jmhodges/levigo"
)
var DB *levigo.DB
var DefaultReadOptions = levigo.NewReadOptions()
var DefaultWriteOptions = levigo.NewWriteOptions()
var ReadWithoutCacheFill = levigo.NewReadOptions()
func openDB() {
opts := levigo.NewOptions()
cache := levigo.NewLRUCache(128 * 1024 * 1024) // 128MB cache
opts.SetCache(cache)
filter := levigo.NewBloomFilter(10)
opts.SetFilterPolicy(filter)
opts.SetCreateIfMissing(true)
var err error
DB, err = levigo.Open("db", opts)
maybeFatal(err)
}
func maybeFatal(err error) {
if err != nil {
fmt.Printf("Fatal error: %s\n", err)
os.Exit(1)
}
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
openDB()
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
listen()
}
func init() {
ReadWithoutCacheFill.SetFillCache(false)
}