Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?

Load Testing For API With Apache Benchmark On Windows

I just lately had the necessity to perform load testing on some endpoints that I created for a challenge on my Home windows OS. Setting this up was a part of a herculean activity as a result of most tutorials have been accomplished on an Ubuntu machine.

What’s Load Testing

Load Testing is a sort of efficiency testing that offers you perception into how your internet utility or HTTP server would react when extra demand is positioned on it.

For this text, we’ll deal with testing an HTTP server utilizing Apache Benchmark on a Home windows OS.


Putting in Apache Benchmark

The most recent model of Apache Benchmark for home windows will be put in here

Folder structure after unzipping

Transfer into the Apache24/bin listing and replica each the ab and abs executable recordsdata to your challenge listing (non-obligatory).

ab and abs exec files

Current project structure

Making a GET request to our server

Run the next command in your terminal, within the listing the place your ab and abs executable recordsdata are positioned:

./ab -c 10 -n 20 http://localhost:8080/ 
Enter fullscreen mode

Exit fullscreen mode

  • -c Concurrency
    This means the variety of a number of requests to make at a time. For this check, we’re sending 10 requests to our server concurrently on the similar time.

  • -n Request
    This means the variety of requests to carry out.

Extra of this flags and there descriptions will be discovered within the Apache Benchmark site

For this check, under is our anticipated response.

that is ApacheBench, Model 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Expertise Ltd, http://www.zeustech.web/
Licensed to The Apache Software program Basis, http://www.apache.org/

Benchmarking localhost (be affected person).....accomplished

Server Software program:
Server Hostname:        localhost
Server Port:            8080

Doc Path:          /
Doc Size:        23 bytes

Concurrency Stage:      10
Time taken for exams:   0.033 seconds
Full requests:      20
Failed requests:        0
Complete transferred:      19240 bytes
HTML transferred:       460 bytes
Requests per second:    606.58 [#/sec] (imply)
Time per request:       16.486 [ms] (imply)
Time per request:       1.649 [ms] (imply, throughout all concurrent requests)
Switch charge:          569.85 [Kbytes/sec] obtained

Connection Instances (ms)
              min  imply[+/-sd] median   max
Join:        0    0   0.4      0       1
Processing:     3   12   3.9     13      18
Ready:        2   10   4.0     10      17
Complete:          3   13   3.8     13      18

Share of the requests served inside a sure time (ms)
  50%     13
  66%     15
  75%     16
  80%     17
  90%     17
  95%     18
  98%     18
  99%     18
 100%     18 (longest request)
Enter fullscreen mode

Exit fullscreen mode

This offers an in depth perception into how our server performs when 10 concurrent requests are despatched. It reveals the period of time it takes to course of a sure share of our requests and offers in-depth evaluation of our server’s efficiency.

Making a POST request to our server utilizing Apache Benchmark

When making a POST request that requires a request physique, we have to cross the info to our benchmark request. That is accomplished by making a .txt file that ought to comprise our request physique knowledge. The file must be in the identical location as our ab and abs executable recordsdata.

For this check, I created a put up.txt file that incorporates a JSON object representing our request physique.

The request physique must be in a single line with no additional end-of-line areas.

TIP: To put knowledge in a single line on VS Code, choose the entire content material and use this command CTRL + SHIFT + J.

File containing our request body data

Proceed to run the next line of command in your terminal.

./ab -p put up.txt -T utility/json  -c 5 -n 5 http://localhost:8080/v1/product
Enter fullscreen mode

Exit fullscreen mode

  • -p Publish File
    This means the file containing knowledge to POST.

  • -t Content material Sort
    Content material-type header to make use of for POST/PUT knowledge, eg. utility/x-www-form-urlencoded. Default is textual content/plain.

To check a server that requires an authentication header with Apache benchmark, the next command can be utilized:

ab -p put up.txt -T utility/json -H 'Authorization: Token abcdbdhbuhfrhv' -c 10 -n 200 http://localhost:8080/v1/product
Enter fullscreen mode

Exit fullscreen mode

  • -H Customized header –
    This appends additional headers to the request. The argument is often within the type of a legitimate header line, containing a colon-separated field-value pair (i.e., “Settle for-Encoding: zip/zop;8bit”).

Be aware: Apache Bench solely makes use of one OS thread no matter the concurrency degree (specified by the -c flag). Subsequently, when benchmarking high-capacity servers, a single occasion of Apache Bench generally is a bottleneck. To utterly saturate the goal URL, use extra situations of Apache Bench in parallel (in case your server has a number of processor cores).

Do not forget to love, share and let me know if you happen to discovered this useful.

Add a Comment

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?