From cb4125e130a00d12cd51ffe43ee3961ad2eb711c Mon Sep 17 00:00:00 2001 From: Bruno Tremblay Date: Tue, 5 May 2020 21:56:38 -0400 Subject: [PATCH 1/2] add a warmup parameter --- R/loadtest.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/R/loadtest.R b/R/loadtest.R index fc35061..51e25d2 100644 --- a/R/loadtest.R +++ b/R/loadtest.R @@ -136,6 +136,7 @@ parse_url <- function(url){ #' @param loops The number of times each thread should hit the endpoint. #' @param ramp_time The time (in seconds) that it should take before all threads are firing. #' @param delay_per_request A delay (in milliseconds) after a thread completes before it should make its next request. +#' @param warmup The number of times each thread should hit the endpoint before capturing the output. #' Raw assumes the body is a character and preserves it. #' Json converts a list into json like the pacakge httr. @@ -185,7 +186,8 @@ loadtest <- function(url, threads = 1, loops = 16, ramp_time = 0, - delay_per_request = 0){ + delay_per_request = 0, + warmup = 2){ invisible(check_java_installed()) invisible(check_jmeter_installed()) @@ -254,6 +256,9 @@ loadtest <- function(url, # where to save the results save_location <- tempfile(fileext = ".csv") + # include warmup + loops <- loops + min(0, warmup) + # the full test specification jmx_spec <- glue::glue(template) @@ -288,9 +293,19 @@ loadtest <- function(url, names(output) <- c("start_time", "elapsed", "response_code","response_message", "thread", "request_status", "received_bytes", "sent_bytes", "threads", "latency", "idle", "connect") + #remove warmups + output[["thread"]] <- as.integer(gsub("^Thread Group 1-", "", output[["thread"]])) + if (warmup > 0) { + warmups <- do.call(c, + lapply( + unique(output[["thread"]]), + function(x) { + which(output[["thread"]] == x)[seq_len(warmup)] + })) + output <- output[-warmups,] + } output[["start_time"]] <- as.POSIXct(output[["start_time"]]/1000, origin="1970-01-01") output[["time_since_start"]] <- round(as.numeric(output[["start_time"]]-min(output[["start_time"]]))*1000) - output[["thread"]] <- as.integer(gsub("^Thread Group 1-", "", output[["thread"]])) output[["request_id"]] <- 1:nrow(output) output[["request_status"]] <- factor(ifelse(output[["request_status"]],"Success","Failure"),c("Failure","Success")) output <- output[,c("request_id", "start_time", "thread", "threads", "response_code", "response_message", From c50998ea4dde3ecd5032209e12bc36d84f0a48a0 Mon Sep 17 00:00:00 2001 From: Bruno Tremblay Date: Wed, 6 May 2020 12:46:39 -0400 Subject: [PATCH 2/2] up is down down is up --- R/loadtest.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/loadtest.R b/R/loadtest.R index 51e25d2..6d8c91b 100644 --- a/R/loadtest.R +++ b/R/loadtest.R @@ -257,7 +257,7 @@ loadtest <- function(url, save_location <- tempfile(fileext = ".csv") # include warmup - loops <- loops + min(0, warmup) + loops <- loops + max(0, warmup) # the full test specification jmx_spec <- glue::glue(template)