测量 Web 应用程序性能(压力测试)和带宽要求

发布于 2024-10-19 00:01:21 字数 1539 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洛阳烟雨空心柳 2024-10-26 00:01:21

好吧,问题是你想如何分析?您想模拟现实世界的活动吗?或者你只是想轰炸该网站?

对单个页面进行负载测试

我认为使用 Apache Bench (<代码>ab)。它使用起来非常简单,并且会给您的应用程序带来很大的压力。我的典型用法是:

ab -c 10 -n 1000 http://www.example.com/path/to/page

-c 参数是同时发出的请求数。我建议从低水平开始(比如 5 到 10),然后逐步提高。观察失败的请求和下降的响应率的输出。大多数 Linux 机器上的连接数都被限制在 1000 个左右,所以不要太疯狂。

-n 参数是发出多少个请求。我建议至少执行 100 倍的并发请求数以获得良好的平均值...

apache bench 的另一个重要用途是对单个数据库查询进行基准测试。只需创建一个运行查询的简单脚本,然后加载即可。这可能是一个非常好的方法来检测快速但昂贵的查询,这些查询会使您的服务器在生产中停机,但在测试中看起来很好。

对整个应用程序进行负载测试

我在 WebLoad 方面运气不错。如果您没有足够的预算,可以使用开源版本来入门。但我建议使用专业版。有了它,您可以设置一个分布式测试环境(就像在办公室的每台机器上安装客户端一样简单,像为其启动一堆虚拟机一样复杂)。

最酷的是,您可以用 JavaScript 对其进行编程。因此,您可以告诉它在网站上采用随机点击路径,并具有随机延迟。这应该比您手动模拟用户更好。然后,一旦设置完毕,将测试推送到分布式引擎并点击开始。

它支持许多不同的负载配置文件(在测试期间逐渐增加负载的阶梯式等)。因此,您可以模拟斜线效果配置文件、正常的日常使用情况等。

它生成的报告非常有用。它会向您显示慢速网址、瓶颈所在等。

还有很多其他测试平台和系统。这只是我当时觉得效果很好的一个(我大约两三年前做过比较)。我与该公司没有任何关系。

对应用程序的部分进行负载测试

这是一种非常有用的技术,称为分析。操作方法和工具相当特定于语言,因此我不会在这里讨论太多细节(因为您的问题没有语言标签)。但重点是,一旦发现缓慢的页面,您就需要对其进行分析以找出导致其变慢的原因。然后修复最容易实现的目标(最慢的部分)。然后重新测试,看看您是否有所作为...

结论

由于模拟现实世界的负载几乎是不可能的,因此这实际上更像是一门艺术而不是一门科学。尽情享受吧,玩得开心。不过,不要认真对待结果,即使进行了最好的测试,您也可能会错过一些东西......所以我不会将它们视为福音并告诉首席执行官您进行了测试它能够支持 10 万个并发用户。因为当它崩溃的那一天发生时(如果你幸运的话它会崩溃),他会责怪你,因为你告诉他这会起作用......

Well, the question is how do you want to profile? Do you want to simulate real-world activity? Or do you just want to bombard the heck out of the site?

Load Testing Individual Pages

I don't think you can go wrong with using Apache Bench (ab). It's dirt simple to use, and can really stress your application. My typical usage is:

ab -c 10 -n 1000 http://www.example.com/path/to/page

The -c parameter is the number of simultaneous requests to issue. I would suggest starting low (like 5 to 10) and working your way up. Watch the output for failed requests and falling response rate. You're limited to about 1000 connections on most linux machines, so don't go too crazy.

The -n parameter is how many requests to issue. I would suggest doing at least 100 times the number of concurent requests to get a good average...

Another great use for apache bench is to benchmark individual database queries. Just create a simple script that runs the query, and load away. This can be a really good way to detect fast but expensive queries that will take your server down in production yet seem fine in testing.

Load Testing The Whole Application

I've had good luck with WebLoad. There's an Open Source version if you don't have a good budget that will get you started. But I'd suggest springing for the pro version. With it, you can setup a distributed test environment (as simple as installing the client on every machine in the office, as complex as spinning up a bunch of VMs for it).

The cool thing, is that you can program it in javascript. So you can tell it to take random click paths through the site with random delays. This should simulate a user far better than you could do manually. Then, once you have it setup, push the tests to the distributed engine and hit go.

It supports many different load profiles (stair-step where it adds load little by little for the duration of the test, etc). So you can simulate a slashdot-effect profile, normal day-to-day usage, etc.

The reports it generates are immensely useful. It shows you the slow urls, where the bottlenecks are, etc.

There are plenty of other test platforms and systems out there. This was just one that I found that I felt worked pretty well at the time (I did a comparison about 2 to 3 years ago). I am not affiliated with the company in any way.

Load Testing parts of the application

This is a really useful technique called profiling. The how to and tools are fairly language specific, so I won't go into too much detail here (since you don't have a language tag on your question). But the point is that once you find a slow page, you'll need to profile it to figure out what's slowing it down. Then fix the low hanging fruit (the parts that are the slowest). Then re-test to see if you made a difference or not...

Conclusion

Since it's almost impossible to simulate real-world load, this is really more of an art than a science. Have at it, and have fun. Don't take the results to seriously though, even with the best testing, you're likely to miss something... So I wouldn't take them as gospel and go telling the CEO that you tested that it's capable of 100k concurent users. Since when the day it crashes happens (and if you are lucky it will crash), he will blame you since you told him it would work...

梦情居士 2024-10-26 00:01:21

试想一下,你说只有 IE,那么它托管在 IIS 上吗?如果是这样,那么您可能需要查看 Microsft 的 WCAT(Web 容量分析工具),此处提供更多信息:

http ://support.microsoft.com/kb/231282

虽然它不是开源的,但它是免费的 - 您需要源代码吗?

Just a thought, you say IE only so is it hosted on IIS? if so then you might want to look at Microsft's WCAT (Web Capacity Analysis Tool), more information is available here:

http://support.microsoft.com/kb/231282

Although it isn't open source but it is free - do you need the source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文