我正在使用ApacheBench进行一些负载测试。我希望ab使用Mac上/ etc / hosts中指定的IP地址来解析主机名。我怎么强迫呢? curl有一个--resolve选项来完成这个,就像指定here一样。我正在寻找类似ab的东西。
答案 0 :(得分:8)
反过来想一想:你可以告诉Curl点击一个IP地址,并指定Host
标题以触发所需的域。
curl example.com
curl --header "Host: example.com" 93.184.216.34
使用ab
标记的同一方法适用于-H
ab -n 10 -c 10 http://example.com/
ab -n 10 -c 10 -H "Host: example.com" http://93.184.216.34/
希望这有帮助。
修改强>
关闭@Magistar的回答,你想确保你使用正确的协议(http
vs https
)并且正在达到正确的FQD。也就是说,如果您的网站响应www.example.com
而不是example.com
(没有www
),请务必使用有效的网站。
需要注意的另一件事是确保您没有加载测试重定向。例如,针对ab
运行yahoo.com
(我不建议这样做)将不是一个好的测试,因为yahoo.com
会立即重定向到www.yahoo.com
,您可以看看你是否curl
处于详细模式:
# curl yahoo.com
redirect
# curl yahoo.com -v
* About to connect() to yahoo.com port 80 (#0)
* Trying 98.139.180.180...
* Connected to yahoo.com (98.139.180.180) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: yahoo.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 07 Mar 2018 13:46:53 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp29.prod.media.bf1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=2592000
< Location: https://www.yahoo.com/
< Content-Length: 8
<
* Connection #0 to host yahoo.com left intact
redirect
或者更具体地说,因为这是关于将主机欺骗到目标IP地址:
# curl --header "Host: yahoo.com" 98.139.180.180 -v
* About to connect() to 98.139.180.180 port 80 (#0)
* Trying 98.139.180.180...
* Connected to 98.139.180.180 (98.139.180.180) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Accept: */*
> Host: yahoo.com
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 07 Mar 2018 13:51:26 GMT
< Connection: keep-alive
< Via: http/1.1 media-router-fp82.prod.media.bf1.yahoo.com (ApacheTrafficServer [c s f ])
< Server: ATS
< Cache-Control: no-store, no-cache
< Content-Type: text/html
< Content-Language: en
< X-Frame-Options: SAMEORIGIN
< Strict-Transport-Security: max-age=2592000
< Location: https://www.yahoo.com/
< Content-Length: 8
<
* Connection #0 to host 98.139.180.180 left intact
redirect
因此,请务必首先curl
该网址,以确保其返回您期望的数据,然后继续ab
。
答案 1 :(得分:2)
对于基于SSL的网站,以防止获得0字节:
except AssertionError as err
诀窍是将子域(www)包含在主机名中。
(ps没有足够的分数将其添加为评论)。