K
K
Konstantin Khairov2018-11-09 21:02:50
linux
Konstantin Khairov, 2018-11-09 21:02:50

How to reduce load from apache and mysql?

Hello everyone, there is a site with a small attendance of 3-4k per day. Now half of the old news has been removed from the site due to the lack of relevance, the database has become 2 times less weight, but that's the problem when there are 100-150 people on the site, the site began to slow down terribly.
VDS parameters: 2 processor cores 100GB
SSD
2GB RAM
It used to work fine and so online, but now it slows down the only thing that has changed during this time is now used by MariaDB and Apache used to be just Mysql.
Apache goes in conjunction with Nginx
At peak consumption according to VESTACP
Apache
httpd
web server
Processor: 1.5Memory: 93 MB Running
: 0 min.
mysql mariadb
database server

Processor: 3.7 Memory: 1119 MB Running
: 53 min.

Usually Mysql spent 600-700 and here are the numbers.
I tried editing the config, but it didn't really help. Maybe I did something wrong there because of inexperience.
Here are the configs

Mysql config

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld]
skip-external-locking
key_buffer_size = 4M
max_allowed_packet = 1M
table_open_cache = 128
max_connections = 40
sort_buffer_size = 4M
read_buffer_size = 128K
read_rnd_buffer_size = 128K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 4M
query_cache_type = 1
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 2
#skip-locking
key_buffer = 16K
max_allowed_packet = 1M
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 64K
innodb=OFF
default-storage-engine = MyISAM
#slow_query_log=1
#slow_query_log_file=/var/log/mysql-slow-queries.log
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 32M
read_buffer = 2M
write_buffer = 2M
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
Apache config (Used by PREFORK)

ServerRoot "/etc/httpd"
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin [email protected]
ServerTokens OS
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
Timeout 10
MaxClients 30
KeepAlive on
KeepAliveTimeout 5
MaxRequestsPerChild 3000
StartServers 4
MaxClients 100
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
StartServers 10
MinSpareServers 10
MaxSpareServers 16
MaxClients 100
MaxRequestsPerChild 3000
ServerAdmin [email protected]
ServerAdmin [email protected]
DocumentRoot "/home/admin/web/ sitename.uz/public_html"
ServerName sitename
ErrorLog /home/admin/web/ sitenameuz/logs/log.log
CustomLog /home/admin/web/ sitename.uz/logs/log.log common
AllowOverride none
DocumentRoot "/home/admin/web/"
AllowOverride None
Require all granted
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
DirectoryIndex index.php index.html
Require all denied
ErrorLog "logs/error_log"
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%b" bytes
CustomLog "logs/access_log" combined
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
#AddHandler cgi-script .cgi
AddDefaultCharset UTF-8
MIMEMagicFile conf/magic
EnableSendfile on
RemoteIPHeader X-Real-IP
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%a %l %u %t \"%r\" %>s %b" common
IncludeOptional conf.d/*.conf
#Включаем Worker
LoadModule auth_digest_module modules/mod_mpm_worker.so
#LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule ruid2_module modules/mod_ruid2.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
#LoadModule ldap_module modules/mod_ldap.so
#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
#LoadModule suexec_module modules/mod_suexec.so
#LoadModule disk_cache_module modules/mod_disk_cache.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule mem_cache_module modules/mod_mem_cache.so
#LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so

The server generates the site page in 5-7 seconds per peak and usually in 0.4 - 0.7
What else needs to be changed in the config to somehow optimize all this and speed up the site

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TyzhSysAdmin, 2018-11-09
@POS_troi

Self-written engine?
Well, so, with such a load (in visitors), there should not be a problem with Apache and the database, and it is not the server that needs to be optimized here, but the CODE.
Most likely you have a problem with "crooked SQL queries"
PS 2Gb RAM is not enough by today's standards.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question