Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a bad way to do server load testing?

I'm working on a PHP-MySQL web app, and the available tools for server load testing are cumbersome and confusing. So I thought I'd try this, and I'd like to know if it's a bad idea:

  • Add page generation time and memory_get_usage() to the output of each page
  • Use jQuery, AJAX and setInterval to hit the page n-times a second, recording the time/memory consumption.

Here is the Javascript and markup:

<script>
function roundNumber(num, dec) {
    var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
    return result;
}

$(function(){

totalCount = 0;
i = 1;
totalTime = 0;
highest = 0;
memoryUsage = 0;

var hitsPerSecond = 1000;
var totalLimit = 100;

function testLoad(){

            
    if (totalCount <= totalLimit){
        
        $.get('/lp/user-page.php', function(data){
            $(data).filter('#page-generation-time').each(function(){
                totalTime += parseFloat($(this).text());
                $('.console').append('<p>('+i+') - Load time: '+$(this).text()+'</p>');
                            i++;
                            if (highest < $(this).text()){
                                highest = $(this).text();
                            }
                            $('.average').html('Average: '+roundNumber(totalTime/i, 5)+' - Highest: '+highest);
            });
            $(data).filter('#page-memory-usage').each(function(){
                memoryUsage = parseFloat($(this).text());
                $('.memory').html($(this).text());
            });


        });
        
        
    } else {
        clearInterval(testLoadInterval);
    }
    
    totalCount++;

};


var testLoadInterval = setInterval(function(){ testLoad(); }, 1000/hitsPerSecond);

});

</script>

<h2>Load Test</h2>
<div class="average"></div>
<div class="memory"></div>
<div class="console-container">
    <div class="console"></div>
</div>

Is this an incredibly stupid/inaccurate way to do load testing? Because it seems like it has its advantages:

  • Light-weight and easy to implement.
  • Loads the entire page using a real browser.
  • Tracks the average page load time and records the results right in the browser.

But I really don't have any frame of reference to know if the numbers I'm getting are right. Thanks to anyone who can tell me if I'm completely wrong, and if there's something slightly more user-friendly out there than jMeter.

UPDATE

Do not use this as a method of server load testing. It will not give you an accurate reading.

Using the above code, I was able to hit the server with "1,000" loads a second with very little problem. After attempting the same with ApacheBench, I've found that this was in no way a reflection of reality.

Using ApacheBench, I was able to crash the server by hitting the app with 40 (!) concurrent connections.

Obviously, I'm rewriting parts of the app to use cached HTML wherever humanly possible.

So, to answer my own question, yes, this is a bad way to do server testing.

like image 680
Carter Fort Avatar asked Nov 23 '11 15:11

Carter Fort


People also ask

What are the disadvantages of load test?

Disadvantages of Load TestingLoad test script creation requires scripting knowledge of the language supported by the tool. Incorrectly configured or scripted load test plan/script can lead to false performance issues which take a considerable amount of time and resources.

Is load testing necessary?

Load testing is important in the Software Development Lifecycle because of the following reasons: It simulates real user scenarios. It evaluates how the performance of an application can be affected by normal and peak loads. It helps save money by identifying bottlenecks and defects on time.

What is the outcome of load testing?

When done correctly, load tests reveal system errors and limitations through test results so they can be remediated. The accurate interpretation of performance test data is an incredibly critical role. Analysis results inform the tactical and strategic decisions that drive the business.

How long should you run a load test?

A good, comprehensive load test, with enough results to make statistically valid optimizations, takes some time. Ideally, you'd run all the tests in your test suite for at least 10 minutes, if not longer, and that's too long to run for every commit.


1 Answers

This isn't the worst idea, but there are a few problems with it as mentioned in the comments.

One problem you're definitely going to have is caching. Just make sure in whatever browser you're using to turn off the cache. Note: I've had some issues with the Chrome cache being turned off and Chrome still insisting on delivering cached content, so watch out for that.

Beyond caching, this isn't the most accurate way of doing things. Even though it does simulate a real browser load it's only simulating one connection. This essentially emulates one user refreshing that single page a bunch of times, not very accurate.

I'd definitely use apache bench over this just for the concurrent connections. Something like

ab -n 1000 -c 10 http://www.your_url.com/

Change those numbers around depending on your server. That example would run 1000 requests 10 at a time.

One thing you could do if you wanted to check the "accuracy" of the numbers of from your javascript benchmark is to run apache bench and get some baseline no-browser number estimates and then run your benchmark script and see how close the results are.

Another great tool is Siege. It isn't very difficult to install and is well worth if it you really want to test performance accurately. But if you're looking for something very user-friendly it might not be up your alley.

Another potential tool you could use that has a nice interface is Charles

It isn't really designed for load testing though, but it does have a feature where you can run repeat concurrent requests (similar to apache bench) and it has a pretty interface.

There are alot more options out there, but they might not be user-friendly enough for you so I won't go into much more detail

One good paid (they give you a few trial runs before charging you) option I've used in the past is LoadImpact

It's kind of pricey though if you want to do any really heavy duty testing, but it does simulate concurrent browser loads and allows you to script a "path" for the simulated users to take through your site fairly easily. If you're looking for a VERY user-friendly solution with relatively high accuracy I'd definitely recommend them (if you have the cash).

Another potential paid solution is CapCal

I don't really know much about them though. Looks like they might have some sort of free trial too.

like image 77
William King Avatar answered Sep 27 '22 17:09

William King