loadtest: Run a load test of an HTTP request

Description Usage Arguments Value Examples

View source: R/loadtest.R

Description

This is the core function of the package, which creates many HTTP requests using Apache JMeter. In this function, you specify a URL and HTTP method along with how many times to hit the URL, then the function calls JMeter to run a load test. For requests that require special headers or a body, you can specify them as well.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
loadtest(
  url,
  method = c("GET", "POST", "HEAD", "TRACE", "OPTIONS", "PUT", "DELETE"),
  headers = NULL,
  body = NULL,
  encode = c("raw", "json"),
  threads = 1,
  loops = 16,
  ramp_time = 0,
  delay_per_request = 0
)

Arguments

url

The url to hit as part of the test, such as https://www.t-mobile.com .

method

The HTTP method to use. Defaults to "GET" but other common choices are "POST", "PUT", and "DELETE".

headers

A named character vector of headers to use as part of HTTP request. The names are the keys and the vector contents are the values.

body

A list to be encoded as a json object to use as the body of the HTTP request.

encode

The method of encoding the body, if it exists.

threads

The number of threads to concurrently run in the test.

loops

The number of times each thread should hit the endpoint.

ramp_time

The time (in seconds) that it should take before all threads are firing.

delay_per_request

A delay (in milliseconds) after a thread completes before it should make its next request. Raw assumes the body is a character and preserves it. Json converts a list into json like the pacakge httr.

Value

A data.frame containing the JMeter test results of the HTTP requests made during the tests. The columns have the following specification.

request_id

An intentifier for each request. An integer from 1 to the number of requests

start_time

The time the request was started, as a POSIXct.

thread

The thread the request was made from (from 1 to n, where n is the number of threads)

threads

The number of open threads at the time the request was made. Should decrease to 1 as the requests finish.

response_code

The response code of the HTTP request, such as 200, 403, or 500. A character that should be able to be converted to an integer, but may be a string be if an error occurred.

response_message

The message of the response. May be an error if the request fails.

request_status

A factor for if the request succeeded (Success/Failure)

sent_bytes

The number of bytes sent in the request.

received_bytes

The number of bytes received in the request.

time_since_start

The number of milliseconds after the test started that the request started. Useful for plotting the time the request occurred relative to the start of the test. You will need to add other values to this (such as elapsed) to measure end times of requests.

elapsed

The number of milliseconds that elapsed between when the request started and when the response was finished being received.

latency

The number of milliseconds that elapsed between when the request started and when the response began. Thus, this does not include the time it takes to receive the request, which can matter for a large download. This is included in the elapsed time (and is at most equal to).

connect

The number of milliseconds needed to make the connection. This is included in both the elapsed and latency measures, but it may need to be removed depending on what should be measured.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# a simple GET request
results <- loadtest(url = "https://www.t-mobile.com", threads = 2, loops = 5)

# a more complex POST request
results <- loadtest(url = "http://deepmoji.teststuff.biz",
                    method = "POST",
                    headers = c("version"="v1.0"),
                    body = list(sentences = list("I love this band")),
                    encode = "json",
                    threads = 1,
                    loops = 15,
                    delay_per_request = 100)

tmobile/loadtest documentation built on April 13, 2020, 2:21 a.m.