Skip to content
Merged
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
150 changes: 150 additions & 0 deletions .cursor/rules/151-java-performance-jmeter.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
description:
globs:
alwaysApply: false
---
# Run performance tests based on JMeter

## ⚠️ CRITICAL INSTRUCTION FOR AI ASSISTANTS ⚠️

**WHEN USING THE PERFORMANCE SCRIPT TEMPLATE:**
- **COPY THE BASH SCRIPT EXACTLY** from `java-performance-script-template.md`
- **NO MODIFICATIONS, INTERPRETATIONS, OR ENHANCEMENTS** allowed
- **USE EVERY LINE VERBATIM** - do not change logic, structure, or features
- **DO NOT CREATE YOUR OWN VERSION** - use the provided template only
- The template script is complete, tested, and production-ready

---

## 📋 How to Copy the Performance Script Template

### Step 1: Create the Script File
When a user requests JMeter performance testing setup:

1. **Copy the entire script** from `.cursor/rules/templates/java-performance-script-template.md`
2. **Create the file** as `run-jmeter.sh` in the project root
3. **Make it executable**: `chmod +x run-jmeter.sh`

### Step 2: Template Location
- **Source**: `.cursor/rules/templates/java-performance-script-template.md`
- **Destination**: `run-jmeter.sh` (project root)
- **Copy Method**: Exact verbatim copy - no changes allowed

---

## 🚀 Script Usage Instructions

### Basic Usage
```bash
# Run with default settings (1000 loops, 1 thread, 1s ramp-up)
./run-jmeter.sh

# Custom configuration
./run-jmeter.sh -l 500 -t 10 -r 30

# Open JMeter GUI
./run-jmeter.sh -g
```

### Available Options
- `-l, --loops LOOPS`: Number of loops per thread (default: 1000)
- `-t, --threads THREADS`: Number of concurrent threads (default: 1)
- `-r, --ramp-up SECONDS`: Ramp-up period in seconds (default: 1)
- `-g, --gui`: Open JMeter GUI instead of running in non-GUI mode
- `-h, --help`: Show detailed help message

### Environment Variables
```bash
# Override defaults using environment variables
JMETER_LOOPS=500 JMETER_THREADS=5 ./run-jmeter.sh

# Or export them
export JMETER_LOOPS=1000
export JMETER_THREADS=10
export JMETER_RAMP_UP=30
./run-jmeter.sh
```

### Example Scenarios
```bash
# Light load test
./run-jmeter.sh -l 100 -t 1 -r 1

# Medium load test
./run-jmeter.sh -l 500 -t 5 -r 10

# Heavy load test
./run-jmeter.sh -l 1000 -t 20 -r 60

# Quick GUI setup
./run-jmeter.sh -g
```

---

## 📁 Required Project Structure

The script expects this structure:
```
project-root/
├── run-jmeter.sh # The performance script
├── src/test/resources/jmeter/
│ └── load-test.jmx # JMeter test plan
└── target/ # Generated reports (auto-created)
├── jmeter-results.jtl # Raw results
├── jmeter-report/ # HTML dashboard
│ └── index.html # Main report
└── jmeter.log # Execution log
```

---

## 🔧 Prerequisites

1. **JMeter Installation**: Must be installed and available in PATH
2. **Test Plan**: Must exist at `src/test/resources/jmeter/load-test.jmx`
3. **Executable Permissions**: Script must be executable (`chmod +x run-jmeter.sh`)

---

## 📊 Output Files

After running the script, you'll get:

1. **Raw Results**: `target/jmeter-results.jtl` (JTL format)
2. **HTML Dashboard**: `target/jmeter-report/index.html` (automatically opens in browser)
3. **Execution Log**: `jmeter.log` (debugging information)

---

## 💡 Best Practices

### For Load Testing
- Start with low thread counts and gradually increase
- Monitor system resources during tests
- Use realistic ramp-up periods (don't slam the server)

### For Test Plan Development
- Use GUI mode (`-g`) for initial test plan creation
- Test with low load first (`-l 10 -t 1`)
- Validate test plan logic before heavy load testing

### For CI/CD Integration
```bash
# Example CI/CD usage
./run-jmeter.sh -l 100 -t 5 -r 10
# Check exit code for pass/fail status
```

---

## 🚨 Important Notes

- The script automatically cleans previous results
- HTML reports open automatically in your default browser
- All configuration is parameterized - no hardcoded values
- The script provides colored output for better visibility
- Comprehensive error handling and validation included

---

23 changes: 14 additions & 9 deletions .cursor/rules/templates/java-checklist-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Use the following process to improve the java development in some areas if requi
|-------------|-------------|--------|-------|
| [131-java-unit-testing](.cursor/rules/131-java-unit-testing.mdc) | Unit Testing | `Can improve the unit tests using the cursor rule @131-java-unit-testing` | Add in the context a Test Class or the package |


### Step 5: Refactoring

| Cursor Rule | Description | Prompt | Notes |
Expand All @@ -45,14 +44,20 @@ Use the following process to improve the java development in some areas if requi
| [142-java-functional-programming](.cursor/rules/142-java-functional-programming.mdc) | Functional Programming | `Refactor my code to use functional programming using the cursor rule @142-java-functional-programming` | |
| [143-java-data-oriented-programming](.cursor/rules/143-java-data-oriented-programming.mdc) | Data Oriented Programming | `Refactor my code to use data oriented programming using the cursor rule @143-java-data-oriented-programming` | |

### Step 6: Profiling
### Step 6: Performance (Jmeter)

| Activity | Description | Prompt | Notes |
|----------|------|--------|-------|
| [151-java-performance-jmeter](.cursor/rules/151-java-performance-jmeter.mdc) | Run a peformance test with Jmeter | `Add JMeter performance testing to this project using @151-java-performance-jmeter.mdc` | You could ask the model to create a JMeter based on a RestController/Resource |

### Step 7: Profiling (Async profiler)

| Activity | Description | Prompt | Notes |
|----------|------|--------|-------|
| [151-java-profiling-detect](.cursor/rules/151-java-profiling-detect.mdc) | Measure problems | `My Java application has performance issues - help me set up comprehensive profiling process using @151-java-profiling-detect.mdc and use the location YOUR-DEVELOPMENT/profiler` | Replace YOUR-DEVELOPMENT with your actual development path. Example: examples/spring-boot-memory-leak-demo/profiler |
| [152-java-profiling-analyze](.cursor/rules/152-java-profiling-analyze.mdc) | Analyze results | `Analyze the results located in YOUR-DEVELOPMENT/profiler and use the cursor rule @152-java-profiling-analyze` | Replace YOUR-DEVELOPMENT with your actual development path. Example: examples/spring-boot-memory-leak-demo/profiler |
| [161-java-profiling-detect](.cursor/rules/161-java-profiling-detect.mdc) | Measure problems | `My Java application has performance issues - help me set up comprehensive profiling process using @151-java-profiling-detect.mdc and use the location YOUR-DEVELOPMENT/profiler` | Replace YOUR-DEVELOPMENT with your actual development path. Example: examples/spring-boot-memory-leak-demo/profiler |
| [162-java-profiling-analyze](.cursor/rules/162-java-profiling-analyze.mdc) | Analyze results | `Analyze the results located in YOUR-DEVELOPMENT/profiler and use the cursor rule @152-java-profiling-analyze` | Replace YOUR-DEVELOPMENT with your actual development path. Example: examples/spring-boot-memory-leak-demo/profiler |
| - | Code Refactoring | `Can you apply the solutions from @profiling-solutions-yyyymmdd.md in @/info to mitigate bottlenecks` | Make a refactoring with the notes from the analysis |
| [154-java-profiling-compare](.cursor/rules/152-java-profiling-compare.mdc) | Analyze results | `Review if the problems was solved with last refactoring using the reports located in @/results with the cursor rule 154-java-profiling-compare.mdc` | Put in the context the folder with the results |
| [164-java-profiling-compare](.cursor/rules/162-java-profiling-compare.mdc) | Analyze results | `Review if the problems was solved with last refactoring using the reports located in @/results with the cursor rule 154-java-profiling-compare.mdc` | Put in the context the folder with the results |

## Reference Table: Java Cursor Rules

Expand All @@ -70,10 +75,10 @@ Use the following process to improve the java development in some areas if requi
| Modern Java Features | @141-java-refactoring-with-modern-features | Refactoring with modern Java (Java 8+) features |
| Functional Programming | @142-java-functional-programming | Applying functional programming in Java |
| Data Oriented Programming | @143-java-data-oriented-programming | Data-oriented programming style in Java |
| Java Profiling | @151-java-profiling-detect | Generate profiling data |
| Java Profiling | @152-java-profiling-analyze | Analyze profiling data |
| Java Profiling | @154-java-profiling-compare | Compare results after refactoring |
| SQL Guidelines | @500-sql | SQL development best practices |
| Performance testing | @151-java-performance-jmeter | Run a Jmeter script |
| Java Profiling | @161-java-profiling-detect | Generate profiling data |
| Java Profiling | @162-java-profiling-analyze | Analyze profiling data |
| Java Profiling | @164-java-profiling-compare | Compare results after refactoring |

## Tips & Best Practices

Expand Down
Loading