Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
litespeed_wiki:ttfb [2018/11/11 01:46]
Erwin Venekamp
litespeed_wiki:ttfb [2018/11/12 16:39]
Erwin Venekamp [Insufficient caching]
Line 1: Line 1:
-====== ​Optimizing time to first byte ====== +====== ​Troubleshooting high TTFB ====== 
-According to Wikipedia, ​TTFB "​measures the duration from the user or client making an HTTP request to the first byte of the page being received by the client'​s browser. This time is made up of the socket connection time, the time taken to send the HTTP request, and the time taken to get the first byte of the page."+According to Wikipedia, ​Time To First Byte "​measures the duration from the user or client making an HTTP request to the first byte of the page being received by the client'​s browser. This time is made up of the socket connection time, the time taken to send the HTTP request, and the time taken to get the first byte of the page."
  
 In short, it is a commonly used performance measurement of how long it takes for the web server to start sending data. It's often misused as a general performance metric: for example, more aggressive gzip compression might worsen your TTFB, but improve your overall page load time. It's useful as a diagnostic indicator though, and this page will go through some common reasons your TTFB might be very high. In short, it is a commonly used performance measurement of how long it takes for the web server to start sending data. It's often misused as a general performance metric: for example, more aggressive gzip compression might worsen your TTFB, but improve your overall page load time. It's useful as a diagnostic indicator though, and this page will go through some common reasons your TTFB might be very high.
  
 +Some useful tools to test your TTFB are http://​www.bytecheck.com and https://​performance.sucuri.net. Remember, you want to try to achieve a sensible TTFB value, not necessarily the best possible TTFB value.
 ===== High resource usage ===== ===== High resource usage =====
 One common reason for high TTFB is high resource usage on your server. All CPU cores might be busy, or your server might be swapping if it's running low on RAM. Some things to check for: One common reason for high TTFB is high resource usage on your server. All CPU cores might be busy, or your server might be swapping if it's running low on RAM. Some things to check for:
   * Run ''​top'':​ how's your CPU usage and RAM looking? Alternatively,​ for RAM, you can also use ''​free -m''​   * Run ''​top'':​ how's your CPU usage and RAM looking? Alternatively,​ for RAM, you can also use ''​free -m''​
   * Run ''​df -h'':​ are any partitions out of disk space?   * Run ''​df -h'':​ are any partitions out of disk space?
 +  * Run ''​iotop'':​ is there an excessive amount of disk IO happening?
   * What about your bandwidth usage? You can use tools like ''​nload''​ to check, and your provider will likely have bandwidth graphs too.   * What about your bandwidth usage? You can use tools like ''​nload''​ to check, and your provider will likely have bandwidth graphs too.
  
 ===== Many queries ===== ===== Many queries =====
-Your TTFB may be high if your website makes very many database queries, or consists of very unoptimized application code (such as PHP). A common example of this is WordPress websites that use dozens of plugins. If possible, look into reducing the workload for your application. Caching ​may also help alleviate thisconsider using [[litespeed_wiki:​cache:​|LiteSpeed Cache]] ​if you aren't already.+Your TTFB may be high if your website makes very many database queries, or consists of very unoptimized application code (such as PHP). A common example of this is WordPress websites that use dozens of plugins. If possible, look into reducing the workload for your application ​by disabling plugins or unnecessary features. 
 + 
 +===== Insufficient caching ===== 
 +Caching ​is a good idea for almost all database-driven applications:​ serving a cached version of a dynamic page will lead to a vastly reduced workload, and improved TTFB. This is especially beneficial if your website has many database queries that can't be avoided or reduced. 
 + 
 +LiteSpeed offers a caching plugin for many popular CMSes: [[litespeed_wiki:​cache:​|LiteSpeed Cache]].
  
 ===== Slow databases ===== ===== Slow databases =====
  • Admin
  • Last modified: 2018/11/12 16:43
  • by Erwin Venekamp