Merge lp:~clint-fewbar/charms/precise/mysql/dynamic-memory into lp:charms/mysql

Proposed by Clint Byrum
Status: Merged
Approved by: Marco Ceppi
Approved revision: 78
Merged at revision: 78
Proposed branch: lp:~clint-fewbar/charms/precise/mysql/dynamic-memory
Merge into: lp:charms/mysql
Diff against target: 78 lines (+30/-6)
3 files modified
config.yaml (+2/-2)
hooks/config-changed (+27/-3)
revision (+1/-1)
To merge this branch: bzr merge lp:~clint-fewbar/charms/precise/mysql/dynamic-memory
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+120663@code.launchpad.net

Description of the change

Makes RAM dynamic based on available system memory. This should fix mysql not starting up on HP Cloud which only has 800MB of RAM for the default instance type.

To post a comment you must log in.
78. By Clint Byrum

bumping rev for new memory changes

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2012-04-25 07:20:11 +0000
3+++ config.yaml 2012-08-21 21:15:23 +0000
4@@ -1,7 +1,7 @@
5 options:
6 dataset-size:
7- default: 1G
8- description: How much data do you want to keep in memory in the DB. This will be used to tune settings in the database server appropriately. Any more specific settings will override these defaults though. This currently sets innodb_buffer_pool_size or key_cache_size depending on the setting in preferred-storage-engine. If query-cache-type is set to 'ON' or 'DEMAND' 10% of this is given to query-cache-size.
9+ default: '80%'
10+ description: How much data do you want to keep in memory in the DB. This will be used to tune settings in the database server appropriately. Any more specific settings will override these defaults though. This currently sets innodb_buffer_pool_size or key_cache_size depending on the setting in preferred-storage-engine. If query-cache-type is set to 'ON' or 'DEMAND' 20% of this is given to query-cache-size. Suffix this value with 'K','M','G', or 'T' to get the relevant kilo/mega/etc. bytes. If suffixed with %, one will get that percentage of RAM devoted to dataset and (if enabled) query cache.
11 type: string
12 preferred-storage-engine:
13 default: InnoDB
14
15=== modified file 'hooks/config-changed'
16--- hooks/config-changed 2012-08-01 23:39:18 +0000
17+++ hooks/config-changed 2012-08-21 21:15:23 +0000
18@@ -6,11 +6,26 @@
19 import re
20 import hashlib
21 import os
22+from string import upper
23
24 num_re = re.compile('^[0-9]+$')
25
26+# Going for the biggest page size to avoid wasted bytes. InnoDB page size is
27+# 16MB
28+PAGE_SIZE = 16*1024*1024
29+
30 configs=json.loads(check_output(['config-get','--format=json']))
31
32+def get_memtotal():
33+ with open('/proc/meminfo') as meminfo_file:
34+ meminfo = {}
35+ for line in meminfo_file:
36+ (key, mem) = line.split(':', 2)
37+ if key == 'MemTotal':
38+ (mtot, modifier) = mem.strip().split(' ')
39+ return '%s%s' % (mtot, upper(modifier[0]))
40+
41+
42 # There should be a library for this
43 def human_to_bytes(human):
44 if num_re.match(human):
45@@ -19,14 +34,23 @@
46 modifier=human[-1]
47 if modifier in factors:
48 return int(human[:-1]) * factors[modifier]
49- raise Exception("Can only convert K,M,G, or T")
50+ if modifier == '%':
51+ total_ram = human_to_bytes(get_memtotal())
52+ factor = int(human[:-1]) * 0.01
53+ pctram = total_ram * factor
54+ return int(pctram - (pctram % PAGE_SIZE))
55+ raise ValueError("Can only convert K,M,G, or T")
56
57 # smart-calc stuff in the configs
58 dataset_bytes = human_to_bytes(configs['dataset-size'])
59
60+check_call(['juju-log','-l','INFO','dataset size in bytes: %d' % dataset_bytes])
61+
62 if configs['query-cache-size'] == -1 and configs['query-cache-type'] in ['ON','DEMAND']:
63- configs['query-cache-size'] = int(dataset_bytes * 0.20)
64- dataset_bytes -= configs['query-cache-size']
65+ qcache_bytes = (dataset_bytes * 0.20)
66+ qcache_bytes = int(qcache_bytes - (qcache_bytes % PAGE_SIZE))
67+ configs['query-cache-size'] = qcache_bytes
68+ dataset_bytes -= qcache_bytes
69
70 # 5.5 allows the words, but not 5.1
71 if configs['query-cache-type'] == 'ON':
72
73=== modified file 'revision'
74--- revision 2012-08-21 00:07:19 +0000
75+++ revision 2012-08-21 21:15:23 +0000
76@@ -1,1 +1,1 @@
77-146
78+147

Subscribers

People subscribed via source and target branches

to all changes: