Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

apache
benchmark
http
web server

How to load test with Apache Bench

Educative Answers Team

Apache Bench (ab) is a command-line tool for load testing and benchmarking HTTP web servers. It is part of the Apache HTTP Server Project and allows you to quickly check your web server’s performance in a simple, straightforward way.

svg viewer

Installation

Apache Bench comes preinstalled with most Linux and Mac systems.
If you don’t already have it installed, you can install the apache2 utils package:
apt-get install apache2-utils

If you’re on Windows, you can download the Apache Binaries .zip file, extract it, and find the ab.exe file there.

Syntax

ab [OPTIONS ...] URL

Commonly used options include:

  • -c concurrency:
    Number of multiple requests to perform at a time. The default is one request at a time.
  • -f protocol:
    Specify SSL/TLS protocol (SSL2, SSL3, TLS1, TLS1.1, TLS1.2, or ALL). TLS1.1 and TLS1.2 support available in 2.4.4 and later.
  • -h:
    Display usage information.
  • -k:
    Enables the HTTP KeepAlive feature, i.e., can perform multiple requests within one HTTP session. Default is no KeepAlive.
  • -n requests:
    Number of requests to perform for the benchmarking session. The default is to perform a single request, which usually leads to non-representative benchmarking results.

For a complete list of available options, you can check out the official docs.

Running a simple load test

Let’s run a simple load test on https://www.google.com/:

ab -n 100 -c 10 https://www.google.com/

The above command stimulates 100 connections (-n flag) over 10 concurrent threads (-c flag).

Sample output:

This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.apache.org (be patient).....done


Server Software:        Apache/2.4.18
Server Hostname:        www.apache.org
Server Port:            443
SSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256
TLS Server Name:        www.apache.org

Document Path:          /
Document Length:        83764 bytes

Concurrency Level:      10
Time taken for tests:   25.444 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      8410800 bytes
HTML transferred:       8376400 bytes
Requests per second:    3.93 [#/sec] (mean)
Time per request:       2544.434 [ms] (mean)
Time per request:       254.443 [ms] (mean, across all concurrent requests)
Transfer rate:          322.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      560  716 338.5    593    2069
Processing:  1111 1459 399.7   1343    3121
Waiting:      185  228 139.6    196    1000
Total:       1693 2174 545.3   1945    4045

Percentage of the requests served within a certain time (ms)
  50%   1945
  66%   2198
  75%   2472
  80%   2686
  90%   3020
  95%   3297
  98%   3860
  99%   4045
 100%   4045 (longest request)

Note: Apache Bench only uses one OS thread irrespective of the concurrency level (specified by the -c flag). Therefore, when benchmarking high-capacity servers, a single instance of Apache Bench can be a bottleneck. To completely saturate the target URL, use additional instances of Apache Bench in parallel (if your server has multiple processor cores).

RELATED TAGS

apache
benchmark
http
web server
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring