Skip to content

shell: enable visualization for performance testing #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules/
/playwright/.cache/
/logs*
.env*
/reports*
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@ The process will take some time, and the logs are updated live at `./logs`.

Your machine might struggle with the default artillery configuration, but it should still reveal performance differences between the tests. Adjust the configuration as needed by learning from [artillery.io options](https://www.artillery.io/docs).

### Visualizing Results

After running the monitoring script, you get several outputs to analyze the benchmark results:

1. **Log Files**: Plain text logs are generated in the `./logs/<log-context>-<app>-<script>.log` directory.

2. **JSON Reports**: Performance data is saved as JSON in `./reports/<log-context>-<app>-<script>.json`.

3. **HTML Reports**: Interactive visual reports are automatically generated at `./reports/<log-context>-<app>-<script>.html`. These reports include:
- Visual graphs of response times
- Request rates
- HTTP codes
- Latency distributions
- Other Artillery metrics

<img src="./assets/local-html.png" alt="HTML Report Example" width="800">

To view the HTML report, simply open it in any web browser:

```shell
open ./reports/<log-context>-<app>-<script>.html
```

4. **Artillery Cloud Integration**: If you provide an Artillery Cloud API key as a fourth parameter, results are also sent to Artillery's cloud dashboard:

```shell
./scripts/monitor.sh <app> <artillery-script> <log-context> <artillery-key>
```

Artillery Cloud offers a free tier that allows you to compare multiple test executions side by side, making it easier to track performance changes over time or between different Meteor versions.

<img src="./assets/cloud-artillery-compare.png" alt="Artillery Cloud Comparison" width="800">

These visualization options make it easier to identify performance bottlenecks and compare different Meteor versions.

You can analyze performance using a Meteor checkout. This allows you to quickly measure the impact of ongoing changes and ensure consistent or improved performance.

```shell
Expand Down
Binary file added assets/cloud-artillery-compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/local-html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 40 additions & 3 deletions scripts/monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
app="${1}"
script="${2}"
logName="${3:-''}"
artilleryKey="${4:-''}"

if [[ -z "$app" ]] || [[ -z "$script" ]]; then
echo "Usage: monitor.sh <app_name> <script_name>"
echo "Usage: monitor.sh <app_name> <script_name> [log_name] [artillery_key]"
echo " artillery_key: Optional - Your Artillery Cloud API key to send results to Artillery Cloud"
exit 1;
fi

# Determine if we should use Artillery Cloud
useCloud="false"
if [[ -n "${artilleryKey}" ]]; then
useCloud="true"
echo "Artillery Cloud key provided - results will be sent to Artillery Cloud"
fi

# Redirect stdout (1) and stderr (2) to a file
logFile="logs/${logName}-${app}-${script}.log"
mkdir -p logs
Expand All @@ -21,6 +31,12 @@ baseDir="${PWD}"
appsDir="${baseDir}/apps"
appPath="${appsDir}/${app}"
appPort=3000
reportDir="${baseDir}/reports"
jsonReport="${reportDir}/${logName}-${app}-${script}.json"
htmlReport="${reportDir}/${logName}-${app}-${script}.html"

# Create reports directory if it doesn't exist
mkdir -p "${reportDir}"

# Define color codes
RED='\033[0;31m'
Expand Down Expand Up @@ -82,7 +98,7 @@ function logScriptConfig() {
echo -e "==============================="
echo -e " Artillery Configuration - $(date) "
echo -e "==============================="
cat "${baseDir}/artillery/${script}"
cat "${baseDir}/artillery/${script}.yml"
echo -e "==============================="
}

Expand Down Expand Up @@ -127,6 +143,16 @@ function cleanup() {
else
echo -e "${GREEN}Output is suitable for comparisons (${logFile})${NC}"
echo -e "${GREEN} Your machine managed the configuration correctly.${NC}"

if [[ -f "${htmlReport}" ]]; then
echo -e "${GREEN}HTML report was generated successfully at: ${htmlReport}${NC}"
else
echo -e "${RED}Warning: HTML report was not generated${NC}"
fi

if [[ "${useCloud}" == "true" ]]; then
echo -e "${GREEN}Results were sent to Artillery Cloud. Check your dashboard at https://artillery.io/cloud${NC}"
fi

exit 0
fi
Expand Down Expand Up @@ -164,7 +190,13 @@ echo "APP PID: ${appPid}"
echo "DB PID: ${dbPid}"

# Run artillery script
npx artillery run "${baseDir}/artillery/${script}" &
if [[ "${useCloud}" == "true" ]]; then
echo "Running Artillery with Cloud integration..."
npx artillery run "${baseDir}/artillery/${script}.yml" --record --key "${artilleryKey}" --output "${jsonReport}" &
else
echo "Running Artillery locally..."
npx artillery run "${baseDir}/artillery/${script}.yml" --output "${jsonReport}" &
fi
artPid="$!"

# Run CPU and RAM monitoring for meteor app and db
Expand All @@ -180,4 +212,9 @@ echo "Monitor CpuRam DB Pid ${cpuRamDbPid}"
# Wait for artillery script to finish the process
wait "${artPid}"

# Generate HTML report
echo "Generating HTML report..."
npx artillery report "${jsonReport}" --output "${htmlReport}"
echo "HTML report generated at: ${htmlReport}"

cleanup "true"