290
290
class PerconaClusterHelper(object):
292
# Going for the biggest page size to avoid wasted bytes. InnoDB page size is
292
# Going for the biggest page size to avoid wasted bytes.
293
# InnoDB page size is 16MB
294
295
DEFAULT_PAGE_SIZE = 16 * 1024 * 1024
296
DEFAULT_INNODB_BUFFER_FACTOR = 0.50
296
298
def human_to_bytes(self, human):
297
299
"""Convert human readable configuration options to bytes."""
352
354
if 'max-connections' in config:
353
355
mysql_config['max_connections'] = config['max-connections']
355
# Total memory available for dataset
356
dataset_bytes = self.human_to_bytes(config['dataset-size'])
357
mysql_config['dataset_bytes'] = dataset_bytes
359
if 'query-cache-type' in config:
360
# Query Cache Configuration
361
mysql_config['query_cache_size'] = config['query-cache-size']
362
if (config['query-cache-size'] == -1 and
363
config['query-cache-type'] in ['ON', 'DEMAND']):
364
# Calculate the query cache size automatically
365
qcache_bytes = (dataset_bytes * 0.20)
366
qcache_bytes = int(qcache_bytes -
367
(qcache_bytes % self.DEFAULT_PAGE_SIZE))
368
mysql_config['query_cache_size'] = qcache_bytes
369
dataset_bytes -= qcache_bytes
371
# 5.5 allows the words, but not 5.1
372
if config['query-cache-type'] == 'ON':
373
mysql_config['query_cache_type'] = 1
374
elif config['query-cache-type'] == 'DEMAND':
375
mysql_config['query_cache_type'] = 2
377
mysql_config['query_cache_type'] = 0
379
357
# Set a sane default key_buffer size
380
358
mysql_config['key_buffer'] = self.human_to_bytes('32M')
382
if 'preferred-storage-engine' in config:
383
# Storage engine configuration
384
preferred_engines = config['preferred-storage-engine'].split(',')
385
chunk_size = int(dataset_bytes / len(preferred_engines))
386
mysql_config['innodb_flush_log_at_trx_commit'] = 1
387
mysql_config['sync_binlog'] = 1
388
if 'InnoDB' in preferred_engines:
389
mysql_config['innodb_buffer_pool_size'] = chunk_size
390
if config['tuning-level'] == 'fast':
391
mysql_config['innodb_flush_log_at_trx_commit'] = 2
393
mysql_config['innodb_buffer_pool_size'] = 0
395
mysql_config['default_storage_engine'] = preferred_engines[0]
396
if 'MyISAM' in preferred_engines:
397
mysql_config['key_buffer'] = chunk_size
399
if config['tuning-level'] == 'fast':
400
mysql_config['sync_binlog'] = 0
359
total_memory = self.human_to_bytes(self.get_mem_total())
361
log("Option 'dataset-size' has been deprecated, instead by default %d%% of system \
362
available RAM will be used for innodb_buffer_pool_size allocation" %
363
(self.DEFAULT_INNODB_BUFFER_FACTOR * 100), level="WARN")
365
innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)
367
if innodb_buffer_pool_size:
368
innodb_buffer_pool_size = self.human_to_bytes(
369
innodb_buffer_pool_size)
371
if innodb_buffer_pool_size > total_memory:
372
log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
373
innodb_buffer_pool_size,
374
total_memory), level='WARN')
376
innodb_buffer_pool_size = int(
377
total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR)
379
mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
402
380
return mysql_config