Skip to content

Conversation

@mtrezza
Copy link
Member

@mtrezza mtrezza commented Nov 9, 2025

Pull Request

Issue

Using mongodb-runner to simulate the DB, there is currently an insignificant network delay.

Approach

For more realistic results, add simulated DB delay to performance benchmarks.

Summary by CodeRabbit

  • Chores
    • Enhanced internal performance benchmarking infrastructure with simulated database latency for more accurate performance measurements.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Nov 9, 2025

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Nov 9, 2025

📝 Walkthrough

Walkthrough

The performance CI workflow is updated to integrate Toxiproxy for simulating 10ms database latency during benchmarks. Setup and restart steps are added for baseline and PR runs respectively, MONGODB_URI environment variable is introduced pointing to the proxied MongoDB instance, and benchmark messages are updated to document the latency simulation.

Changes

Cohort / File(s) Summary
CI Performance Workflow Configuration
\.github/workflows/ci-performance\.yml
Adds Toxiproxy baseline setup step to install and run Toxiproxy with 10ms MongoDB latency on port 27018; adds Toxiproxy restart step for PR benchmarks; introduces MONGODB_URI environment variable for baseline and PR benchmark runs; updates benchmark run messages and comment generation to reflect 10ms simulated latency

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify Toxiproxy installation and port configuration (27018) are correct
  • Confirm MONGODB_URI environment variable is properly propagated to both baseline and PR benchmark runs
  • Validate that 10ms latency value is consistent across setup, restart, and messaging steps
  • Check comment generation includes latency disclaimer accurately

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete with 'Closes: FILL_THIS_OUT' placeholder unfilled and Tasks section left entirely blank, missing required issue link and implementation checklist details. Fill in the 'Closes' field with the relevant issue number and complete the Tasks checklist to indicate which items apply and their status.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'ci: Add simulated DB delay to performance benchmarks' directly and clearly summarizes the main change—adding simulated database latency to CI performance benchmarks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@parseplatformorg
Copy link
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
.github/workflows/ci-performance.yml (1)

343-343: Document latency simulation as a breaking change for benchmark interpretation.

The PR comment now documents 10ms latency. However, this represents a significant change in how benchmarks are measured. Existing baseline numbers from before this change are not directly comparable.

Consider adding a note in the PR description or documentation about:

  • Why 10ms latency was chosen
  • How this affects interpretation of performance metrics
  • Whether historical baseline numbers need to be re-established

Would you like me to suggest documentation updates for the benchmark README or CONTRIBUTING guide to explain the latency simulation and its implications?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d94f348 and 1fd1cef.

📒 Files selected for processing (1)
  • .github/workflows/ci-performance.yml (3 hunks)
🔇 Additional comments (1)
.github/workflows/ci-performance.yml (1)

90-90: Verify MongoDB connection pool handles proxy latency correctly.

The benchmark now runs against a proxied MongoDB with 10ms added latency. Ensure that the benchmark connection pool configuration (idle timeout, max connections, etc.) doesn't cause resource exhaustion or false timeouts due to the added latency.

Please verify:

  1. That the benchmark script's MongoDB connection pool is configured appropriately for network latency
  2. That no connection timeouts occur due to the added 10ms latency
  3. That the results are reproducible across runs

Also applies to: 170-170

Comment on lines +68 to +85
- name: Setup Toxiproxy for latency simulation (baseline)
run: |
# Download and install toxiproxy
wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
sudo dpkg -i toxiproxy.deb
# Start toxiproxy server in background
toxiproxy-server &
sleep 2
# Create a proxy for MongoDB (27017 -> 27018)
toxiproxy-cli create mongodb -l localhost:27018 -u localhost:27017
# Add 10ms latency to simulate network conditions
toxiproxy-cli toxic add mongodb -t latency -a latency=10
echo "Toxiproxy setup complete - MongoDB accessible on port 27018 with 10ms latency"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add error handling and health checks to Toxiproxy setup.

The Toxiproxy setup lacks error handling and health checks. If the download fails, the dpkg command fails, or the server doesn't start properly, the workflow continues silently and benchmarks run against an unavailable proxy, producing invalid results.

Additionally, the 2-second sleep after starting the server is arbitrary and may not be sufficient for the proxy to be ready in all CI conditions.

Apply this diff to add error handling and health checks:

      - name: Setup Toxiproxy for latency simulation (baseline)
        run: |
+         set -e
+         trap 'echo "Toxiproxy setup failed"; exit 1' ERR
+
          # Download and install toxiproxy
          wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
          sudo dpkg -i toxiproxy.deb
 
          # Start toxiproxy server in background
          toxiproxy-server &
-         sleep 2
+         sleep 3
+         
+         # Wait for toxiproxy to be ready (health check)
+         for i in {1..10}; do
+           if nc -z localhost 8474 2>/dev/null; then
+             echo "Toxiproxy server is ready"
+             break
+           fi
+           echo "Waiting for Toxiproxy server... ($i/10)"
+           sleep 1
+         done
 
          # Create a proxy for MongoDB (27017 -> 27018)
          toxiproxy-cli create mongodb -l localhost:27018 -u localhost:27017
+         if [ $? -ne 0 ]; then
+           echo "Failed to create MongoDB proxy"
+           exit 1
+         fi
 
          # Add 10ms latency to simulate network conditions
          toxiproxy-cli toxic add mongodb -t latency -a latency=10
+         if [ $? -ne 0 ]; then
+           echo "Failed to add latency toxic"
+           exit 1
+         fi
 
+         # Verify the proxy is working
+         if nc -z localhost 27018 2>/dev/null; then
+           echo "Toxiproxy setup complete - MongoDB accessible on port 27018 with 10ms latency"
+         else
+           echo "Toxiproxy proxy is not accessible on port 27018"
+           exit 1
+         fi
-         echo "Toxiproxy setup complete - MongoDB accessible on port 27018 with 10ms latency"

Note: This assumes netcat (nc) is available; you may need to install it or use an alternative connectivity test.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Setup Toxiproxy for latency simulation (baseline)
run: |
# Download and install toxiproxy
wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
sudo dpkg -i toxiproxy.deb
# Start toxiproxy server in background
toxiproxy-server &
sleep 2
# Create a proxy for MongoDB (27017 -> 27018)
toxiproxy-cli create mongodb -l localhost:27018 -u localhost:27017
# Add 10ms latency to simulate network conditions
toxiproxy-cli toxic add mongodb -t latency -a latency=10
echo "Toxiproxy setup complete - MongoDB accessible on port 27018 with 10ms latency"
- name: Setup Toxiproxy for latency simulation (baseline)
run: |
set -e
trap 'echo "Toxiproxy setup failed"; exit 1' ERR
# Download and install toxiproxy
wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
sudo dpkg -i toxiproxy.deb
# Start toxiproxy server in background
toxiproxy-server &
sleep 3
# Wait for toxiproxy to be ready (health check)
for i in {1..10}; do
if nc -z localhost 8474 2>/dev/null; then
echo "Toxiproxy server is ready"
break
fi
echo "Waiting for Toxiproxy server... ($i/10)"
sleep 1
done
# Create a proxy for MongoDB (27017 -> 27018)
toxiproxy-cli create mongodb -l localhost:27018 -u localhost:27017
if [ $? -ne 0 ]; then
echo "Failed to create MongoDB proxy"
exit 1
fi
# Add 10ms latency to simulate network conditions
toxiproxy-cli toxic add mongodb -t latency -a latency=10
if [ $? -ne 0 ]; then
echo "Failed to add latency toxic"
exit 1
fi
# Verify the proxy is working
if nc -z localhost 27018 2>/dev/null; then
echo "Toxiproxy setup complete - MongoDB accessible on port 27018 with 10ms latency"
else
echo "Toxiproxy proxy is not accessible on port 27018"
exit 1
fi

Comment on lines +71 to +72
wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
sudo dpkg -i toxiproxy.deb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add checksum validation for downloaded Toxiproxy binary.

Downloading executables without verifying integrity is a supply-chain risk. If the GitHub release is compromised or a MITM attack occurs, malicious code could run in the CI environment.

Consider adding checksum validation:

         wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v${TOXIPROXY_VERSION}/toxiproxy_${TOXIPROXY_VERSION}_amd64.deb
+        wget -O toxiproxy.deb.sha256 https://github.com/Shopify/toxiproxy/releases/download/v${TOXIPROXY_VERSION}/toxiproxy_${TOXIPROXY_VERSION}_amd64.deb.sha256
+        sha256sum -c toxiproxy.deb.sha256 || (echo "Checksum validation failed"; exit 1)
         sudo dpkg -i toxiproxy.deb

Alternatively, use a package manager or container image that handles verification automatically.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
.github/workflows/ci-performance.yml around lines 71-72: the workflow downloads
and installs the Toxiproxy .deb without verifying integrity; update the job to
validate the download by obtaining the expected checksum (preferably a vetted
SHA256 from a trusted source or a checksum file committed to the repo), compute
the SHA256 of the downloaded toxiproxy.deb in CI and compare it against the
expected value, and fail the job if they differ; alternatively replace the
direct download with a verified source such as the OS package manager or a
signed container image that provides built-in verification.

- name: Setup Toxiproxy for latency simulation (baseline)
run: |
# Download and install toxiproxy
wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Hard-coded Toxiproxy version requires a maintenance plan.

The Toxiproxy version is hard-coded to v2.9.0 with no documented strategy for updates or deprecation handling. As CI infrastructure evolves, this could become a source of maintenance debt or security issues.

Consider using a version variable pinned at the top of the workflow for easier updates, or document the maintenance cadence.

Apply this diff to add versioning at the workflow level:

 env:
   NODE_VERSION: 24.11.0
   MONGODB_VERSION: 8.0.4
+  TOXIPROXY_VERSION: 2.9.0

Then update the setup step to reference it:

-         wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy_2.9.0_amd64.deb
-         sudo dpkg -i toxiproxy.deb
+         wget -O toxiproxy.deb https://github.com/Shopify/toxiproxy/releases/download/v${TOXIPROXY_VERSION}/toxiproxy_${TOXIPROXY_VERSION}_amd64.deb
+         sudo dpkg -i toxiproxy.deb

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +152 to +165
- name: Restart Toxiproxy for PR benchmarks
run: |
# Restart toxiproxy server (toxiproxy-cli is already installed from baseline)
pkill toxiproxy-server || true
sleep 1
toxiproxy-server &
sleep 2
# Recreate proxy with same configuration
toxiproxy-cli create mongodb -l localhost:27018 -u localhost:27017
toxiproxy-cli toxic add mongodb -t latency -a latency=10
echo "Toxiproxy restarted with 10ms latency"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add health checks and error handling to Toxiproxy restart step.

The restart step uses pkill ... || true which silently suppresses errors, potentially leaving stale processes. There's no verification that the old process actually stopped or that the new one starts correctly. This can cause state corruption or port conflicts.

Apply this diff to add error handling and validation:

      - name: Restart Toxiproxy for PR benchmarks
        run: |
+         set -e
+         trap 'echo "Toxiproxy restart failed"; exit 1' ERR
+
          # Restart toxiproxy server (toxiproxy-cli is already installed from baseline)
-         pkill toxiproxy-server || true
-         sleep 1
-         toxiproxy-server &
-         sleep 2
+         if pgrep -f toxiproxy-server > /dev/null; then
+           echo "Stopping existing Toxiproxy instance..."
+           pkill -f toxiproxy-server
+           sleep 2
+           # Verify the old process is gone
+           if pgrep -f toxiproxy-server > /dev/null; then
+             echo "Warning: Toxiproxy process still running, using pkill -9"
+             pkill -9 -f toxiproxy-server
+             sleep 1
+           fi
+         fi
+
+         echo "Starting Toxiproxy server..."
+         toxiproxy-server &
+         TOXIPROXY_PID=$!
+         sleep 3
+         
+         # Wait for toxiproxy to be ready
+         for i in {1..10}; do
+           if nc -z localhost 8474 2>/dev/null; then
+             echo "Toxiproxy server is ready (PID: $TOXIPROXY_PID)"
+             break
+           fi
+           echo "Waiting for Toxiproxy server... ($i/10)"
+           sleep 1
+         done
 
          # Recreate proxy with same configuration
          toxiproxy-cli create mongodb -l localhost:27018 -u localhost:27017
          toxiproxy-cli toxic add mongodb -t latency -a latency=10
+         if [ $? -ne 0 ]; then
+           echo "Failed to recreate MongoDB proxy"
+           exit 1
+         fi
 
-         echo "Toxiproxy restarted with 10ms latency"
+         # Verify the proxy is working
+         if nc -z localhost 27018 2>/dev/null; then
+           echo "Toxiproxy restarted with 10ms latency - MongoDB accessible on port 27018"
+         else
+           echo "Toxiproxy proxy is not accessible on port 27018 after restart"
+           exit 1
+         fi
🤖 Prompt for AI Agents
.github/workflows/ci-performance.yml around lines 152 to 165: the Toxiproxy
restart step lacks verification and silences failures; update the step to
explicitly stop any existing toxiproxy-server and fail if it cannot be
terminated within a short timeout, verify the proxy port is free before
starting, start toxiproxy-server and poll until it responds on its control port
(failing the job on timeout), recreate the proxy and toxic but check the return
codes or HTTP responses for success and retry a couple times before failing, and
emit clear error messages on each failure so the CI job fails fast on
unrecoverable errors.

@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.05%. Comparing base (d94f348) to head (1fd1cef).

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #9924      +/-   ##
==========================================
- Coverage   93.07%   93.05%   -0.02%     
==========================================
  Files         187      187              
  Lines       15224    15224              
  Branches      177      177              
==========================================
- Hits        14170    14167       -3     
- Misses       1042     1045       +3     
  Partials       12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mtrezza
Copy link
Member Author

mtrezza commented Nov 9, 2025

Not necessary; variability is low enough at current test setup

@mtrezza mtrezza closed this Nov 9, 2025
@mtrezza mtrezza deleted the ci/perf branch November 9, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants