h2load for REST API benchmarking

Carvia Tech | May 03, 2020 | 3 min read | 666 views

h2load is a benchmarking tool for HTTP/2 and HTTP/1 with support for SSL/TLS. h2load uses non-blocking io for making concurrent calls to target GET/POST Http endpoint, thus does not cause much load on the running system since single thread can make thousands of requests per second.



If you have homebrew installed on your mac, installing h2load is just a matter of running a single command:

$ brew install nghttp2


On ubuntu 18.04 or 20.04 LTS, you can run the below command:

$ sudo apt install nghttp2-client



the total number of requests. Default: 1


the number of concurrent clients. Default: 1


The max concurrent streams to issue per client. Default: 1


the number of native threads. Defaults: 1.


Add/Override a header to the request.


Output debug information.


displays help information.


can be used to specify protocol, by default HTTP/2 is used. Available protocols are: h2c and http/1.1, default is h2c. Alternatively, you can always use --h1 option to force HTTP/1.1 for both cleartext and SSL/TLS.

Basic load testing

HTTP GET endpoint benchmarking

below command will perform benchmark to URI http://localhost:8080/health.json using total 10000 requests, 100 concurrent clients and each client creating maxmium 10 concurrent streams.

Benchmarking HTTP/1.1 GET endpoint using h2load
h2load -n10000 -c100 -m10 --h1 "http://localhost:8080/health.json".   (1)
1 h1 flag is used to enforce HTTP/1.1 instead of default HTTP/2 which requires SSL/TLS connection.
Results will look like below:
finished in 233.18s, 0.43 req/s, 105B/s
requests: 100 total, 100 started, 100 done, 100 succeeded, 0 failed, 0 errored, 0 timeout
status codes: 100 2xx, 0 3xx, 0 4xx, 0 5xx
traffic: 23.93KB (24500) total, 15.53KB (15900) headers (space savings 0.00%), 4.20KB (4300) data
                     min         max         mean         sd        +/- sd
time for request:      9.22s      29.59s      22.60s       3.01s    72.00%
time for connect:   599.74ms    599.90ms    599.80ms        51us    70.00%
time to 1st byte:     20.26s      24.39s      23.16s       1.47s    80.00%
req/s           :       0.04        0.05        0.04        0.00    80.00%

For HTTP/2 endpoints, we do not need to supply --h1 flag, so the command will look like this:

Benchmarking HTTP/2 endpoint using h2load
h2load -n100 -c10 -m1 https://dapi.shunyafoundation.com/sidecar-pdf/health.json

HTTP POST endpoint benchmarking

For benchmarking POST endpoints, you first need to create a file containing request payload of POST request.

    "query": "convert text into entities"

Now you have the file testpayload.json, below command can run requests against POST endpoint on the server.

$ h2load -v http://host:port/v1/ner -d testpayload.json --h1 --header 'Content-Type: application/json' -n 500 -t 4 -c 4 -T 10

In the above command we have specified payload using -d flag and also, we specified custom timeout for each request to 10 seconds.

Time based load testing

h2load supports time based load-testing. Using this method will perform time based load testing in terms of a given duration instead of a pre-defined number of requests.


warms up period


duration in seconds for which benchmarking will run against the server, if supplied, -n option is ignored by h2load client.

For example, the below command will perform load-testing for 10 seconds after 5 seconds of warming up period.

h2load -c100 -m100 --duration=10 --warm-up-time=5 --h1 http://localhost:8080/health.json

Adding HTTP Headers

We can easily add HTTP headers in request using --header flag, the below example illustrates this:

h2load -n1000 -c10 -m1 --header="accept-encoding: gzip" https://localhost:443/health.json

Request Timeout Headers

We can set connection timeout in seconds using available flags --connection-active-timeout and --connection-inactivity-timeout

h2load -t2 -n10 -c10 -m1 --connection-active-timeout=3 --connection-inactivity-timeout=3 https://www.google.com/

When no timeout value is set (either active or inactive), h2load will keep a connection open indefinitely, waiting for a response.

Top articles in this category:
  1. Rest Assured API Testing Interview Questions
  2. 50 SDET Java Interview Questions & Answers
  3. SDET: JUnit interview questions for automation engineer
  4. Junit 5 Platform Launcher API
  5. RestAssured multipart file upload
  6. SDET Java Coding Challenges
  7. Http methods for RESTful services

Find more on this topic:
SDET Interviews image
SDET Interviews

SDET Java Interview pattern and collection of questions covering SDET coding challenges, automation testing concepts, functional, api, integration, performance and security testing, junit5, testng, jmeter, selenium and rest assured

Last updated 1 week ago

Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info