ab负载测试 [英] ab load testing

查看:38
本文介绍了ab负载测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以引导我完成如何使用 apache bench 工具 (ab)?

Can someone please walk me through the process of how I can load test my website using apache bench tool (ab)?

我想知道以下内容:

网站每分钟可以处理多少人?

请引导我完成我应该运行的命令来解决这个问题.

Please walk me through the commands I should run to figure this out.

我尝试了所有教程,但它们令人困惑.

I tried every tutorial, and they are confusing.

推荐答案

apache 基准测试工具非常基础,虽然它会给你一些性能的可靠概念,只依赖它是一个坏主意如果您打算让您的网站在生产过程中承受严重压力.

The apache benchmark tool is very basic, and while it will give you a solid idea of some performance, it is a bad idea to only depend on it if you plan to have your site exposed to serious stress in production.

话虽如此,这里是最常见和最简单的参数:

Having said that, here's the most common and simplest parameters:

-c:(并发").表示将有多少客户(人/用户)同时访问该站点.当 ab 运行时,将会有 -c 客户端访问该站点.这实际上决定了您的网站在基准测试期间将承受的压力.

-c: ("Concurrency"). Indicates how many clients (people/users) will be hitting the site at the same time. While ab runs, there will be -c clients hitting the site. This is what actually decides the amount of stress your site will suffer during the benchmark.

-n:表示将要发出多少请求.这只是决定了基准的长度.一个高 -n 值和一个您的服务器可以支持的 -c 值是一个好主意,以确保事情不会在持续压力下崩溃:这与支持压力 5 秒而不是 5 小时.

-n: Indicates how many requests are going to be made. This just decides the length of the benchmark. A high -n value with a -c value that your server can support is a good idea to ensure that things don't break under sustained stress: it's not the same to support stress for 5 seconds than for 5 hours.

-k:这是浏览器天生的KeepAlive"功能.您不需要为 -k 传递值,因为它是布尔值"(意思是:它表明您希望您的测试使用来自 HTTP 的 Keep Alive 标头并维持连接).由于浏览器会执行此操作,并且您可能希望模拟您的网站将来自浏览器的压力和流量,因此建议您对此进行基准测试.

-k: This does the "KeepAlive" funcionality browsers do by nature. You don't need to pass a value for -k as it it "boolean" (meaning: it indicates that you desire for your test to use the Keep Alive header from HTTP and sustain the connection). Since browsers do this and you're likely to want to simulate the stress and flow that your site will have from browsers, it is recommended you do a benchmark with this.

最后一个参数就是主机.默认情况下,如果您不指定它,它将访问 http://协议.

The final argument is simply the host. By default it will hit http:// protocol if you don't specify it.

ab -k -c 350 -n 20000 example.com/

通过发出上述命令,您将使用 350 个同时连接点击 http://example.com/,直到满足 2 万个请求.它将使用保持活动标头完成.

By issuing the command above, you will be hitting http://example.com/ with 350 simultaneous connections until 20 thousand requests are met. It will be done using the keep alive header.

流程完成 2 万个请求后,您将收到有关统计信息的反馈.这将告诉您使用上述参数时网站在您施加的压力下的表现如何.

After the process finishes the 20 thousand requests, you will receive feedback on stats. This will tell you how well the site performed under the stress you put it when using the parameters above.

要了解站点可以同时处理多少人,只需查看响应时间(平均值、最小和最大响应时间、失败的请求等)是否是您的站点可以接受的数字(不同的站点可能需要不同的速度).您可以使用不同的 -c 值运行该工具,直到您说如果我增加它,它就会开始收到失败的请求并且它会中断".

For finding out how many people the site can handle at the same time, just see if the response times (means, min and max response times, failed requests, etc) are numbers your site can accept (different sites might desire different speeds). You can run the tool with different -c values until you hit the spot where you say "If I increase it, it starts to get failed requests and it breaks".

根据您的网站,您预计每分钟的平均请求数.这变化很大,你将无法用 ab 模拟它.但是,可以这样想:如果您的平均用户每分钟会点击 5 个请求,并且您认为有效的平均响应时间是 2 秒,这意味着一分钟中有 10 秒有 1 个用户会收到请求,这意味着只有1/6 的时间它会到达网站.这也意味着,如果您有 6 个用户同时使用 ab 访问站点,那么即使您的并发级别 (-c) 仅为 6,您也可能有 36 个用户在模拟中.

Depending on your website, you will expect an average number of requests per minute. This varies so much, you won't be able to simulate this with ab. However, think about it this way: If your average user will be hitting 5 requests per minute and the average response time that you find valid is 2 seconds, that means that 10 seconds out of a minute 1 user will be on requests, meaning only 1/6 of the time it will be hitting the site. This also means that if you have 6 users hitting the site with ab simultaneously, you are likely to have 36 users in simulation, even though your concurrency level (-c) is only 6.

这取决于您对使用该网站的用户的期望行为,但您可以从我希望我的用户每分钟点击 X 个请求,我认为平均响应时间为 2 秒时有效"中得到它.然后只需修改您的 -c 级别,直到您达到 2 秒的平均响应时间(但请确保最大响应时间和 stddev 仍然有效),然后看看您可以设置多大的 -c.

This depends on the behavior you expect from your users using the site, but you can get it from "I expect my user to hit X requests per minute and I consider an average response time valid if it is 2 seconds". Then just modify your -c level until you are hitting 2 seconds of average response time (but make sure the max response time and stddev is still valid) and see how big you can make -c.

我希望我解释清楚:)祝你好运

I hope I explained this clear :) Good luck

这篇关于ab负载测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆