Thanks to visit codestin.com
Credit goes to github.com

Skip to content

coeur85/mariadb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MariaDB Performance Testing Suite with Percona Monitoring

A comprehensive Docker-based solution for MariaDB performance testing with integrated Percona PMM monitoring.

πŸ—οΈ Project Structure

β”œβ”€β”€ docker-compose.yml     # Complete environment setup
β”œβ”€β”€ Dockerfile            # Test application container
β”œβ”€β”€ README.md             # This documentation
└── test_files/           # Test scripts directory
    β”œβ”€β”€ auto_run_tests.sh     # Automated test runner
    β”œβ”€β”€ setup_database.sh     # Database setup
    β”œβ”€β”€ insert_test.sh        # INSERT operations
    β”œβ”€β”€ update_test.sh        # UPDATE operations  
    β”œβ”€β”€ delete_test.sh        # DELETE operations
    β”œβ”€β”€ select_test.sh        # SELECT queries
    └── run_performance_tests.sh  # Interactive test menu

πŸš€ Quick Start

Complete Setup

# Start all services
docker compose up -d

# Enable query response time plugin
./mariadb_setup/enable-query-response-time.sh

# Setup PMM table statistics  
./mariadb_setup/enable-pmm-table-stats.sh

# Run performance tests on custom database
sudo docker run --rm -e DB_NAME=sales_db --name sales_db_test --network mariadb_app_network mariadb-tester

πŸ“Š Services Overview

MariaDB Database (mariadb1)

  • Container: mariadb1
  • Port: 3306
  • Credentials: root / 123
  • Default DB: performance_test

Percona PMM Server (pmm-server)

Percona PMM Client (pmm-client)

  • Container: pmm-client
  • Purpose: Monitoring agent for MariaDB
  • Auto-connects: Links to PMM server automatically

Test Application (Standalone)

  • Built from: Dockerfile
  • Purpose: CRUD and performance testing
  • Database Parameter: Configurable via DB_NAME environment variable
  • Usage: Run separately using docker commands

πŸ§ͺ Running Tests

Basic Test Run

# First, build the test image
docker build -t mariadb-tester .

# Run tests on default database (performance_test)
sudo docker run --rm --network mariadb_app_network mariadb-tester

# Run tests on custom database (simplified syntax)
sudo docker run --rm --network mariadb_app_network \
  -e DB_NAME=sales_db --name sales_db_test mariadb-tester

# Run interactive test menu
sudo docker run --rm -it --network mariadb_app_network \
  -e DB_NAME=sales_db --name sales_db_test mariadb-tester ./run_performance_tests.sh

Available Test Operations

Script Description Operations
setup_database.sh Database and table creation DDL
insert_test.sh High-volume INSERT operations CREATE
select_test.sh Complex SELECT queries READ
update_test.sh Bulk UPDATE operations UPDATE
delete_test.sh Bulk DELETE operations DELETE
auto_run_tests.sh Complete automated suite ALL

πŸ“ˆ Percona PMM Monitoring

Access Dashboard

  1. Start services: docker compose up -d
  2. Open browser: http://localhost:8080
  3. Login: admin / admin

Register MariaDB for Monitoring

οΏ½ Setup PMM Monitoring:

# Enable query response time plugin
./mariadb_setup/enable-query-response-time.sh

# Setup PMM table statistics (follow instructions)
./mariadb_setup/enable-pmm-table-stats.sh

Manual Registration via Web UI:

  1. Go to Configuration β†’ Inventory
  2. Click "Add Service"
  3. Select "MySQL"
  4. Use these connection details:
    • Host: mariadb1
    • Port: 3306
    • Username: root
    • Password: 123
    • Service Name: mariadb-monitoring
  5. βš™οΈ CRITICAL - Advanced Settings:
    • βœ… Enable "Table Statistics"
    • βœ… Set "Table Statistics Limit" to 5000
    • βœ… Enable "Query Analytics" with "Performance Schema"
    • βœ… Enable "User Statistics"

πŸ› οΈ Configuration

Environment Variables

All test scripts support these parameters:

DB_NAME=your_database    # Target database name
DB_HOST=mariadb1         # Database host
DB_PORT=3306             # Database port  
DB_USER=root             # Database username
DB_PASS=123              # Database password

Custom Database Testing

# Build test image first (if not already built)
sudo docker build -t mariadb-tester .

# Test specific database (simplified)
sudo docker run --rm --network mariadb_app_network \
  -e DB_NAME=sales_db --name sales_db_test mariadb-tester

# Test with different database
sudo docker run --rm --network mariadb_app_network \
  -e DB_NAME=inventory --name inventory_test mariadb-tester

# Test with custom user credentials (override defaults)
sudo docker run --rm --network mariadb_app_network \
  -e DB_NAME=inventory -e DB_USER=testuser -e DB_PASS=testpass \
  --name inventory_test mariadb-tester

πŸ”§ Management Commands

# Start core services (MariaDB + PMM)
docker compose up -d

# Stop all services  
docker compose down

# View logs
docker compose logs -f mariadb1
docker compose logs -f pmm-server

# Clean restart
docker compose down -v && docker compose up -d

# Build test application
sudo docker build -t mariadb-tester .

# Run specific test
sudo docker run --rm --network mariadb_app_network \
  -e DB_NAME=sales_db --name sales_db_test \
  mariadb-tester ./insert_test.sh

πŸ“‹ Database Schema

CREATE TABLE transactions (
    transaction_id INT AUTO_INCREMENT PRIMARY KEY,
    product_name VARCHAR(100),
    quantity INT,
    price DECIMAL(10,2),
    transaction_date DATETIME
);

🎯 Key Features

  • Dockerized Environment - Complete setup with one command
  • Database Flexibility - Test any database via DB_NAME parameter
  • Comprehensive Testing - CRUD operations + performance tests
  • Real-time Monitoring - Percona PMM integration
  • Network Isolation - All services on dedicated network
  • No Auto-registration - Manual PMM configuration for control

πŸ“š Usage Examples

Development Workflow

# 1. Start core services
docker compose up -d

# 2. Build test application
sudo docker build -t mariadb-tester .

# 3. Run tests on your database  
sudo docker run --rm --network mariadb_app_network \
  -e DB_NAME=myapp_db --name myapp_test mariadb-tester

# 4. Monitor in PMM dashboard
# Visit: http://localhost:8080

# 5. Clean up
docker compose down

This setup provides a complete MariaDB testing and monitoring environment with minimal configuration required.

DB_NAME="performance_test"
DB_USER="root"
DB_PASS=""  # Set your password
DB_HOST="localhost"
DB_PORT="3306"

Usage

Quick Start (Interactive Mode)

cd /home/magdi/mariadb
chmod +x *.sh
./run_performance_tests.sh

Command Line Mode

# Run all tests
./run_performance_tests.sh all

# Run individual tests
./run_performance_tests.sh setup
./run_performance_tests.sh insert
./run_performance_tests.sh update
./run_performance_tests.sh delete
./run_performance_tests.sh select

# Show statistics
./run_performance_tests.sh stats

# Clean database
./run_performance_tests.sh clean

Individual Script Usage

# Setup database first
./setup_database.sh

# Run performance tests
./insert_test.sh      # Insert 100,000 records
./select_test.sh      # Various SELECT patterns
./update_test.sh      # Update 50,000 records
./delete_test.sh      # Delete 25,000 records

# Optimize MariaDB configuration
./optimize_mariadb.sh

Test Details

INSERT Test (insert_test.sh)

  • Records: 100,000 (configurable)
  • Batch Size: 1,000 records per batch
  • Threads: 4 parallel threads
  • Data: Realistic product transactions with random data
  • Features: Bulk inserts with transaction batching for optimal performance

UPDATE Test (update_test.sh)

  • Updates: 50,000 (configurable)
  • Patterns: Price adjustments, quantity updates, product name changes, date updates
  • Threads: 4 parallel threads
  • Features: Various update patterns to simulate real-world scenarios

DELETE Test (delete_test.sh)

  • Deletes: 25,000 (configurable)
  • Patterns: Old records, low-value transactions, high quantities, specific products
  • Threads: 4 parallel threads
  • Features: Different deletion criteria to test various index usage

SELECT Test (select_test.sh)

  • Query Types: Simple, Aggregate, Complex
  • Queries: 1,000 per type (configurable)
  • Threads: 4 parallel threads
  • Features:
    • Simple: ID ranges, product filters, price ranges
    • Aggregate: COUNT, SUM, AVG, GROUP BY operations
    • Complex: Subqueries, window functions, statistical analysis

Performance Optimization

Runtime Optimizations (optimize_mariadb.sh)

The optimizer script automatically:

  • Detects system resources (RAM, CPU, disk space)
  • Calculates optimal buffer pool size (70% of RAM)
  • Sets appropriate connection limits
  • Optimizes InnoDB settings for bulk operations
  • Disables safety features for maximum performance (testing only!)

Key Optimizations Applied:

  • InnoDB Buffer Pool: 70% of available RAM
  • Log File Size: 25% of buffer pool size
  • Flush Settings: Optimized for performance over durability
  • Thread Pool: Based on CPU cores
  • Disabled Features: Binary logging, doublewrite buffer (testing only)

Expected Performance

Typical Throughput (4-core system, 8GB RAM):

  • INSERT: 15,000-25,000 records/second
  • SELECT Simple: 5,000-10,000 queries/second
  • SELECT Aggregate: 1,000-3,000 queries/second
  • SELECT Complex: 500-1,500 queries/second
  • UPDATE: 5,000-15,000 updates/second
  • DELETE: 3,000-10,000 deletes/second

Performance varies significantly based on hardware, MariaDB configuration, and system load.

Monitoring and Results

Each test script provides:

  • Real-time progress updates
  • Execution time measurement
  • Throughput calculations (operations/second)
  • Error reporting
  • Sample result verification

Example Output:

INSERT test completed!
Total time: 6.45s
Records inserted: 100000
Throughput: 15503.88 records/second
Current table count: 100000 records

Safety Considerations

⚠️ WARNING: These scripts are designed for performance testing only!

  • Scripts disable important safety features (durability, binary logging)
  • Use dedicated test systems, not production databases
  • High-volume operations may impact system performance
  • Ensure adequate disk space before running tests

Troubleshooting

PMM Table Statistics Issues:

❌ "No data" in PMM Table Details Dashboard:

# Enable query response time
./mariadb_setup/enable-query-response-time.sh

# Setup PMM table statistics
./mariadb_setup/enable-pmm-table-stats.sh

πŸ”§ Manual Fix:

  1. Ensure Table Statistics are enabled during service registration
  2. Set Table Statistics Limit to 5000+ (not default 1000)
  3. Enable Performance Schema for Query Analytics
  4. Wait 2-3 minutes after registration for data collection

Common Issues:

  1. Connection Failed

    • Check MariaDB service status: sudo docker compose ps
    • Verify credentials in script configuration
    • Ensure MariaDB is accepting connections
  2. Low Performance

    • Check system resources (RAM, CPU, I/O)
    • Monitor system load during tests
    • Use docker compose logs mariadb1 for debugging
  3. Out of Memory Errors

    • Reduce batch sizes in scripts
    • Decrease thread count
    • Increase system swap space
    • Optimize MariaDB memory settings
  4. Permission Errors

    • Ensure scripts are executable: chmod +x *.sh
    • Use sudo for Docker commands
    • Verify file system permissions

Customization

Adjusting Test Parameters:

Edit variables in each script:

TOTAL_RECORDS=100000    # Number of records to insert
BATCH_SIZE=1000         # Records per batch
THREADS=4               # Parallel threads
QUERIES_PER_TYPE=1000   # Queries per test type

Adding Custom Test Patterns:

Modify the test functions in each script to add:

  • Different data patterns
  • Custom query types
  • Additional product categories
  • Specific business logic scenarios

Advanced Usage

Benchmarking Different Configurations:

  1. Run baseline tests with default MariaDB settings
  2. Apply optimizations with optimize_mariadb.sh
  3. Run tests again and compare results
  4. Adjust individual parameters and re-test

Continuous Performance Testing:

# Create a performance monitoring loop
while true; do
    echo "Starting performance test cycle at $(date)"
    ./run_performance_tests.sh all
    echo "Sleeping for 1 hour..."
    sleep 3600
done

Support

For issues or questions:

  1. Check MariaDB error logs: /var/log/mysql/error.log
  2. Monitor system resources: htop, iotop, free -h
  3. Review MariaDB performance schema
  4. Adjust script parameters based on your system capabilities

Note: This test suite is designed for database performance evaluation and should be used in controlled test environments only.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published