Last active
May 14, 2018 07:07
-
-
Save pomidoroshev/53e7b0728f6552378cd6e5237fcafe8f to your computer and use it in GitHub Desktop.
BoltDB RAM omnomnom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"runtime" | |
"strconv" | |
bolt "github.com/coreos/bbolt" | |
) | |
func main() { | |
db, _ := bolt.Open("test.db", 0600, nil) | |
defer db.Close() | |
db.Update(func(tx *bolt.Tx) error { | |
b, _ := tx.CreateBucketIfNotExists([]byte("test")) | |
for i := 10000000; i < 20000000; i++ { | |
key := strconv.Itoa(i) | |
b.Put([]byte(key), []byte("")) | |
if i%200000 == 0 { | |
alloc, sys := getMemUsage() | |
log.Printf("Key = '%v', Alloc = %4vM, Sys = %4vM", key, alloc, sys) | |
} | |
} | |
return nil | |
}) | |
} | |
func getMemUsage() (uint64, uint64) { | |
var m runtime.MemStats | |
runtime.ReadMemStats(&m) | |
return bToMb(m.Alloc), bToMb(m.Sys) | |
} | |
func bToMb(b uint64) uint64 { | |
return b / 1024 / 1024 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% go run bench.go | |
2018/05/14 10:06:28 Key = '10000000', Alloc = 0M, Sys = 1M | |
2018/05/14 10:06:28 Key = '10200000', Alloc = 27M, Sys = 52M | |
2018/05/14 10:06:28 Key = '10400000', Alloc = 53M, Sys = 69M | |
2018/05/14 10:06:29 Key = '10600000', Alloc = 82M, Sys = 140M | |
2018/05/14 10:06:29 Key = '10800000', Alloc = 165M, Sys = 252M | |
2018/05/14 10:06:29 Key = '11000000', Alloc = 157M, Sys = 252M | |
2018/05/14 10:06:29 Key = '11200000', Alloc = 161M, Sys = 253M | |
2018/05/14 10:06:29 Key = '11400000', Alloc = 266M, Sys = 350M | |
2018/05/14 10:06:30 Key = '11600000', Alloc = 240M, Sys = 472M | |
2018/05/14 10:06:30 Key = '11800000', Alloc = 248M, Sys = 472M | |
2018/05/14 10:06:30 Key = '12000000', Alloc = 406M, Sys = 623M | |
2018/05/14 10:06:30 Key = '12200000', Alloc = 417M, Sys = 624M | |
2018/05/14 10:06:30 Key = '12400000', Alloc = 427M, Sys = 624M | |
2018/05/14 10:06:31 Key = '12600000', Alloc = 377M, Sys = 814M | |
2018/05/14 10:06:31 Key = '12800000', Alloc = 388M, Sys = 814M | |
2018/05/14 10:06:31 Key = '13000000', Alloc = 398M, Sys = 814M | |
2018/05/14 10:06:32 Key = '13200000', Alloc = 469M, Sys = 1052M | |
2018/05/14 10:06:32 Key = '13400000', Alloc = 479M, Sys = 1052M | |
2018/05/14 10:06:32 Key = '13600000', Alloc = 490M, Sys = 1052M | |
2018/05/14 10:06:32 Key = '13800000', Alloc = 788M, Sys = 1052M | |
2018/05/14 10:06:33 Key = '14000000', Alloc = 798M, Sys = 1053M | |
2018/05/14 10:06:33 Key = '14200000', Alloc = 809M, Sys = 1053M | |
2018/05/14 10:06:33 Key = '14400000', Alloc = 820M, Sys = 1053M | |
2018/05/14 10:06:33 Key = '14600000', Alloc = 830M, Sys = 1054M | |
2018/05/14 10:06:34 Key = '14800000', Alloc = 722M, Sys = 1054M | |
2018/05/14 10:06:34 Key = '15000000', Alloc = 733M, Sys = 1054M | |
2018/05/14 10:06:34 Key = '15200000', Alloc = 743M, Sys = 1054M | |
2018/05/14 10:06:34 Key = '15400000', Alloc = 754M, Sys = 1054M | |
2018/05/14 10:06:34 Key = '15600000', Alloc = 765M, Sys = 1054M | |
2018/05/14 10:06:35 Key = '15800000', Alloc = 775M, Sys = 1054M | |
2018/05/14 10:06:35 Key = '16000000', Alloc = 1234M, Sys = 1517M | |
2018/05/14 10:06:35 Key = '16200000', Alloc = 1245M, Sys = 1518M | |
2018/05/14 10:06:35 Key = '16400000', Alloc = 1256M, Sys = 1518M | |
2018/05/14 10:06:35 Key = '16600000', Alloc = 1266M, Sys = 1518M | |
2018/05/14 10:06:36 Key = '16800000', Alloc = 1277M, Sys = 1519M | |
2018/05/14 10:06:36 Key = '17000000', Alloc = 1288M, Sys = 1519M | |
2018/05/14 10:06:36 Key = '17200000', Alloc = 1298M, Sys = 1519M | |
2018/05/14 10:06:37 Key = '17400000', Alloc = 1123M, Sys = 2098M | |
2018/05/14 10:06:37 Key = '17600000', Alloc = 1134M, Sys = 2098M | |
2018/05/14 10:06:37 Key = '17800000', Alloc = 1145M, Sys = 2098M | |
2018/05/14 10:06:38 Key = '18000000', Alloc = 1155M, Sys = 2098M | |
2018/05/14 10:06:38 Key = '18200000', Alloc = 1166M, Sys = 2098M | |
2018/05/14 10:06:38 Key = '18400000', Alloc = 1177M, Sys = 2098M | |
2018/05/14 10:06:38 Key = '18600000', Alloc = 1187M, Sys = 2098M | |
2018/05/14 10:06:38 Key = '18800000', Alloc = 1198M, Sys = 2099M | |
2018/05/14 10:06:38 Key = '19000000', Alloc = 1209M, Sys = 2099M | |
2018/05/14 10:06:39 Key = '19200000', Alloc = 1920M, Sys = 2099M | |
2018/05/14 10:06:40 Key = '19400000', Alloc = 1412M, Sys = 2099M | |
2018/05/14 10:06:40 Key = '19600000', Alloc = 1423M, Sys = 2099M | |
2018/05/14 10:06:40 Key = '19800000', Alloc = 1433M, Sys = 2099M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment