Running Ghost on 1GB RAM - mySQL fix

I made an annotated guide to the tuning settings posted above. This is not an endorsement of them, just explaining how the defaults were changed and what the impact might be.

Generally, it seems they try to trade lower memory use for increased disk I/O or higher CPU load. It’s not clear which settings are really making the most impact without testing them.

One setting that would be a “win-win” for personal blog would be turn down the max_connections. I’m running 5 blogs one 2 GB memory instance and the max connections MySQL has ever needed at once is about 25, compared to the default of 151.

This is not necessarily related to the “max visitors at one time”. For example, Nginx can be serving static files and even the Ghost blog itself can send multiple queries through a single MySQL connection. And if Nginx connections are tuned probably, when the site starts to overload, Nginx can queue the connections rather than completely overloading the server.

So for a single blog, I might try max_connections = 10 and separately read up on tuning your Nginx connection limits.


# The Performance Schema enables some monitoring tools for 1 to 3% CPU penalty.
# If you are using those monitoring tools, turn it off to improve performance.
# https://dev.mysql.com/blog-archive/performance-schema-great-power-comes-without-great-cost/
performance_schema = off

# The default value of key_buffer_size is 8M. 
# Increasing the value to 25% of RAM improves index performance
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_key_buffer_size
key_buffer_size = 16M

# default value for tmp_table_size is 16M
# defines the maximum size of any individual in-memory internal temporary table  
# Lowering it could save memory but reduce performance
# https://dev.mysql.com/doc/refman/8.0/en/internal-temporary-tables.html
tmp_table_size = 1M

# default value for innodb_buffer_pool_size is 128M
# Lowering it reduces memory use while increasing disk I/0
# https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_buffer_pool_size 
innodb_buffer_pool_size = 1M

# The default value of innodb_log_buffer_size is 16M
# buffer size that InnoDB uses to write to the log files on disk.
# reducing it saves memory but increases Disk I/O in some casees.
# https://dev.mysql.com/doc/refman/8.0/en/innodb-parameters.html#sysvar_innodb_buffer_pool_size
innodb_log_buffer_size = 1M

# The default value of max_connections is 151
# Reducing connections reduces memory.
# For a personal blog, as few as 10 may be sufficient.
# There's no point setting the value higher than the number that the application 
can use under load.
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_connections
max_connections = 50

# The default value of sort_buffer_size is 256K
# It's the amount memory allocated when sorting
# It's not clear why increasing it would improve performance or reduce memory
# on a smaller server.
# ref: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_sort_buffer_size
sort_buffer_size = 512K

# The default for read_buffer_size is 128K
# Increasing it may help the performance of sequential scans
# Ref: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_read_buffer_size
read_buffer_size = 256K

# The default value for read_rnd_buffer_size is 256K
# A higher value improves disk I/O but uses more memory.
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_read_rnd_buffer_size
read_rnd_buffer_size = 512K

# The default size for join_buffer_size is 256K 
# Smaller values can slow down joins but use less memory
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_join_buffer_size
join_buffer_size = 128K

# The default size of thread_stack varies up to 1048k
# A smaller size limits the complexity of SQL the server can handle,
# but saves memory
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_thread_stack
thread_stack = 196K
1 Like