Browse Source

Add additional mysql tunables

Adding more mysql tuning options to better support production-like
environments. These additional attribues have been set to default
values that match the mysql defaults. Including spec tests.

Change-Id: Iadb0746354ea93a6beef9ecbae5d1bdc5cec1d48
Closes-Bug: #1436481
Mark Gloshen 4 years ago
parent
commit
acc54b2680

+ 16
- 4
attributes/mysql.rb View File

@@ -29,6 +29,10 @@ default['openstack']['mysql']['version'] = '5.5'
29 29
 default['openstack']['mysql']['service_name'] = 'default'
30 30
 # Storage engine, base OpenStack requires the InnoDB flavor
31 31
 default['openstack']['mysql']['default-storage-engine'] = 'InnoDB'
32
+# InnoDB lock mode for generating auto-increment values
33
+default['openstack']['mysql']['innodb_autoinc_lock_mode'] = '1'
34
+# InnoDB give each table its own file
35
+default['openstack']['mysql']['innodb_file_per_table'] = 'OFF'
32 36
 # InnoDB thread concurrency
33 37
 default['openstack']['mysql']['innodb_thread_concurrency'] = '0'
34 38
 # InnoDB commit concurrency
@@ -36,10 +40,18 @@ default['openstack']['mysql']['innodb_commit_concurrency'] = '0'
36 40
 # InnoDB number of read io threads
37 41
 default['openstack']['mysql']['innodb_read_io_threads'] = '4'
38 42
 # InnoDB number of commit transactions to flush log
39
-default['openstack']['mysql']['innodb_flush_log_at_trx_commit'] = '2'
43
+default['openstack']['mysql']['innodb_flush_log_at_trx_commit'] = '1'
44
+# InnoDB memory buffer for caching table data and indexes
45
+default['openstack']['mysql']['innodb_buffer_pool_size'] = '134217728'
46
+# InnoDB size of each log file in a log group
47
+default['openstack']['mysql']['innodb_log_file_size'] = '5242880'
48
+# InnoDB size of buffer for logs
49
+default['openstack']['mysql']['innodb_log_buffer_size'] = '8388608'
40 50
 # Skip name resolution
41
-default['openstack']['mysql']['skip-name-resolve'] = true
51
+default['openstack']['mysql']['skip-name-resolve'] = false
42 52
 # Character set
43
-default['openstack']['mysql']['character-set-server'] = 'utf8'
53
+default['openstack']['mysql']['character-set-server'] = 'latin1'
54
+# Memory allocated for caching query results
55
+default['openstack']['mysql']['query_cache_size'] = '0'
44 56
 # Maximum number of connections
45
-default['openstack']['mysql']['max_connections'] = '1024'
57
+default['openstack']['mysql']['max_connections'] = '151'

+ 10
- 3
spec/mariadb-server-redhat_spec.rb View File

@@ -19,11 +19,18 @@ describe 'openstack-ops-database::mariadb-server' do
19 19
       )
20 20
       expect(file).to notify('service[mysql]')
21 21
       [/^default-storage-engine = InnoDB$/,
22
+       /^innodb_autoinc_lock_mode = 1$/,
23
+       /^innodb_file_per_table = OFF$/,
22 24
        /^innodb_thread_concurrency = 0$/,
23 25
        /^innodb_commit_concurrency = 0$/,
24
-       /^innodb_flush_log_at_trx_commit = 2$/,
25
-       /^skip-name-resolve$/,
26
-       /^character-set-server = utf8$/].each do |line|
26
+       /^innodb_read_io_threads = 4$/,
27
+       /^innodb_flush_log_at_trx_commit = 1$/,
28
+       /^innodb_buffer_pool_size = 134217728$/,
29
+       /^innodb_log_file_size = 5242880$/,
30
+       /^innodb_log_buffer_size = 8388608$/,
31
+       /^character-set-server = latin1$/,
32
+       /^query_cache_size = 0$/,
33
+       /^max_connections = 151$/].each do |line|
27 34
         expect(chef_run).to render_config_file(file.name)\
28 35
           .with_section_content('mysqld', line)
29 36
       end

+ 10
- 5
spec/mariadb-server_spec.rb View File

@@ -13,7 +13,7 @@ describe 'openstack-ops-database::mariadb-server' do
13 13
     it 'overrides mariadb default attributes' do
14 14
       expect(chef_run.node['mariadb']['mysqld']['bind_address']).to eq '127.0.0.1'
15 15
       expect(chef_run.node['mariadb']['mysqld']['default_storage_engine']).to eq 'InnoDB'
16
-      expect(chef_run.node['mariadb']['mysqld']['max_connections']).to eq '1024'
16
+      expect(chef_run.node['mariadb']['mysqld']['max_connections']).to eq '151'
17 17
       expect(chef_run.node['mariadb']['forbid_remote_root']).to be true
18 18
     end
19 19
 
@@ -31,13 +31,18 @@ describe 'openstack-ops-database::mariadb-server' do
31 31
       )
32 32
       expect(file).to notify('service[mysql]')
33 33
       [/^default-storage-engine = InnoDB$/,
34
+       /^innodb_autoinc_lock_mode = 1$/,
35
+       /^innodb_file_per_table = OFF$/,
34 36
        /^innodb_thread_concurrency = 0$/,
35 37
        /^innodb_commit_concurrency = 0$/,
36 38
        /^innodb_read_io_threads = 4$/,
37
-       /^innodb_flush_log_at_trx_commit = 2$/,
38
-       /^skip-name-resolve$/,
39
-       /^character-set-server = utf8$/,
40
-       /^max_connections = 1024$/].each do |line|
39
+       /^innodb_flush_log_at_trx_commit = 1$/,
40
+       /^innodb_buffer_pool_size = 134217728$/,
41
+       /^innodb_log_file_size = 5242880$/,
42
+       /^innodb_log_buffer_size = 8388608$/,
43
+       /^character-set-server = latin1$/,
44
+       /^query_cache_size = 0$/,
45
+       /^max_connections = 151$/].each do |line|
41 46
         expect(chef_run).to render_config_file(file.name)\
42 47
           .with_section_content('mysqld', line)
43 48
       end

+ 18
- 7
spec/mysql-server_spec.rb View File

@@ -24,13 +24,24 @@ describe 'openstack-ops-database::mysql-server' do
24 24
       )
25 25
     end
26 26
 
27
-    it 'creates mysql openstack config and notifies server to restart' do
28
-      expect(chef_run).to create_mysql_config('openstack').with(
29
-        source: 'openstack.cnf.erb',
30
-        action: [:create]
31
-      )
32
-      resource = chef_run.find_resource('mysql_config', 'openstack')
33
-      expect(resource).to notify('mysql_service[default]').to(:restart).delayed
27
+    describe 'openstack.cnf' do
28
+      let(:file) { '/etc/mysql/conf.d/openstack.cnf' }
29
+
30
+      it 'creates mysql openstack config and notifies server to restart' do
31
+        expect(chef_run).to create_mysql_config('openstack').with(
32
+          source: 'openstack.cnf.erb',
33
+          action: [:create]
34
+        )
35
+        resource = chef_run.find_resource('mysql_config', 'openstack')
36
+        expect(resource).to notify('mysql_service[default]').to(:restart).delayed
37
+      end
38
+
39
+      # TODO: Verify contents of openstack.cnf. This cannot be done properly at
40
+      # present because the mysql_config LWRP comes from the mysql cookbook but
41
+      # does not expose a custom matcher for testing the templates contents.
42
+      # See ChefSpec docs on testing LWRPs from other cookbooks.
43
+      # See issue filed against mysql cookbook:
44
+      # https://github.com/chef-cookbooks/mysql/issues/322
34 45
     end
35 46
   end
36 47
 end

+ 8
- 2
templates/default/openstack.cnf.erb View File

@@ -1,12 +1,18 @@
1 1
 <%= node['openstack']['db']['custom_template_banner'] %>
2 2
 [mysqld]
3 3
 default-storage-engine = <%= node['openstack']['mysql']['default-storage-engine'] %>
4
+innodb_autoinc_lock_mode = <%= node['openstack']['mysql']['innodb_autoinc_lock_mode'] %>
5
+innodb_file_per_table = <%= node['openstack']['mysql']['innodb_file_per_table'] %>
4 6
 innodb_thread_concurrency = <%= node['openstack']['mysql']['innodb_thread_concurrency'] %>
5 7
 innodb_commit_concurrency = <%= node['openstack']['mysql']['innodb_commit_concurrency'] %>
6 8
 innodb_read_io_threads = <%= node['openstack']['mysql']['innodb_read_io_threads'] %>
7 9
 innodb_flush_log_at_trx_commit = <%= node['openstack']['mysql']['innodb_flush_log_at_trx_commit'] %>
8
-<% if node['openstack']['mysql']['skip-name-resolve'] %>
10
+innodb_buffer_pool_size = <%= node['openstack']['mysql']['innodb_buffer_pool_size'] %>
11
+innodb_log_file_size = <%= node['openstack']['mysql']['innodb_log_file_size'] %>
12
+innodb_log_buffer_size = <%= node['openstack']['mysql']['innodb_log_buffer_size'] %>
13
+<%- if node['openstack']['mysql']['skip-name-resolve'] %>
9 14
 skip-name-resolve
10
-<% end %>
15
+<%- end %>
11 16
 character-set-server = <%= node['openstack']['mysql']['character-set-server'] %>
17
+query_cache_size = <%= node['openstack']['mysql']['query_cache_size'] %>
12 18
 max_connections = <%= node['openstack']['mysql']['max_connections'] %>

Loading…
Cancel
Save