Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue while doing Unit Testing for Code Performance

I was testing my code to check how it will behave if we think that 100 users submitted their registration all at once !!!

My code is in PHP Laravel 5.2 and JQuery Ajax is below.

for (i = 0; i < 100; i++) {
    var 
     data={'Role' : "Role"+i},
     request = $.ajax({
        url:                'http://localhost:1234/Practise/public/api/SaveRoleApi',
        type:               "POST",
        data:               JSON.stringify(data),
        contentType:        "application/json; charset=utf-8",
        async:  true,
        success: function(d){ console.log(d); }
     });
}

Out of 100, I am not successful in submitting more then 88 records.

I am using MySQL Database.

if my above code will add records sequentially...id there any way to test 1000 concurrent requests from one computer?

like image 208
Pankaj Avatar asked Sep 01 '16 19:09

Pankaj


2 Answers

Attempting multiple requests from one browser using JavaScript to create all the connections is not a good idea, you are indeed not testing concurrency very well.

Consider using an actual load testing tool like JMeter (I definitely recommend this), or at least parallel curl requests in a batch script.

for n in {1..1000}; do
    for i in `eval echo {$n..$((n+999))}`; do
            echo "club $i..."
            curl -X POST -H "Content-Type: application/json" -d '{"param1":"xyz","param2":"xyz"}' -s "http://localhost:1234/Practise/public/api/SaveRoleApi" >> log.txt
    done &
    wait
done
like image 104
Nestor Mata Cuthbert Avatar answered Oct 13 '22 19:10

Nestor Mata Cuthbert


I would propose to use a tool specific for this purpose like loader. Keep in mind that your web app should be accessible from the outer world.

like image 35
geoandri Avatar answered Oct 13 '22 21:10

geoandri