简体   繁体   English

如何在 NGINX 后面对 NodeJS API 进行压力测试?

[英]How to stress test NodeJS API behind NGINX?

I have an API on a remote server that I need to stress test.我在需要压力测试的远程服务器上有一个 API。 It is sitting behind a NGINX reverse proxy that does 301 to the API app running behind it.它位于 NGINX 反向代理后面,该反向代理对运行在它后面的 API 应用程序执行 301。

Normal requests / Postman all work fine and I get 200s back.正常请求 / Postman 一切正常,我得到了 200 秒。 As soon as I use something like AutoCannon I get 3xx instead of 200s and the requests never hit the actual nodejs app.一旦我使用 AutoCannon 之类的东西,我就会得到 3xx 而不是 200s,并且请求永远不会到达实际的 nodejs 应用程序。

Is there some special configuration I need to do on NGINX to allow stress tests to occur?是否需要在 NGINX 上进行一些特殊配置才能进行压力测试?

Given you're sending the same request you should get the same response so double check the URL, request body, request headers and so on.鉴于您发送相同的请求,您应该得到相同的响应,因此请仔细检查 URL、请求正文、请求标头等。 Compare the requests originating from Postman and AutoCannon using an external sniffer tool like Fiddler or Wireshark , identify the differences and amend AutoCannon configuration so it would send exactly the same request like Postman does.使用FiddlerWireshark等外部嗅探器工具比较来自 Postman 和 AutoCannon 的请求,找出差异并修改 AutoCannon 配置,使其发送与 Postman 完全相同的请求。

You might want to switch to other load testing tool like Apache JMeter which comes with HTTP(S) Test Script Recorder so you will be able to record the request from your browser (or other application like Postman) so you won't have to guess what's wrong with your AutoCannor setup.您可能希望切换到其他负载测试工具,例如Apache JMeter ,它带有HTTP(S) 测试脚本记录器,这样您就可以记录来自浏览器(或 Postman 等其他应用程序)的请求,这样您就不必猜测了您的 AutoCannor 设置有什么问题。 There is also JMeter Chrome Extension so if you can access your API via browser you will be able to record JMeter script without having to worry about proxies and certificates.还有JMeter Chrome 扩展,因此如果您可以通过浏览器访问 API,您将能够记录 JMeter 脚本,而无需担心代理和证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM