curl测试http请求各时间段

curl 简单又强大,要好好学习。

test_output=/tmp/curl-test
test_times=3000
test_url="http://jpuyy.com/wp-content/uploads/2012/03/bg.gif"
for i in $(seq 1 $test_times);
    do curl -o /dev/null -s -w 'time_namelookup:%{time_namelookup} time_connect:%{time_connect} time_appconnect:%{time_appconnect} time_pretransfer:%{time_pretransfer} time_redirect:%{time_redirect} time_starttransfer:%{time_starttransfer} time_total:%{time_total}' $test_url >> $test_output 2>&1
    echo >> $test_output
done

按总时间(最后一段)排序,取出 10 次用时最长的访问

cat /tmp/curl-test | sort -k 7 | tail -n 10

服务器上到底花了多少时间呢

time_starttransfer - time_pretransfer

保存一个 format 文件

\n
              url_effective:  %{url_effective}\n
                  http_code:  %{http_code}\n
            time_namelookup:  %{time_namelookup}\n
            time_appconnect:  %{time_appconnect}\n
               time_connect:  %{time_connect}\n
            time_appconnect:  %{time_appconnect}\n
           time_pretransfer:  %{time_pretransfer}\n
              time_redirect:  %{time_redirect}\n
         time_starttransfer:  %{time_starttransfer}\n
               num_connects:  %{num_connects}\n
              num_redirects:  %{num_redirects}\n
                            ----------\n
                 time_total:  %{time_total}\n
\n
              size_download:  %{size_download}\n
                size_header:  %{size_header}\n
               size_request:  %{size_request}\n
\n

curl 请求的时候加 -w @curl-format 调用此格式

发表评论

电子邮件地址不会被公开。 必填项已用*标注