0

We have newly installed Ubuntu 16.4 LTS + apache + mysql virtual server on Windows server 2016 enviroment.

Our present production system on Cloud service works like it should be, page load time on server ~200ms or so. But when used on our enviroment same page has load times like 3,4 seconds. This happend on only one particular PHP page. Other pages have somewhat ok results on page load time.

Server has got lot of resources free and I have given server 40 cores (all) and 8 gigabytes of ram. So it's should not be becouse of lack of resources.

I have so far tweaked out mysql. if I run SQL queries sraight with phpmyadmin they response times are something like 0,02sec / query...

I think our enviroment has something that block PHP scripts or some network related thing or something wrong with PHP, apache settings...

Where to start debugging this problem? how do I speed up PHP? I have done lot's of googling but non of them haven't helped. Thing like do not call mysql localhost, use instead 127.0.0.1 and so on.

Timo77
  • 111
  • 2
  • 5
  • 13
  • You'll want to start with a profiler, to see what parts of the page's execution are taking up time. https://blackfire.io/ is good, as is xdebug. – ceejayoz Oct 10 '17 at 18:16
  • I did some profiling with blackfire.io It seems like mysql is taking a lot's of time... Promlem is why. Same page, same queries on slighly different enviroment works like it should be. But on our enviroment it takes time. I have same database tables same structure copied to mysql etc. Is there something on mysql config I should do? – Timo77 Oct 11 '17 at 06:13

2 Answers2

0

The main problem was in mysql configuration. Some of these settings were critical to mysql performance. Present setting:

    #
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 0.0.0.0
#
#omat saadot
key_buffer_size = 128M
#kopioitu vanhasta
sort_buffer_size = 12M
read_buffer_size = 12M
read_rnd_buffer_size = 12M
myisam_sort_buffer_size = 76M
query_cache_type=1

thread_stack = 128K
max_heap_table_size = 256M
query_cache_limit = 1M
query_cache_size = 16M

innodb_log_file_size = 512M

#kopioituja vanhasta
# In theory, you want this to encompass your entire database. In
# practice, you only have so much RAM available
innodb_buffer_pool_size = 512M
# Reduce contention. Set to 4+ in MySQL 5.5+
innodb_buffer_pool_instances = 4
# O_DIRECT bypasses the operating system's handling of data. This can
# drastically improve how well your system handles large amounts of RAM by
# removing buffers (once in InnoDB's cache, again in the filesystem's
# cache), at a slight cost to reliability. This appears to be more dramatic
# the more RAM you have. Should reduce swap pressure and in most cases
# improves performance.
#innodb_flush_method = O_DIRECT
# Control Durability
# 1=flush and sync; 2=flush; 0=neither
# Setting innodb_flush_log_at_trx_commit to 0 causes InnoDB to only flush to
# disk once per second, improving performance considerably.
innodb_flush_log_at_trx_commit = 0
# How long to wait for row level locks before bailing out.
innodb_lock_wait_timeout = 180
# The number of open tables for all threads. Increasing this value increases
# the number of file descriptors that mysqld requires.
#table_cache = 4096
# The next two lines replace the basic table_cache value as of MySQL 5.1.
# table_definition_cache should be big enough for every table in your database,
# plus temporary tables, and table_open_cache should be a reflection of how
# many of these will be open in a live connection at once - it will likely
# exceed your definition cache.  It doesn't hurt to set these to large values.
# They don't take a lot of RAM and it's better than hitting the limit.
table_definition_cache = 4096
table_open_cache = 16384
# The default optimizer_search_depth is 62. This causes MySQL to take
# an obscene amount of time planning a query, though when it finally
# executes, it is pretty close to optimal.
optimizer_search_depth = 32
#open-files = 10000




skip_name_resolve

# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
slow_query_log=1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 1
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size   = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem


sql-mode="TRADITIONAL"

Previous settings were the default setting mysql has after install and after first startup I think:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size     = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries   = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id      = 1
#log_bin            = /var/log/mysql/mysql-bin.log
expire_logs_days    = 10
max_binlog_size   = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

I'am not sure what it the most critical? Should I even raise those values more? I do have lot's of memory to be used. At he moment I have 8 gigabytes of memory on this virtual machine.

i would like to know what might cause so big diffrence on mysql? Do you have some prefered settings for Mysql on production, what?

Timo77
  • 111
  • 2
  • 5
  • 13
0

If you will remove from your configuration file the following lines,

sort_buffer_size
read_buffer_size
read_rnd_buffer_size

system DEFAULTS will work for you and avoid extensive RAM allocation that is detrimental to each new connection. Use of MySQLCalculator.com will be helpful for you to understand this answer related to these 3 Critical RAM resources PER connection.

Wilson Hauck
  • 426
  • 4
  • 10