linux命令测试https,用linux curl命令来测试http/https各部分(dns,tcp,ssl等)的耗时

来看下如下linux命令:

curl -X POST -w '\n\n 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}\n' \

https://www.baidu.com:443/ \

-H 'Cache-Control: no-cache' \

-H 'Content-Type: application/json' \

-d '{

"k1": "xxx",

"k2": "yyy",

"token": "123456789"

}'

结果:

time_namelookup: 0.004

time_connect: 0.153

time_appconnect: 0.702

time_pretransfer: 0.702

time_redirect: 0.000

time_starttransfer: 0.863

----------

time_total: 0.865

注意,上面的时间有累积性,单位是秒。

比如:

dns解析的耗时是0.004s

tcp连接建立的耗时是: 0.153s - 0.004s

https ssl交互的耗时是:0.702s - 0.153s

https连接建立好到准备发送数据的耗时是: 0.702s - 0.702s

此处不涉及重定向,故为0.000

服务端收到https请求并处理完毕的耗时时间是:0.863s - 0.702s    (包含了服务端的所有处理逻辑)

服务端数据返回到客户端的耗时是:0.865s - 0.863s

再来做个简单实验,服务端go代码为:

package main

import (

"io"

"log"

"time"

"net/http"

)

func handlerHello(w http.ResponseWriter, r *http.Request) {

time.Sleep(3 * time.Second)

io.WriteString(w, "hello girls")

}

func main() {

http.HandleFunc("/hello", handlerHello) // 注册

err := http.ListenAndServe("localhost:8080", nil)

if err != nil {

log.Println(err)

}

}

执行如下命令:

curl -X POST -w '\n\n 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}\n' \

http://localhost:8080/hello \

-H 'Cache-Control: no-cache' \

-H 'Content-Type: application/json' \

-d '{

"k1": "xxx",

"k2": "yyy",

"token": "123456789"

}'

结果是:

taoge:~$ curl -X POST -w '\n\n 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}\n' \

> http://localhost:8080/hello \

> -H 'Cache-Control: no-cache' \

> -H 'Content-Type: application/json' \

> -d '{

> "k1": "xxx",

> "k2": "yyy",

> "token": "123456789"

> }'

hello girls

time_namelookup: 0.004930

time_connect: 0.005109

time_appconnect: 0.000000

time_pretransfer: 0.005150

time_redirect: 0.000000

time_starttransfer: 3.007478

----------

time_total: 3.007560

taoge:~$

注意那个3s, 好好理解一下。

不多说。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值