如何对 node.js 服务器进行负载测试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12221128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:15:08  来源:igfitidea点击:

How to do load testing of node.js server?

node.jsloadstress-testing

提问by Shekhar

I want to write one web application with node.js and MongoDB and I have got task to even test it. I would like to know if there are any tools like JMeter or anything else for load/stress testing of Node.js?

我想用 node.js 和 MongoDB 编写一个 Web 应用程序,我什至有任务来测试它。我想知道是否有像 JMeter 这样的工具或其他任何用于 Node.js 负载/压力测试的工具?

EDIT

编辑

My application is going to be information extraction kind of application and client expects extraction should not take more than 10 seconds for one document. Currently I have same application written in C# but its not scaling upto client's expectations. Then I came across this beautiful and fast Node.js. I think Node.js can help me alot.

我的应用程序将是信息提取类应用程序,客户希望提取一个文档的时间不应超过 10 秒。目前我有用 C# 编写的相同应用程序,但它没有达到客户的期望。然后我遇到了这个漂亮而快速的 Node.js。我认为 Node.js 可以帮到我很多。

Please enlighten !!!

请赐教!!!

采纳答案by laktak

Try nodeload: it's a collection of node.js modules for load testing HTTP services.

尝试nodeload:它是用于负载测试 HTTP 服务的 node.js 模块的集合。

As a developer, you should be able to write load tests and get informative reports without having to learn another framework. You should be able to build by example and selectively use the parts of a tool that fit your task. Being a library means that you can use as much or as little of nodeload as makes sense, and you can create load tests with the power of a full programming language. For example, if you need to execute some function at a given rate, just use the 'nodeload/loop' module, and write the rest yourself

作为开发人员,您应该能够编写负载测试并获得信息丰富的报告,而无需学习其他框架。您应该能够通过示例构建并有选择地使用适合您任务的工具部分。作为一个库意味着您可以尽可能多地或尽可能少地使用 nodeload,并且您可以使用完整编程语言的强大功能创建负载测试。例如,如果您需要以给定的速率执行某个函数,只需使用“nodeload/loop”模块,其余部分自己编写

Just found out that this package is no longer under development so here are some active forks:

刚刚发现这个包不再开发,所以这里有一些活跃的分支:

回答by anthonygore

Why couldn't you test a node server with JMeter? For most load tests it doesn't matter what language your server is, you're just hitting it with a bunch of requests.

为什么不能用 JMeter 测试节点服务器?对于大多数负载测试来说,你的服务器是什么语言并不重要,你只是用一堆请求来击中它。

In any case, you could try loadtestwhich is implement in node.

在任何情况下,您都可以尝试在node.js中实现的loadtest

Runs a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.

对选定的 HTTP 或 WebSockets URL 运行负载测试。API 允许轻松集成到您自己的测试中。

Edit:

编辑:

This answer provides more options:

此答案提供了更多选项:

NodeJs stress testing tools/methods [closed]

NodeJs 压力测试工具/方法 [关闭]

回答by ns16

Try artillery. Here are its features, the description of which is taken from the documentation:

试试大炮。以下是它的功能,其描述取自文档:

  • Multiple protocols: Load test HTTP, WebSocket, Socket.io, Kinesis, HLS and more.
  • Scenarios: Support for complex scenarios to test multi-step interactions in your API or web app (great for ecommerce, transactional APIs, game servers etc).
  • Load testing & Functional testing: reuse the same scenario definitions to run performance tests or functional tests on your API or backend.
  • Performance metrics: get detailed performance metrics (latency, requests per second, concurrency, throughput).
  • Scriptable: write custom logic in JS, using any of the thousands of useful npm modules.
  • Integrations: statsd support out of the box for real-time reporting (integrate with Datadog, Librato, InfluxDB etc).
  • Extensible: write custom reporters, custom plugins, custom protocol engines etc.
  • and more! HTML reports, nice CLI, parameterization with CSV files.
  • 多种协议:负载测试 HTTP、WebSocket、Socket.io、Kinesis、HLS 等。
  • 场景:支持复杂场景以测试 API 或 Web 应用程序中的多步骤交互(非常适合电子商务、交易 API、游戏服务器等)。
  • 负载测试和功能测试:重用相同的场景定义在您的 API 或后端运行性能测试或功能测试。
  • 性能指标:获取详细的性能指标(延迟、每秒请求数、并发性、吞吐量)。
  • 可编写脚本:使用数千个有用的 npm 模块中的任何一个,在 JS 中编写自定义逻辑。
  • 集成:statsd 支持开箱即用的实时报告(与 Datadog、Librato、InfluxDB 等集成)。
  • 可扩展:编写自定义报告器、自定义插件、自定义协议引擎等。
  • 和更多!HTML 报告、漂亮的 CLI、使用 CSV 文件进行参数化。