How HTTP client-server interaction works
A Web server receives a request from a client for index.php page, for example, generates a page with static HTML content and sends to the client. This is Time to First byte (TTFB).
Then client web browser starts executing index.php: requests content mentioned in the page – various scripts, images etc. The scripts are delivered from the server and a web browser starts executing them.
Possible causes
- Server-side problems: web or MySQL service workload/bad optimisation.
- Network problems: connection is not stable or bandwidth is not sufficient.
- Site uses not optimal PHP version
- Website code problems: content size and website code optimization.
- Slow DNS servers are used.
Troubleshooting steps
Note: To get an idea what is a good value, compare your website performance against big service providers such as Google, Youtube, Amazon, Microsoft, etc.
Check Time To First Byte (TTFB) value for static (e.g. .html files) and dynamic (e.g. .php files) content:
# curl -s -w '\nLookup time:\t\t%{time_namelookup}\nConnect time:\t\t%{time_connect}\nSSL handshake time:\t%{time_appconnect}\nPre-Transfer time:\t%{time_pretransfer}\nRedirect time:\t\t%{time_redirect}\nStart transfer time:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null http://example.com
Lookup time: 0.055
Connect time: 0.224
SSL handshake time: 0.000
Pre-Transfer time: 0.225
Redirect time: 0.000
Start Transfer time: 0.395
Total time: 0.395
Subtract the "Start Transfer" value from the "Pre-Transfer" value to get TTFB value. In the example above, the TTFB value is a lot less than 1 second and this means that the web server is not causing the issue. If the value is more than one second, follow the steps from this article to troubleshoot the web server further: TTFB is too high. Another reason can be due to exceeded FcgidMaxProcesses processes or reached pm.max_children PHP-FPM limit. Also, basic checking for possible DDoS attack can be performed.
Plugins, Themes periodically are updated and require higher PHP version. Switch PHP to highest possible version in Domains > example.com > Hosting Settings
The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization. Activate MySQL slow query log and make sure that there are no entries. Contact website developer if slow queries are found. The article: MySQL performance is slow. How to improve it? - can help to investigate MySQL performance issue.
Try to open the website from a workstation in the other physical location (webpagetest.org or tools.pingdom.com). If from the other location/network it opens fine, contact system administrator to test network connection bandwidth (iperf) and stability (mtr). If the bandwidth is small, consider compressing website static content (images) – see the next step.
If most of bandwidth is taken by DNS, test website with another DNS servers, for example use 8.8.8.8 Google DNS.
-
If the website is "heavy", optimize its size by compressing images, for example.
-
Use Fiddler or webpagetest.org to find out which HTTP requests take the most time to execute: it can be slow authentication requests,
.aspx
pages compiled slowly due to antivirus or not optimized script. -
If the website is written in PHP and served by PHP-FPM, slowlog can be enabled. It allows logging scripts (not just their names, but their PHP backtraces too, using ptrace and similar things to read remote process' execute_data) that are executed unusually slow.
To enable it go to Plesk > Domains > example.com > PHP Settings > Additional directives > Additional configuration directives
CONFIG_TEXT: [php-fpm-pool-settings]
slowlog = /var/www/vhosts/example.com/slow.log
request_slowlog_timeout = 5sYou can replace
5s
with any other value. This will help find scripts which execute slowly. Image resizing function, network I/O related functions are some examples which will frequently show-up in PHP slowlog. -
To analyze the code for optimization (decrease execution time for scripts) contact the website developer. The optimized code is handled by web browsers faster.
-
To reduce the size of transmitted data GZip compression can be enabled
Comments
1 comment
I suggest you check the /etc/resolv.conf file.
If localhost (127.0.0.1) is not in the first place then change that.
If you are already using dynamic addition to resolv.conf, the default option on server providers, then make sure that the first place is 127.0.0.1. You can achieve this by editing the files in /etc/resolvconf/resolv.conf.d/ in the head file add entries:
nameserver ::1
nameserver 127.0.0.1
I have spent a lot of time to come to the conclusion that if you have a foreign server entered and it is slow or with restrictions, the whole plesk panel works slowly and even can fail to work.
Please sign in to leave a comment.