Applicable to:
- Plesk for Windows
- Plesk for Linux
Question
The initial website appearance time (Time To First Byte) takes much time. What can be done to improve it?
Answer
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.
Time To First Byte (TTFB) is a metric that depends on many variables. It can equally be intertwined either with the destination server side of things or any other node of the connection route.
First of all, check if the issue relates to Network particularities.
-
On Windows server, open website locally and check TTFB with browsers Development mode (can be enabled in any browser with F12).
-
On Linux server execute the below command with websites URL:
# 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}\nTime to first byte:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null http://example.com
If TTFB in local environment reduces significantly (more than 500ms), contact system administrator to test network connection bandwidth (iperf) and stability (mtr).
If most of bandwidth is taken by DNS, test website with another DNS servers, for example use 8.8.8.8 Google DNS.
-
Go to Plesk > Domains > example.com > File Manager and create test_ttfb_file.php and test_ttfb_file.html.
Note: change the "example.com" website name in the path above to the correct one.
-
Open the test_ttfb_file.php file and add the next content:
CONFIG_TEXT: <?php
phpinfo();
?> -
Open the test_ttfb_file.html file and add the following content:
CONFIG_TEXT: <html>
<body>
Hello world
</body>
</html> -
Check TTFB on these sample pages by opening them in a browser with the debug console (can be enabled in any browser with F12) or by execution commands below:
Note: change the "example.com" website name in the commands below to the correct one.
# 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}\nTime to first byte:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null https://example.com/test_ttfb_file.html
Lookup time: 0.000956
Connect time: 0.052297
SSL handshake time: 0.167975
Pre-Transfer time: 0.168120
Redirect time: 0.000000
Time to first byte: 0.223718
Total time: 0.223787# 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}\nTime to first byte:\t%{time_starttransfer}\n\nTotal time:\t\t%{time_total}\n' -o /dev/null https://example.com/test_ttfb_file.php
Lookup time: 0.000868
Connect time: 0.051084
SSL handshake time: 0.165087
Pre-Transfer time: 0.165256
Redirect time: 0.000000
Time to first byte: 0.224418
Total time: 0.224494 -
If TTFB for sample files is fine the root cause of the issue is connected with the website code. Follow further steps to continue the issue troubleshooting.
Once the Network performance is considered as fine and sample pages are load fast, proceed to the optimization of website/webserver per instructions below.
Ideally, each case should be inspected and treated individually. General recommendations can be found below:
-
In most cases, there are some plugins, which can contain heavy content or deprecated PHP functions. Try to disable all plugins at Plesk > Domains > WordPress > Plugins. If it helped, try to determine the plugin, which causes delay by enabling them one by one.
-
The same can be caused by themes. Try to enable default WordPress theme (for example, "Twenty Seventeen", "Twenty Sixteen") and check TTFB.
-
Improve performance on web server side: go to Plesk > Domains > example.com > Apache & nginx Settings and turn on the following options:
- Proxy mode
- Smart static files processing
- Serve static files directly by nginx
- Enable nginx caching
-
Enable "keep-alive" requests in Apache: go to Plesk > Domains > example.com > Apache & nginx Settings and add the following Additional directives for HTTP and Additional directives for HTTPS fields:
CONFIG_TEXT: KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 100
-
Enable Dedicated application pool for the website at Domains > example.com > Dedicated IIS Application Pool for Website > Switch On.
-
Connect to the server via RDP.
-
Open Internet Information Services (IIS) Manager at Control Panel > Administrative Tools > Internet Information Services (IIS) Manager
-
Go to SERVERNAME > Application Pools, right-click on the application pool of the website, choose Advanced Settings
-
In appeared windows change in (General) section "Start Mode" to AlwaysRunning.
-
Change in CPU section "Limit action" to No Action.
-
Go to Sites > example.com > Advanced Settings... (in the right pane).
-
Switch the "Preload Enabled" option to True.
Comments
0 comments
Please sign in to leave a comment.