-
Notifications
You must be signed in to change notification settings - Fork 5
/
heapspace_calculator
executable file
·85 lines (65 loc) · 2.46 KB
/
heapspace_calculator
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
import sys
import yaml
UNIT = 1024.0
# Ensure command line arguments are given
if len(sys.argv) > 3:
cfstats = sys.argv[1]
cassandrayaml = sys.argv[2]
heapsize = float(sys.argv[3]) * UNIT
else:
sys.stderr.write('Usage: %s <cfstats-output> <cassandra.yaml> <heapsize-in-GB> [<avg-key-size-in-Bytes>]\n' % __file__)
sys.exit(1)
if len(sys.argv) > 4:
# Bytes -> KiloBytes -> MegaBytes
avg_key_size = int(sys.argv[4]) / UNIT / UNIT
else:
avg_key_size = None
# Read cassandra.yaml
with open(cassandrayaml) as f:
cassandrayaml = yaml.load(f)
if 'key_cache_size_in_mb' in cassandrayaml and isinstance(cassandrayaml['key_cache_size_in_mb'], int):
key_cache_size = cassandrayaml['key_cache_size_in_mb']
else:
key_cache_size = min(0.05 * heapsize * UNIT, 100)
if 'memtable_total_space_in_mb' in cassandrayaml:
memtable_total_space_in_mb = cassandrayaml['memtable_total_space_in_mb']
else:
# Default memtable size is 1/3 of heapspace
memtable_total_space_in_mb = heapsize / 3.0
if 'index_interval' in cassandrayaml:
index_interval = cassandrayaml['index_interval']
else:
index_interval = 128
index_size = float(key_cache_size) / index_interval
# Calculate Key Cache
with open(cfstats, 'r') as f:
cfstats = f.read()
bloom_filter_used = 0
for line in cfstats.split('\n'):
needle = 'Bloom Filter Space Used:'
if needle in line:
bloom_filter_used += int(line.split(needle)[1])
# Bytes -> KiloBytes -> MegaBytes
bloom_filter_used = bloom_filter_used / UNIT / UNIT
# Print out the Calculated Heap Sizes
print 'Memtable size: {0:.1f} GB'.format(memtable_total_space_in_mb / UNIT)
print 'Key Cache Used: {0:.1f} GB'.format(key_cache_size / UNIT)
print 'Bloom Filter Size: {0:.1f} MB'.format(bloom_filter_used)
print 'Index Size: {0:.1f} MB'.format(index_size)
print
print '75% of the Heap Size:'
print '{0:.2f} GB'.format(heapsize / UNIT * 0.7)
print
print 'Estimated Java Heap Size:'
print '{0:.2f} GB'.format((memtable_total_space_in_mb + UNIT + key_cache_size + bloom_filter_used + index_size) / UNIT)
print
# Alert cases
if 'row_cache_provider' in cassandrayaml:
if cassandrayaml['row_cache_provider'] != 'SerializingCacheProvider':
print 'ALERT: Not using SerializingCacheProvider!'
print
if 'rpc_timeout_in_ms' in cassandrayaml:
if cassandrayaml['rpc_timeout_in_ms'] > 10000:
print 'ALERT: rpc_timeout_in_ms currently at: %s' % cassandrayaml['rpc_timeout_in_ms']
print