-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
69 lines (55 loc) · 1.72 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"runtime/debug"
"time"
)
var (
baseUrlFlag = flag.String("url", "http://dajoh.io/store/", "Backend store base URL.")
cacheDirFlag = flag.String("dir", "cache", "Disk cache directory.")
coordUrlFlag = flag.String("coord", "", "Peer discovery URL.")
coordClusterFlag = flag.String("cluster", "", "Peer discovery cluster name.")
webAddrFlag = flag.String("webaddr", ":8080", "Frontend listen address.")
poolAddrFlag = flag.String("pooladdr", "127.0.0.1:7070", "Cache pool listen address.")
poolPeersFlag = flag.String("poolpeers", "127.0.0.1:7070", "List of cache pool peers, comma separated.")
chunkSizeFlag = flag.Int64("size-c", 16, "Chunk size in MiB.")
sizeCacheSizeFlag = flag.Int64("size-s", 16, "Size cache size in MiB.")
diskCacheSizeFlag = flag.Int64("size-d", 768, "Disk cache size in MiB.")
chunkCacheSizeFlag = flag.Int64("size-m", 512, "Memory cache size in MiB.")
baseUrl string
cacheDir string
coordUrl string
coordCluster string
webAddr string
poolAddr string
poolPeers string
chunkSize int64
sizeCacheSize int64
diskCacheSize int64
chunkCacheSize int64
)
func main() {
flag.Parse()
baseUrl = *baseUrlFlag
cacheDir = *cacheDirFlag
coordUrl = *coordUrlFlag
coordCluster = *coordClusterFlag
webAddr = *webAddrFlag
poolAddr = *poolAddrFlag
poolPeers = *poolPeersFlag
chunkSize = *chunkSizeFlag * 1024 * 1024
diskCacheSize = *diskCacheSizeFlag * 1024 * 1024
sizeCacheSize = *sizeCacheSizeFlag * 1024 * 1024
chunkCacheSize = *chunkCacheSizeFlag * 1024 * 1024
go freeOSMemory()
discoveryInit()
diskInit()
cacheInit()
frontendRun()
}
func freeOSMemory() {
for {
time.Sleep(15 * time.Second)
debug.FreeOSMemory()
}
}