Skip to content

Commit

Permalink
Merge pull request #4 from posit-conf-2023/load-testing
Browse files Browse the repository at this point in the history
Load testing
  • Loading branch information
rpodcast committed Sep 11, 2023
2 parents 9cebd1b + 0532be9 commit d562969
Show file tree
Hide file tree
Showing 20 changed files with 782 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile_rstudio
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
FROM ghcr.io/rocker-org/devcontainer/tidyverse:4.3

ENV QUARTO_VERSION=prerelease

# install preview version of quarto
RUN /rocker_scripts/install_quarto.sh

# key dependencies for utilities
RUN apt-get update -qq \
&& export DEBIAN_FRONTEND=noninteractive \
Expand All @@ -23,3 +28,4 @@ RUN apt-get update -qq \

# install R package dependencies
RUN install2.r renv httpgd languageserver shiny rmarkdown markdown countdown fontawesome profvis golem rsconnect devtools

2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"features": {
"ghcr.io/rocker-org/devcontainer-features/pandoc:1": {},
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {
"version": "1.3.433"
"version": "1.4.352"
},
"ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {},
"ghcr.io/guiyomh/features/vim:0": {}
Expand Down
54 changes: 54 additions & 0 deletions R/shinycannon.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' Run the shinycannon utility
#'
#' @param shinycannon_path Path to the Shinycannon JAR file.
#' @param recording_file Path to recording file
#' @param app_url URL of the Shiny application to interact with
#' @param output_dir Path to directory to store session logs in for this
#' test run
#' @param workers Number of workers to simulate. Default is 1.
#' @param loaded_duration_minutes Number of minutes to continue simulating
#' sessions in each worker after all workers have completed one session.
#' Can be fractional. Default is 5.
#' @param overwrite_output Delete the output directory before starting,
#' if it exists already. Default is TRUE.
#' @param debug_log Produce a debug.log in the output directory. File can get
#' very large. Default is FALSE.
#' @param log_level Log level. Possible values include warn, info, error,
#' debug. Default is warn.
#'
#' @return exit code from `sys::exec_wait()`
shinycannon <- function(
shinycannon_path,
recording_file,
app_url,
output_dir,
workers = 1,
loaded_duration_minutes = 5,
overwrite_output = TRUE,
debug_log = FALSE,
log_level = "warn") {

# assemble command-line arguments
cli_args <- c(
"-jar",
shinycannon_path,
recording_file,
app_url,
"--workers",
workers,
"--loaded-duration-minutes",
loaded_duration_minutes,
"--output-dir",
output_dir,
"--log-level",
log_level
)

if (debug_log) cli_args <- c(cli_args, "--debug-log")
if (overwrite_output) cli_args <- c(cli_args, "--overwrite-output")

sys::exec_wait(
cmd = "java",
args = cli_args
)
}
27 changes: 23 additions & 4 deletions R/test_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ library(sys)


# define paths and constants
app_link <- "https://rsc.training.rstudio.com/bricktest/"
app_url <- "https://rsc.training.rstudio.com/bricktest/"
recording_file <- "R/recording.log"

shinyloadtest::record_session(
app_link,
output_file = "R/recording.log",
output_file = recording_file,
connect_api_key = Sys.getenv("RSCONNECT_KEY")
)

# use the exec_wait function from sys
shinycannon_path <- "utils/shinycannon-1.1.3-dd43f6b.jar"

shinycannon(
shinycannon_path,
recording_file,
app_url,
output_dir = "R/run1"
)

# baseline run
exec_wait(
cmd = "java",
Expand All @@ -55,6 +62,18 @@ exec_wait(
)
)

df <- load_runs("Run 1" = "R/run1")

shinyloadtest_report(
df,
output = "R/report_test.html"
)

# experiment with creating single plots
dur_plot <- slt_session_duration(df)
plotly::ggplotly(dur_plot)


# comparison run (3 workers)
exec_wait(
cmd = "java",
Expand Down Expand Up @@ -104,8 +123,8 @@ shinyloadtest_report(df, "R/report1.html")
library(connectapi)

client <- connect(
server = paste0("https://", Sys.getenv("RSCONNECT_SERVER")),
api_key = Sys.getenv("RSCONNECT_KEY")
server = paste0("https://", Sys.getenv("CONNECT_SERVER")),
api_key = Sys.getenv("CONNECT_API_KEY")
)

content_df <- get_content(client)
Expand Down
12 changes: 12 additions & 0 deletions _extensions/emilhvitfeldt/codewindow/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: codewindow
author: Emil Hvitfeldt
version: 1.1.0
quarto-required: ">=1.4.0"
contributes:
revealjs-plugins:
- name: RevealCodewindow
script:
- codewindow.js
stylesheet:
- codewindow.css

48 changes: 48 additions & 0 deletions _extensions/emilhvitfeldt/codewindow/codewindow.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* TODO: CSS for plugin */

.codewindow {
overflow-wrap: anywhere;
margin-bottom: 36px;
font-size: 0.45em;
font-family: monospace;
background: white;
border-radius: 10px;
box-shadow: #26394d 0px 20px 30px -10px;
}

.codewindow .header {
display: flex;
background: #e2e8f0;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
padding-left: 16px;
gap: 16px;
height: 30px;
}

.codewindow .header .file {
margin-top: 5px;
padding-left: 20px;
padding-right: 20px;
display: flex;
background: white;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
height: 90%;
align-items: center;
gap: 4px;
}

.codewindow .textarea {
padding: 21px;
}

.codewindow .textarea .sourceCode {
background: unset;
border: unset;
font-size: unset;
}

.codewindow .textarea pre {
font-size: unset;
}
112 changes: 112 additions & 0 deletions _extensions/emilhvitfeldt/codewindow/codewindow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions _extensions/emilhvitfeldt/highlightword/_extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: highlightword
author: Emil Hvitfeldt
version: 1.0.0
quarto-required: ">=1.4.0"
contributes:
revealjs-plugins:
- name: RevealHighlightword
script:
- highlightword.js
Loading

0 comments on commit d562969

Please sign in to comment.