zhmg23

我们是如此的不同

如何在Linux终端上测试网站加载速度

1、测试http请求速度

# 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 "https://www.baidu.com"

Testing Website Response Time for :https://www.baidu.com/

Lookup Time:0.002

Connect Time:0.028

Pre-transfer Time:0.028

Start-transfer Time:0.055

Total Time:0.055

 

注:上述命令格式中的变量

time_namelookup - 以秒为单位的时间,从开始到名称解析完成。

time_connect - 从开始到TCP连接到远程主机(或代理)完成所花费的时间,以秒为单位。

time_pretransfer - 时间,以秒为单位,从开始到文件传输即将开始。

time_starttransfer - 以秒为单位的时间,从开始到第一个字节即将被转移。

time_total - 以秒为单位的总操作持续时间(毫秒分辨率)。

如果格式太长,可以将其写入一个文件中,并使用下面的语法来读取它:

# curl -s -w“@ format.txt”-o / dev / null https://www.baidu.com

-s - 告诉curl默默地工作。

-w - 在标准输出上打印信息。

-o- 用于重定向输出(这里我们通过将其重定向到/ dev / null来丢弃输出)。

2、对于https站点的测试,可用如下命令

# 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.baidu.com

Testing Website Response Time for :https://www.baidu.com/

 

在上面的格式中,新的时间变量是:

time_appconnect - 以秒为单位,从开始直到到远程主机的SSL连接/握手完成。

time_redirect - 时间,以秒为单位,包括名称查找,连接,预转移和转移之前的所有重定向步骤。它计算多个重定向的完整执行时间。

需要注意

您会注意到,当您运行不同的测试时,响应时间值会不断变化(由于多种因素),因此建议您收集多个值并获取平均速度。

其次,从上面的命令的结果可以看出,通过HTTP访问网站比通过HTTPS快得多。


评论