MySQL Server Performance: Scaling to Handle 3,000 Queries Per Second for High-Traffic Websites


1 views

When planning for a website expecting 500,000 unique visitors generating 2 million pageviews daily, with each page executing ~50 queries, you're looking at:

  • 100 million queries/day
  • 4 million queries/hour
  • 70,000 queries/minute
  • 1,200 queries/second (average)
  • 3,000 queries/second (peak)

A well-tuned MySQL server on modern hardware can typically handle:

  • Basic configuration: 500-1,000 QPS
  • Optimized single server: 2,000-5,000 QPS
  • Highly-tuned with SSD/NVMe: 10,000-30,000 QPS

For 3,000 QPS peaks, consider these approaches:

# Example my.cnf optimization for high QPS
[mysqld]
innodb_buffer_pool_size = 12G  # 70-80% of RAM
innodb_log_file_size = 2G
innodb_flush_method = O_DIRECT
innodb_read_io_threads = 16
innodb_write_io_threads = 16
query_cache_type = 0
table_open_cache = 4000

For 50,000 QPS, you'll need a distributed architecture:

# Python example for read/write splitting
import mysql.connector
from mysql.connector import pooling

# Master for writes
write_pool = pooling.MySQLConnectionPool(
    pool_name="master_pool",
    pool_size=10,
    host="master.db.example.com",
    user="app_user",
    password="secure_password",
    database="app_db"
)

# Read replicas pool
read_pool = pooling.MySQLConnectionPool(
    pool_name="read_pool",
    pool_size=30,
    host="replica.db.example.com",
    user="app_user",
    password="secure_password",
    database="app_db"
)
  • Dedicated database servers (not shared)
  • 64GB+ RAM for buffer pools
  • NVMe SSDs for storage
  • High-performance network (10Gbps+)

Consider these complementary technologies:

// Redis caching example
const redis = require('redis');
const client = redis.createClient();

async function getCachedData(key) {
  const cached = await client.get(key);
  if (cached) return JSON.parse(cached);
  
  // Fallback to database
  const data = await fetchFromDatabase(key);
  client.setex(key, 3600, JSON.stringify(data));
  return data;
}

When planning for a website expecting 500,000 unique visitors generating 2 million pageviews daily, we face a database throughput challenge. Each page makes ~50 queries, resulting in:

  • 100M queries/day
  • 4M queries/hour
  • 70K queries/minute
  • 1,200 queries/second (average)
  • 3,000 queries/second (peak)

Modern MySQL servers can typically handle:

  • Basic server: 500-1,000 QPS
  • Optimized server: 2,000-5,000 QPS
  • High-end server: 10,000+ QPS

To achieve 3,000 QPS consistently:

Vertical Scaling

A single high-performance server configuration:

# Example my.cnf optimization for high throughput
[mysqld]
innodb_buffer_pool_size = 12G  # 70-80% of RAM
innodb_log_file_size = 2G
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
query_cache_type = 0
table_open_cache = 4000

Horizontal Scaling

For better redundancy and scalability:

# Example read/write splitting configuration
$config = [
    'write' => [
        'host' => 'master.db.example.com'
    ],
    'read' => [
        'host1' => 'replica1.db.example.com',
        'host2' => 'replica2.db.example.com',
        'host3' => 'replica3.db.example.com'
    ]
];

Reduce database load with Redis caching:

// PHP example using Redis cache
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

$cacheKey = "page_data:$pageId";
if (!$data = $redis->get($cacheKey)) {
    $data = $db->query("SELECT * FROM pages WHERE id = ?", [$pageId]);
    $redis->setex($cacheKey, 3600, json_encode($data));
}

Essential optimizations for high throughput:

  • Add proper indexes on frequently queried columns
  • Use EXPLAIN to analyze query execution plans
  • Implement prepared statements
  • Batch operations when possible

Key metrics to watch:

# MySQL performance monitoring queries
SHOW GLOBAL STATUS LIKE 'Questions';
SHOW ENGINE INNODB STATUS;
SHOW PROCESSLIST;

For your scenario, I recommend starting with:

  • 1 powerful master server (16+ cores, 32GB+ RAM, NVMe storage)
  • 2-3 read replicas with similar specs
  • Redis cache cluster
  • Connection pooling (50-100 connections per server)