A website response time can have a great impact on user experience, and if you are a web developer, or simply a server administrator who is particularly responsible for organizing the pieces together, then you have to make it a point that users don’t feel frustrated while accessing your site – so there is really “need for speed”.
Read Also: httpstat – A Curl Statistics Tool to Check Website Performance
This guide will show you how to test a website response time from the Linux command line. Here, we will show how to check the time in seconds, it takes:
- to perform name resolution.
- for TCP connection to the server.
- for the file transfer to begin.
- for the first byte to be transferred.
- for the complete operation.
Additionally, for HTTPS-enabled sites, we will also see how to test the time, in seconds, it takes: for a redirect, and SSL connection/handshake to the server to be completed. It sounds good right, okay, let’s get started.
cURL is a powerful command line tool to transfer data from or to a server, using protocols such as FILE, FTP, FTPS, HTTP, HTTPS and many others. In most cases, it is used as a command line downloader, or for checking HTTP headers. However, here, we will describe one of its lesser-known functionalities.
cURL has a useful option: -w
for printing information on stdout after a completed operation. It has some variables that we can use to test the different response times listed above, of a website.
We will use some of the time-related variables, which can be passed in a given format as a literal string or inside a file.
So open your terminal and run the command below:
$ curl -s -w 'Testing Website Response Time for :%{url_effective}/n/nLookup Time:/t/t%{time_namelookup}/nConnect Time:/t/t%{time_connect}/nPre-transfer Time:/t%{time_pretransfer}/nStart-transfer Time:/t%{time_starttransfer}/n/nTotal Time:/t/t%{time_total}/n' -o /dev/null http://www.google.com
Test Website Loading Speed
The variables in the above format are:
- time_namelookup – time, in seconds, it took from the start until the name resolving was completed.
- time_connect – time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.
- time_pretransfer – time, in seconds, it took from the start until the file transfer was just about to begin.
- time_starttransfer – time, in seconds, it took from the start until the first byte was just about to be transferred.
- time_total – total time, in seconds, that the full operation lasted (millisecond resolution).
If the format is too long, you can write it in a file and use the syntax below to read it:
$ curl -s -w "@format.txt" -o /dev/null http://www.google.com
In the above command, the flag:
-s
– tells curl to work silently.-w
– print the information on stdout.-o
– used to redirect output (here we discard the output by redirecting it to /dev/null).
For HTTPS sites, you can run the command below:
$ curl -s -w 'Testing Website Response Time for :%{url_effective}/n/nLookup Time:/t/t%{time_namelookup}/nConnect Time:/t/t%{time_connect}/nAppCon Time:/t/t%{time_appconnect}/nRedirect Time:/t/t%{time_redirect}/nPre-transfer Time:/t%{time_pretransfer}/nStart-transfer Time:/t%{time_starttransfer}/n/nTotal Time:/t/t%{time_total}/n' -o /dev/null https://www.google.com
Test HTTPS Website Speed
In the above format, the new time variables are:
- time_appconnect – time, in seconds, it took from the start until the SSL connect/handshake to the remote host was completed.
- time_redirect – time, in seconds, it took for all redirection steps including name lookup, connect, pretransfer and transfer before the final transaction was started; it computes the full execution time for multiple redirections.
Important points to be noted.
- You will notice that the response time values keep on changing (due to several factors) as you run different tests, therefore it is advisable to collect several values and get an average speed.
- Secondly, from the results of the commands above, you can see that accessing a website over HTTP is much faster than over HTTPS.
For more information, see the cURL man page:
$ man curl
Last but not least, if your results are not pleasing, then you have some adjustments to make on your server or within the code. You may consider using the following tutorials which explain programs and tips to make website(s) load faster in Linux:
- Install Nginx with Ngx_Pagespeed (Speed Optimization) on Debian and Ubuntu
- Speed Up Nginx Performance with Ngx_Pagespeed on CentOS 7
- Learn How to Speed Up Websites Using Nginx and Gzip Module
- How to Boost Linux Server Internet Speed with TCP BBR
That’s all! Now you know how to test website response time from the command line. You can ask questions via the feedback form below.
Source: tecmint.com