Skip to content

Performance Testing Implementation - October 17, 2025

Overview

Implemented comprehensive performance testing using Gatling 3.10.5, a powerful open-source load testing framework. This implementation showcases performance testing best practices for Java developers.


Implementation Summary

Files Created

1. Build Configuration

  • build.gradle - Added Gatling plugin and dependencies

2. Test Scenarios (Scala)

  • BasicLoadSimulation.scala - Normal load testing (45 users, 1 min)
  • StressTestSimulation.scala - Breaking point identification (200+ users, 2 min)
  • CircuitBreakerSimulation.scala - Resilience testing (60 users, 2 min)
  • EnduranceTestSimulation.scala - Stability over time (32 users, 10 min)

3. Configuration & Data

  • gatling.conf - Gatling configuration
  • products.csv - Mock product data (20 products)
  • members.csv - Mock member data (20 members)

4. Documentation

  • PERFORMANCE_TESTING.md - Comprehensive guide (400+ lines)
  • GATLING_QUICK_REFERENCE.md - Quick reference card

Test Scenarios

1. BasicLoadSimulation

Purpose: Validate basic functionality under normal load conditions

Characteristics: - 45 concurrent users - Gradual ramp-up over 20 seconds - 3 scenarios running in parallel - Duration: ~1 minute

Test Coverage: - Health check endpoint - API endpoints (default, second, probe) - Basic circuit breaker behavior

Success Criteria: - Max response time: <5 seconds - Success rate: >95% - No circuit breaker trips

Use Cases: - Smoke testing after deployments - Baseline performance metrics - Regression testing - CI/CD integration


2. StressTestSimulation

Purpose: Identify system breaking points and capacity limits

Characteristics: - 200+ concurrent users - Includes spike tests (100 users at once) - Sustained high load for 60 seconds - Mixed workload patterns - Duration: ~2 minutes

Test Coverage: - Sustained high load - Sudden traffic spikes - Circuit breaker stress testing - Mixed endpoint workload

Success Criteria: - Max response time: <10 seconds - Success rate: >80% - Circuit breaker may open (expected)

Use Cases: - Capacity planning - Infrastructure sizing - Identifying bottlenecks - Load balancer testing


3. CircuitBreakerSimulation

Purpose: Verify Resilience4j circuit breaker behavior and recovery

Characteristics: - 60 concurrent users - 5 distinct test phases - Specific scenarios to trigger circuit breaker - Duration: ~2 minutes

Test Phases: 1. Normal Operation (0-20s): Baseline behavior 2. Trigger Circuit Breaker (20-40s): Rapid requests to open circuit 3. Recovery (40-60s): Verify half-open and closed states 4. Mixed Load (throughout): Realistic traffic patterns 5. Resilience Verification (60-90s): Post-stress validation

Success Criteria: - Success rate: >70% (accounts for circuit breaker opening) - Circuit breaker opens under stress - System recovers after load reduction - No cascading failures

Use Cases: - Validating circuit breaker configuration - Testing failure scenarios - Verifying recovery mechanisms - Resilience engineering


4. EnduranceTestSimulation

Purpose: Test stability and performance over extended periods (soak test)

Characteristics: - 32 concurrent users - 10-minute duration - Sustained moderate load - Periodic burst patterns - Continuous health monitoring

Test Coverage: - Continuous API calls - Health monitoring - Mixed endpoint usage - Periodic traffic bursts

Success Criteria: - Success rate: >99% - Stable response times throughout - No memory leaks - No resource exhaustion

Use Cases: - Identifying memory leaks - Testing resource cleanup - Validating long-running stability - Production readiness verification


Technical Implementation

Gradle Configuration

plugins {
  id 'io.gatling.gradle' version '3.10.5.1'
}

dependencies {
  gatling 'io.gatling.highcharts:gatling-charts-highcharts:3.10.5'
  gatling 'io.gatling:gatling-app:3.10.5'
  gatling 'io.gatling:gatling-recorder:3.10.5'
}

gatling {
  logLevel = 'WARN'
}

Directory Structure

src/gatling/
├── scala/com/anr/performance/
│   ├── BasicLoadSimulation.scala
│   ├── StressTestSimulation.scala
│   ├── CircuitBreakerSimulation.scala
│   └── EnduranceTestSimulation.scala
├── resources/
│   ├── gatling.conf
│   └── data/
│       ├── products.csv
│       └── members.csv

Example Test Scenario

package com.anr.performance

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class BasicLoadSimulation extends Simulation {

  val httpProtocol = http
    .baseUrl("http://localhost:8080")
    .acceptHeader("application/json")
    .basicAuth("user", "password")

  val scenario = scenario("API Test")
    .exec(
      http("Request")
        .get("/api/v1/default")
        .check(status.is(200))
    )

  setUp(
    scenario.inject(rampUsers(10) during (10.seconds))
  ).protocols(httpProtocol)
    .assertions(
      global.responseTime.max.lt(5000),
      global.successfulRequests.percent.gt(95)
    )
}

Mock Data

Products CSV (20 items)

name,description,price
Laptop Pro,High-performance laptop with 16GB RAM,1299.99
Wireless Mouse,Ergonomic wireless mouse with USB receiver,29.99
...

Members CSV (20 items)

firstname,lastname,email,dob
John,Doe,john.doe@example.com,1990-01-15
Jane,Smith,jane.smith@example.com,1985-03-22
...

Running Tests

Quick Start

# Start application
docker-compose up -d

# Run basic load test
./gradlew gatlingRun-com.anr.performance.BasicLoadSimulation

# View report
open build/reports/gatling/*/index.html

All Test Commands

# Run all tests
./gradlew gatlingRun

# Run specific tests
./gradlew gatlingRun-com.anr.performance.BasicLoadSimulation
./gradlew gatlingRun-com.anr.performance.StressTestSimulation
./gradlew gatlingRun-com.anr.performance.CircuitBreakerSimulation
./gradlew gatlingRun-com.anr.performance.EnduranceTestSimulation

Reports

Report Location

build/reports/gatling/<simulation-name>-<timestamp>/index.html

Key Metrics

Response Time: - Mean, Min, Max - Percentiles (50th, 75th, 95th, 99th)

Throughput: - Requests per second - Responses per second

Success Rate: - OK (HTTP 2xx) - KO (HTTP 4xx/5xx, timeouts)

Active Users: - Concurrent virtual users over time

Sample Report Output

================================================================================
---- Global Information --------------------------------------------------------
> request count                                    1000 (OK=950    KO=50    )
> min response time                                  12 (OK=12     KO=45    )
> max response time                                2345 (OK=2345   KO=1234  )
> mean response time                                234 (OK=220    KO=567   )
> response time 95th percentile                     890 (OK=850    KO=1100  )
> mean requests/sec                               16.67 (OK=15.83  KO=0.83  )
================================================================================

Benefits for Java Developers

1. Educational Value

  • Learn performance testing best practices
  • Understand load testing patterns
  • See real-world test scenarios
  • Study Scala DSL for testing

2. Practical Examples

  • Circuit breaker testing
  • Stress testing patterns
  • Endurance testing strategies
  • Data-driven testing with CSV

3. Production Ready

  • CI/CD integration examples
  • Comprehensive documentation
  • Realistic test scenarios
  • Performance baselines

4. Framework Knowledge

  • Gatling DSL
  • Scenario composition
  • Load injection patterns
  • Assertions and validations

Integration with CI/CD

GitHub Actions Example

name: Performance Tests

on:
  schedule:
    - cron: '0 2 * * *'

jobs:
  performance:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '21'

      - name: Start Application
        run: docker-compose up -d

      - name: Run Performance Tests
        run: ./gradlew gatlingRun

      - name: Upload Reports
        uses: actions/upload-artifact@v3
        with:
          name: gatling-reports
          path: build/reports/gatling/

Best Practices Demonstrated

1. Test Organization

  • Separate scenarios by purpose
  • Clear naming conventions
  • Modular test design
  • Reusable components

2. Load Patterns

  • Gradual ramp-up
  • Sustained load
  • Spike testing
  • Mixed workloads

3. Assertions

  • Response time thresholds
  • Success rate requirements
  • Percentile targets
  • Failure limits

4. Data Management

  • CSV feeders for variety
  • Mock data generation
  • Realistic test data
  • Data cleanup

Performance Metrics

Test Execution Times

Test Duration Users Requests
Basic Load ~1 min 45 ~500
Stress Test ~2 min 200+ ~2000
Circuit Breaker ~2 min 60 ~1500
Endurance 10 min 32 ~5000

Resource Requirements

  • CPU: 2+ cores recommended
  • Memory: 4GB+ for stress tests
  • Disk: 100MB for reports
  • Network: Local or low-latency

Comparison: Before vs After

Aspect Before After
Performance Testing None 4 comprehensive scenarios
Load Testing Tool None Gatling 3.10.5
Test Coverage 0% Circuit breaker, stress, endurance
Documentation None 2 comprehensive guides
Mock Data None 40 test records
CI/CD Ready No Yes
Reports None Beautiful HTML reports
Developer Learning None Complete examples

Future Enhancements

Potential Improvements

  1. Additional Scenarios
  2. Database-heavy operations
  3. File upload/download
  4. WebSocket testing
  5. GraphQL endpoints

  6. Advanced Features

  7. Custom protocols
  8. SSE (Server-Sent Events)
  9. gRPC testing
  10. Distributed testing

  11. Integration

  12. Grafana dashboards
  13. Prometheus metrics
  14. ELK stack logging
  15. APM integration

  16. Automation

  17. Scheduled runs
  18. Performance regression detection
  19. Automatic baseline updates
  20. Slack/email notifications

Summary

Implementation Statistics

  • Files Created: 10
  • Test Scenarios: 4
  • Mock Data Records: 40
  • Documentation Pages: 2
  • Lines of Code: ~800 (Scala + config)
  • Lines of Documentation: ~600

Key Features

✅ Gatling 3.10.5 integrated
✅ 4 comprehensive test scenarios
✅ Circuit breaker specific testing
✅ Mock data with CSV feeders
✅ Beautiful HTML reports
✅ CI/CD ready
✅ Comprehensive documentation
✅ Educational for Java developers

Test Coverage

  • ✅ Normal load testing
  • ✅ Stress testing
  • ✅ Circuit breaker behavior
  • ✅ Endurance testing
  • ✅ Response time analysis
  • ✅ Throughput metrics
  • ✅ Success rate validation

Implementation Date: October 17, 2025
Gatling Version: 3.10.5
Status: ✅ Complete and Production-Ready
Purpose: Showcase performance testing for Java developers