简体   繁体   English

测试对基于 REST 的 Web 服务器的并发请求

[英]Test concurrent requests to a REST based web server

如何向基于 REST 的 Web 服务器模拟数以千计的 GET 和 PUT 请求?是否有可用的工具?如果有,有哪些可用的工具?

ab - Apache HTTP server benchmarking tool http://httpd.apache.org/docs/2.0/programs/ab.html ab - Apache HTTP 服务器基准测试工具http://httpd.apache.org/docs/2.0/programs/ab.html

This is a great tool for testing REST APIs.这是测试 REST API 的绝佳工具。

Example:例子:

ab -c 100 -n 100 http://service/path/to/resource

In this example:在这个例子中:

  • "-c 100" means 100 concurrent requests and “-c 100”表示 100 个并发请求和
  • "-n 100" means 100 requests “-n 100”表示100个请求

I know its an old question however I needed a simple AJAX based Script to Test Multiple Concurrent Connections.我知道这是一个老问题,但是我需要一个简单的基于 AJAX 的脚本来测试多个并发连接。 If any of you have similar requirements then you can also use like this one for your tests.如果你们中的任何人有类似的要求,那么你也可以像这样使用你的测试。

模拟多个 Ajax 请求的 JS 代码快照

Please take a look the this js fiddle link or See attached (whichever suits you as both points to the same javascript code)请查看此 js 小提琴链接或参见附件(以适合您的方式为准,因为两者都指向相同的 javascript 代码)

 var interval; var queue = []; var globalElapsedTime; function getUrl() { return $.trim($("#txtAjayUrl").val()); } $("#btnLaunchRequests").on("click", function () { queue = []; $("#divTimeElapsed").html("<i>calculating</i>"); globalElapsedTime = window.performance.now(); $("#divRequestStatus").show(); $("#btnLaunchRequests").prop("disabled", true); var totalRequests = 50; var inputValue = $("#txtNumberOfConcurrentRequests").val(); totalRequests = inputValue.trim(); $("#divTotalNumberOfProcessed").html(totalRequests.toString()); if (interval != null && interval != undefined) { clearInterval(interval); } interval = window.setInterval(function () { $("#divNumberOfCurrentRequests").text(queue.length); }, 500); for (let i = 1; i <= totalRequests; i++) { console.log("Loop No. " + i); if (i == totalRequests) { $.get(getUrl(), function (data) { queue.push("1"); $("#btnLaunchRequests").prop("disabled", false); $("#divNumberOfCurrentRequests").text(queue.length); //clearInterval(interval); }).always(function () { $("#btnLaunchRequests").prop("disabled", false); globalElapsedTime = window.performance.now() - globalElapsedTime; globalElapsedTime = Math.round((globalElapsedTime / 1000) * 100) / 100; console.log("%cLast Result Processed in " + globalElapsedTime + " Seconds.", "color:green"); $("#divTimeElapsed").text(globalElapsedTime + " seconds"); }); } else { $.get(getUrl(), function (data) { queue.push("1"); }); } } });
 <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script> <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <div class="container"> <div class="row" style="padding-top:50px;"> <div class="col-sm-12"> <h3>HTTP GET Concurrent Requests Tester</h3> </div> </div> <div class="row"> <div class="col-sm-12"> <ul> <li>Sample Ajax URL for concurrent request testing: <input type="text" id="txtAjayUrl" value="http://localhost:4500/Api/Home/GetCustomerDetails/36603/Test" style="width:100%"> <br><br> </li> <li><input type="number" value="50" id="txtNumberOfConcurrentRequests"> <input type="button" value="Launch Concurrent Requests" id="btnLaunchRequests"> <br></li> </ul> </div> </div> <div class="row" id="divRequestStatus" style=""> <div class="col-sm-12"> <table class="table table-bordered"> <thead> <tr> <th> Total Number of Requests </th> <th> Total Number of Requests Processed </th> <th> Total Time Elapsed </th> </tr> </thead> <tbody> <tr> <td> <div id="divTotalNumberOfProcessed"></div> </td> <td> <div id="divNumberOfCurrentRequests" style="font-weight: bolder;"></div> </td> <td> <div id="divTimeElapsed"></div> </td> </tr> </tbody> </table> </div> </div> </div>

几乎任何 HTTP 性能测试工具,无论是商业的还是开源的,都可用于对 REST 接口进行性能测试。

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

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