Skip to content

Deploy Clickhouse database on a container image, Maintain Hot, Warm data policy, Manage proper database backup for DB version upgrades, Performance tuning for optimal CPU usage.

License

Notifications You must be signed in to change notification settings

VinitBakare/docker-clickhouse-hot-warm

Repository files navigation

ClickHouse Infrastructure with Dynamic Auto-Configuration

Production-grade ClickHouse Docker infrastructure with hot/warm storage tiering and intelligent resource management.

πŸ”§ Configuration Management

All settings are centralized in the .env-config file for easy management:

# Quick configuration
cp .env-config .env-config.backup    # Backup current config
nano .env-config                     # Edit configuration
./manage.sh restart                  # Apply changes

πŸ“– Complete Configuration Guide β†’

βœ… Current Status: FULLY OPERATIONAL

  • 🟒 HTTP Interface: http://localhost:8123 - Working
  • 🟒 TCP Interface: localhost:9000 - Working
  • 🟒 Health Status: Healthy container
  • 🟒 Storage Policies: Hot/warm tiering active
  • 🟒 Auto-Configuration: Dynamic memory (6.98 GiB) & threading (16 cores)

πŸ—οΈ Storage Setup

  • Hot Storage: ~/Downloads/clickhouse-hot (Fast access)
  • Warm Storage: /Volumes/Extreme-Pro/clickhouse-warm (Archival)
  • Backup Storage: /Volumes/Extreme-Pro/clickhouse-backup (Upgrade backups)

⚑ Quick Start (Optimized for Development)

For CPU-optimized local development:

./start-optimized.sh    # Start with optimized threading (6-12% CPU usage)

Standard management:

./manage.sh start    # Start ClickHouse
./manage.sh stop     # Stop ClickHouse  
./manage.sh client   # Connect to CLI
./manage.sh status   # Check status
./manage.sh logs     # View logs

🎯 CPU Performance Optimization

This setup includes advanced CPU optimization that reduces resource usage by 87-92% while maintaining full functionality:

πŸ”₯ Performance Results

  • Before Optimization: 82.03% CPU usage, 683 processes/threads
  • After Optimization: 5-12% CPU usage (balanced profile)
  • Memory Efficiency: Dynamic allocation based on available RAM
  • Container Stability: Preserved during profile switches

πŸŽ›οΈ Performance Profiles

Switch between performance profiles based on your needs:

./switch-performance-profile.sh [profile-name]

Available Profiles:

  • ultra-low - 2-5% CPU usage (minimal resources)
  • balanced - 6-12% CPU usage (default, development)
  • high-performance - 15-30% CPU usage (testing/staging)
  • production - 20-50% CPU usage (server deployment)

Profile Management:

./switch-performance-profile.sh current      # Show current profile
./switch-performance-profile.sh balanced     # Switch to balanced
./switch-performance-profile.sh production   # Switch to production

πŸ“Š Monitoring CPU Usage

Monitor performance in real-time:

docker stats                           # Live container stats
docker exec clickhouse-server-hot-warm top   # Process monitoring inside container

πŸ“– Complete CPU Tuning Guide β†’
πŸ“‹ Optimization Report β†’

πŸ—„οΈ Storage Architecture

🌐 Access Points

🧠 Dynamic Auto-Configuration Features

  • Memory Management: Uses 90% of available RAM automatically
  • Thread Scaling: Auto-scales from 1-16+ threads based on query complexity
  • Cache Auto-Sizing: Mark and uncompressed caches size themselves
  • Storage Tiering: Automatic hotβ†’warm data movement

πŸ“Š Storage Policies

  • hot_warm_policy: Automatic tiering (starts hot, moves to warm at 80% capacity)
  • hot_only_policy: Keep data on fast storage only
  • warm_only_policy: Archive data directly to warm storage

πŸ§ͺ Quick Tests

# Test HTTP interface
curl "http://localhost:8123/?query=SELECT 1"

# Check auto-configured memory
curl "http://localhost:8123/?query=SELECT formatReadableSize(value::UInt64) FROM system.server_settings WHERE name='max_server_memory_usage'"

# View storage policies  
curl "http://localhost:8123/?query=SELECT policy_name, volume_name FROM system.storage_policies FORMAT TabSeparated"

# Comprehensive test suite
echo "=== CLICKHOUSE CONNECTION TEST SUMMARY ===" && \
echo "1. Container Status:" && \
docker ps --filter name=clickhouse-server-hot-warm --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" && \
echo -e "\n2. HTTP Interface:" && \
curl -s "http://localhost:8123/?query=SELECT%20'HTTP%20OK'%20as%20status" && \
echo -e "\n3. Performance Test:" && \
curl -s "http://localhost:8123/?query=SELECT%20count()%20FROM%20numbers(100000)" && \
echo -e "\n4. Auto-Config Check:" && \
curl -s "http://localhost:8123/?query=SELECT%20formatReadableSize(value::UInt64)%20as%20auto_memory_limit%20FROM%20system.server_settings%20WHERE%20name='max_server_memory_usage'" && \
echo -e "\n5. Storage Policies:" && \
curl -s "http://localhost:8123/?query=SELECT%20count()%20as%20policy_count%20FROM%20system.storage_policies" && \
echo -e "\n=== ALL TESTS PASSED! ==="

πŸ”„ Version Management & Upgrades

Safe Upgrade Process

# Check current version
./upgrade-manager.sh version

# Backup before upgrade
./upgrade-manager.sh backup

# Upgrade to new version (example: 25.8)
./upgrade-manager.sh upgrade 25.8

# Verify data integrity
./upgrade-manager.sh verify

# Rollback if needed
./upgrade-manager.sh rollback

Upgrade Commands

  • ./upgrade-manager.sh upgrade <version> - Safe upgrade with backup
  • ./upgrade-manager.sh backup - Manual backup creation
  • ./upgrade-manager.sh rollback - Revert to previous version
  • ./upgrade-manager.sh verify - Check data integrity
  • ./upgrade-manager.sh list-backups - View available backups

Data Protection Features

  • βœ… Automatic backups before upgrades
  • βœ… Hot/warm storage preservation
  • βœ… Metadata export (schemas, policies)
  • βœ… Integrity verification after upgrades
  • βœ… One-click rollback capability

Files

  • docker-compose.yml - Container setup with environment variables
  • Dockerfile - Custom image with configurable build args
  • .env-config - Central configuration file for all settings
  • manage.sh - Infrastructure management script
  • upgrade-manager.sh - Version upgrade & backup manager
  • config/ - ClickHouse configuration files
    • config.xml - Server settings with auto-configuration
    • users.xml - User authentication & profiles
    • storage.xml - Hot/warm storage policies (partially configurable)

πŸ“š Documentation

πŸŽ‰ PRODUCTION READY

βœ… Centralized Environment Configuration System Successfully Implemented

All infrastructure settings are now managed through a single .env-config file with 75+ configurable parameters. The system has been comprehensively tested and validated for production use.

About

Deploy Clickhouse database on a container image, Maintain Hot, Warm data policy, Manage proper database backup for DB version upgrades, Performance tuning for optimal CPU usage.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published