We’ve got a site that is running pretty slow. Time to first byte (TTFB) can be up to 5 seconds or more. This is a lot of waiting for the customer who is supposed to be browsing the site. I’ve tried optimising PHP, Nginx, Litespeed, MySQL etc but have had no luck yet.
The server we are using has the following specs -
CPUs - 4 x 12 core @ 2.1 Ghz (48 cores in total)
Memory - 512 GB DDR3
Drive - SSD running at 500 MB/s
Running Centos with cPanel
The database is a decent size but nothing huge. It has the following records -
new_orders - 8,523,192
products_categories - 51,236
order_details - 28,839
images - 27,659
product_sales - 22,119
product_option_variants - 19,558
product_option_variants_descriptions - 19,558
orders - 17,744
MySQL slow logs the following slow queries -
/usr/sbin/mysqld, Version: 5.1.68-cll (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
Time Id Command Argument
Time: 130412 16:12:32
User@Host: onlineshop_user[onlineshop_user] @ localhost []
Query_time: 2.836568 Lock_time: 0.000694 Rows_sent: 12 Rows_examined: 225052
use onlineshop_basedb;
SET timestamp=1365747152;
SELECT SQL_CALC_FOUND_ROWS products.*, descr1.product as product, MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price, descr1.short_description, IF(descr1.short_description = ‘’, descr1.full_description, ‘’) as full_description, companies.company as company_name, GROUP_CONCAT(IF(products_categories.link_type = ‘M’, CONCAT(products_categories.category_id, ‘M’), products_categories.category_id)) as category_ids, products_categories.position, os_seo_names.name as seo_name FROM os_products as products LEFT JOIN os_product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = ‘EN’ LEFT JOIN os_product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1 LEFT JOIN os_companies AS companies ON companies.company_id = products.company_id INNER JOIN os_products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN os_categories ON os_categories.category_id = products_categories.category_id AND (os_categories.usergroup_ids = ‘’ OR FIND_IN_SET(0, os_categories.usergroup_ids) OR FIND_IN_SET(1, os_categories.usergroup_ids)) AND os_categories.status IN (‘A’, ‘H’) LEFT JOIN os_seo_names ON os_seo_names.object_id = products.product_id AND os_seo_names.type = ‘p’ AND os_seo_names.dispatch = ‘’ AND os_seo_names.lang_code = ‘EN’ WHERE 1 AND os_categories.category_id IN (1, 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, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 150, 155, 168, 169) AND (companies.status = ‘A’ OR products.company_id = 0) AND (products.usergroup_ids = ‘’ OR FIND_IN_SET(0, products.usergroup_ids) OR FIND_IN_SET(1, products.usergroup_ids)) AND products.status IN (‘A’) AND prices.usergroup_id IN (0, 0, 1) GROUP BY products.product_id ORDER BY descr1.product asc LIMIT 0, 12;
Time: 130412 16:12:40
User@Host: onlineshop_user[onlineshop_user] @ localhost []
Query_time: 2.685642 Lock_time: 0.000539 Rows_sent: 12 Rows_examined: 133744
SET timestamp=1365747160;
SELECT SQL_CALC_FOUND_ROWS products.*, descr1.product as product, MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price, descr1.short_description, IF(descr1.short_description = ‘’, descr1.full_description, ‘’) as full_description, companies.company as company_name, GROUP_CONCAT(IF(products_categories.link_type = ‘M’, CONCAT(products_categories.category_id, ‘M’), products_categories.category_id)) as category_ids, products_categories.position, os_seo_names.name as seo_name FROM os_products as products LEFT JOIN os_product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = ‘EN’ LEFT JOIN os_product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1 LEFT JOIN os_companies AS companies ON companies.company_id = products.company_id INNER JOIN os_products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN os_categories ON os_categories.category_id = products_categories.category_id AND (os_categories.usergroup_ids = ‘’ OR FIND_IN_SET(0, os_categories.usergroup_ids) OR FIND_IN_SET(1, os_categories.usergroup_ids)) AND os_categories.status IN (‘A’, ‘H’) LEFT JOIN os_seo_names ON os_seo_names.object_id = products.product_id AND os_seo_names.type = ‘p’ AND os_seo_names.dispatch = ‘’ AND os_seo_names.lang_code = ‘EN’ WHERE 1 AND os_categories.category_id IN (2, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124) AND (companies.status = ‘A’ OR products.company_id = 0) AND (products.usergroup_ids = ‘’ OR FIND_IN_SET(0, products.usergroup_ids) OR FIND_IN_SET(1, products.usergroup_ids)) AND products.status IN (‘A’) AND prices.usergroup_id IN (0, 0, 1) GROUP BY products.product_id ORDER BY descr1.product asc LIMIT 0, 12;
Time: 130412 16:12:46
User@Host: onlineshop_user[onlineshop_user] @ localhost []
Query_time: 1.069359 Lock_time: 0.000524 Rows_sent: 12 Rows_examined: 51434
SET timestamp=1365747166;
SELECT SQL_CALC_FOUND_ROWS products.*, descr1.product as product, MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price, descr1.short_description, IF(descr1.short_description = ‘’, descr1.full_description, ‘’) as full_description, companies.company as company_name, GROUP_CONCAT(IF(products_categories.link_type = ‘M’, CONCAT(products_categories.category_id, ‘M’), products_categories.category_id)) as category_ids, products_categories.position, os_seo_names.name as seo_name FROM os_products as products LEFT JOIN os_product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = ‘EN’ LEFT JOIN os_product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1 LEFT JOIN os_companies AS companies ON companies.company_id = products.company_id INNER JOIN os_products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN os_categories ON os_categories.category_id = products_categories.category_id AND (os_categories.usergroup_ids = ‘’ OR FIND_IN_SET(0, os_categories.usergroup_ids) OR FIND_IN_SET(1, os_categories.usergroup_ids)) AND os_categories.status IN (‘A’, ‘H’) LEFT JOIN os_seo_names ON os_seo_names.object_id = products.product_id AND os_seo_names.type = ‘p’ AND os_seo_names.dispatch = ‘’ AND os_seo_names.lang_code = ‘EN’ WHERE 1 AND os_categories.category_id IN (129, 130, 133, 149, 135, 141, 143, 144, 145, 146, 147, 148, 151, 152, 153, 154, 156, 167) AND (companies.status = ‘A’ OR products.company_id = 0) AND (products.usergroup_ids = ‘’ OR FIND_IN_SET(0, products.usergroup_ids) OR FIND_IN_SET(1, products.usergroup_ids)) AND products.status IN (‘A’) AND prices.usergroup_id IN (0, 0, 1) GROUP BY products.product_id ORDER BY descr1.product asc LIMIT 0, 12;
Time: 130412 16:12:47
User@Host: onlineshop_user[onlineshop_user] @ localhost []
Query_time: 0.228424 Lock_time: 0.000527 Rows_sent: 1 Rows_examined: 26155
SET timestamp=1365747167;
SELECT MIN(os_product_prices.price) min, MAX(os_product_prices.price) max FROM os_product_prices LEFT JOIN os_products ON os_products.product_id = os_product_prices.product_id LEFT JOIN os_product_prices as prices_2 ON os_product_prices.product_id = prices_2.product_id AND os_product_prices.price > prices_2.price AND prices_2.lower_limit = 1 AND prices_2.usergroup_id IN (0, 0, 1) INNER JOIN os_products_categories ON os_products_categories.product_id = os_products.product_id LEFT JOIN os_categories ON os_categories.category_id = os_products_categories.category_id LEFT JOIN os_companies as companies ON companies.company_id = os_products.company_id WHERE os_products.status IN (‘A’) AND os_products_categories.category_id IN (130, 133, 135, 141, 143, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 156, 167, 129) AND (os_categories.usergroup_ids = ‘’ OR FIND_IN_SET(0, os_categories.usergroup_ids) OR FIND_IN_SET(1, os_categories.usergroup_ids)) AND (os_products.usergroup_ids = ‘’ OR FIND_IN_SET(0, os_products.usergroup_ids) OR FIND_IN_SET(1, os_products.usergroup_ids)) AND os_categories.status IN (‘A’, ‘H’) AND os_products.status IN (‘A’) AND (companies.status = ‘A’ OR os_products.company_id = 0) AND os_product_prices.lower_limit = 1 AND os_product_prices.usergroup_id IN (0, 0, 1) AND prices_2.price IS NULL;
I’ve tried running these commands into MySQL directly and it gives some slow queries -
Showing rows 0 - 11 ( 12 total, Query took 5.1814 sec)
Either MySQL is not optimised well or CS Cart database programming is totally inefficient.
I’ve gone through various versions of my.cnf but here is the current one -
Example MySQL config file for large systems.
#
This is for a large system with memory = 512M where the system runs mainly
MySQL.
#
MySQL programs look for option files in a set of
locations which depend on the deployment platform.
You can copy this option file to one of those
locations. For information about these locations, see:
http://dev.mysql.com/doc/mysql/en/option-files.html
#
In this file, you can use all long options that a program supports.
If you want to know which options a program supports, run the program
with the “–help” option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
safe-show-database
key_buffer_size = 256M
max_allowed_packet = 128M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 256
query_cache_size= 64M
query_cache_limit=2M
query_cache_type=1
table_cache=1024
join_buffer=2M
record_buffer=1M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,
# MASTER_USER=, MASTER_PASSWORD= ;
#
# where you replace , , by quoted strings and
# by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host =
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user =
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port =
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
I have contacted CS Cart support and waiting for their response. Any suggestions would be appreciated!