Sample Performance Testing Framework
1. Framework Architecture
performance-testing-framework/
│
├── config/ # Configurations for environments
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
│
├── test-scripts/ # JMeter test plans
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── custom-groovy-scripts/ # Custom Groovy for complex logic
│ └── [Link]
│
├── test-data/ # Dynamic and static test data
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
│
├── monitoring/ # Monitoring setup for system and application
│ ├── prometheus/
│ ├── grafana/
│ └── dashboards/
│ └── [Link]
│
├── reports/ # Reports and logs
│ ├── html/
│ ├── csv/
│ └── logs/
│ └── [Link]
│
├── scripts/ # Helper scripts
│ ├── [Link]
│ ├── [Link]
│ └── [Link]
│
├── docker/ # Docker setup for test execution
│ ├── Dockerfile
│ ├── [Link]
│ └── [Link]
│
1|Page Santhosh Kumar J
├── pipelines/ # CI/CD integration
│ ├── jenkinsfile
│ └── [Link]
│
├── utils/ # Utility functions and libraries
│ └── [Link]
│
└── [Link] # Documentation
2. Key Enhancements
2.1 Advanced Features
1. Distributed Load Testing:
o Use Kubernetes to scale load generators.
o Dynamically allocate test resources using Kubernetes HPA (Horizontal Pod
Autoscaler).
2. Dynamic Data Handling:
o Generate real-time test data for APIs, Kafka topics, and databases using
Python scripts or Groovy.
3. Integration with Monitoring Tools:
o Integrate JMeter with Prometheus and Grafana for real-time visualization of
metrics like TPS, response times, and error rates.
4. Custom Logic in Groovy:
o Use Groovy scripts for complex scenarios like token handling, conditional
flows, and dynamic payload generation.
3. Setup Guide
3.1 Configuration Files
Example: [Link]
baseUrl=[Link]
threads=50
rampUpTime=30
duration=300
kafkaBroker=[Link]
grafanaUrl=[Link]
3.2 Test Data
Dynamic Data Generator Script ([Link])
2|Page Santhosh Kumar J
import csv
import random
def generate_users(output_file, count):
with open(output_file, 'w', newline='') as csvfile:
writer = [Link](csvfile)
[Link](['username', 'password'])
for i in range(count):
username = f'user{i}@[Link]'
password = f'password{i}'
[Link]([username, password])
generate_users('test-data/[Link]', 100)
3.3 JMeter Test Scripts
1. Custom Login Flow (with Groovy Token Generation) Groovy Script: dynamic-token-
[Link]
import [Link]
def loginResponse = [Link]()
def jsonSlurper = new JsonSlurper()
def response = [Link](loginResponse)
[Link]("authToken", [Link])
2. Kafka Load Test Use JMeter's Kafka sampler to publish and consume messages:
<KafkaProducerSampler>
<bootstrapServers>${kafkaBroker}</bootstrapServers>
<topic>test-topic</topic>
<key>${randomUUID()}</key>
<message>{"orderId": ${orderId}, "status": "processing"}</message>
</KafkaProducerSampler>
3. Distributed Testing Setup
o Master and slave setup using Kubernetes.
o Configurable using [Link].
3.4 Dockerized Load Testing
Dockerfile
FROM alpine:latest
RUN apk add --no-cache openjdk11 curl bash
3|Page Santhosh Kumar J
RUN curl -o /opt/[Link] [Link]
&& \
tar -xzf /opt/[Link] -C /opt && \
rm /opt/[Link]
ENV JMETER_HOME /opt/apache-jmeter-5.5
ENV PATH $JMETER_HOME/bin:$PATH
[Link]
version: '3.8'
services:
jmeter-master:
build: .
command: jmeter -n -t /scripts/[Link] -R jmeter-slave-1,jmeter-slave-2
jmeter-slave:
image: jmeter:latest
4. CI/CD Integration
4.1 Jenkins Pipeline
pipeline {
agent any
environment {
CONFIG_FILE = 'config/[Link]'
}
stages {
stage('Prepare Environment') {
steps {
script {
sh 'python3 scripts/[Link]'
}
}
}
stage('Execute Tests') {
steps {
script {
sh 'bash scripts/[Link] test'
}
}
}
stage('Analyze Results') {
steps {
script {
sh 'python3 scripts/[Link]'
}
}
}
}
}
4|Page Santhosh Kumar J
5. Monitoring and Reporting
5.1 Prometheus and Grafana
• Export JMeter metrics to Prometheus using jmeter-prometheus-plugin.
• Create Grafana dashboards with metrics like:
o Average Response Time
o Error Rate
o 95th Percentile Latency
o System Metrics (CPU, Memory, Disk)
Example Dashboard JSON ([Link]):
{
"title": "Performance Testing Metrics",
"panels": [
{
"title": "Average Response Time",
"type": "graph",
"targets": [
{ "expr": "jmeter_response_time_avg", "legendFormat": "{{test_name}}" }
]
}
]
}
6. Execution Steps
1. Prepare Test Data:
python3 test-data/[Link]
2. Run Tests:
bash scripts/[Link] test
3. Monitor Metrics: Access Grafana at [Link]
4. View Reports: Open reports/html/[Link].
7. Advanced Enhancements
5|Page Santhosh Kumar J
1. Auto-Scaling for Distributed Load:
o Use Kubernetes HPA to scale JMeter slaves based on CPU usage.
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
spec:
scaleTargetRef:
kind: Deployment
name: jmeter-slave
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
2. Chaos Engineering Integration:
o Use Gremlin to inject failures during load testing.
3. Custom Result Analysis:
o Use scripts/[Link] to compare new test results with baselines.
This sample framework provides a robust and scalable solution for advanced performance
testing.
6|Page Santhosh Kumar J