Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test concurrent requests to a REST based web server

How can I simulate thousands of GET and PUT requests to my REST based web server?Are there any tools available and if yes what are the tools available?

like image 420
Naveen Mohan Avatar asked Jun 08 '12 15:06

Naveen Mohan


People also ask

How can I check my server concurrency?

To test for problems with concurrent access to the same database record, you need to write specific scripts that synchronize two clients to make requests of the same records in your server's databases at the same time. Your goal is to encounter faulty read/write locks, software deadlocks, or other concurrency problems.

How many concurrent requests can a Web server handle?

With a single CPU core, a web server can handle around 250 concurrent requests at one time, so with 2 CPU cores, your server can handle 500 visitors at the same time. Getting the balance right between performance and cost is crucial as your site grows in popularity.


3 Answers

ab - Apache HTTP server benchmarking tool http://httpd.apache.org/docs/2.0/programs/ab.html

This is a great tool for testing REST APIs.

Example:

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

In this example:

  • "-c 100" means 100 concurrent requests and
  • "-n 100" means 100 requests
like image 156
ioseb Avatar answered Oct 20 '22 18:10

ioseb


I know its an old question however I needed a simple AJAX based Script to Test Multiple Concurrent Connections. If any of you have similar requirements then you can also use like this one for your tests.

Snapshot of JS Code simulating Multiple Ajax Requests

Please take a look the this js fiddle link or See attached (whichever suits you as both points to the same javascript code)

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>
like image 40
vibs2006 Avatar answered Oct 20 '22 17:10

vibs2006


Try jmeter, there is a third party REST plugin: http://smartrics.blogspot.co.uk/2009/04/jmeter-to-test-robustness-of-system.html

like image 2
artbristol Avatar answered Oct 20 '22 18:10

artbristol