Your current benchmark of 70 requests per second (using ab -n 1000 -c 100
) for a database-heavy page is a solid starting point. Let's break down what this means:
# Sample Apache Benchmark command
ab -n 1000 -c 100 http://yourserver.com/data-intensive-page/
When testing database-intensive operations, we typically look at:
- Query optimization (EXPLAIN ANALYZE in SQL)
- Connection pooling configuration
- Indexing strategies
- ORM efficiency (if applicable)
For a production environment, consider these factors:
// Example Node.js connection pooling setup
const pool = new Pool({
user: 'dbuser',
host: 'database.server.com',
database: 'mydb',
password: 'secretpassword',
port: 5432,
max: 20, // Maximum number of clients in pool
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
});
Here are concrete ways to improve your RPS:
- Caching strategies:
# Redis cache implementation example import redis r = redis.Redis(host='localhost', port=6379, db=0) def get_data(key): cached_data = r.get(key) if cached_data: return cached_data else: data = db_query(key) r.setex(key, 3600, data) # Cache for 1 hour return data
- Database optimization:
-- Example optimized SQL with proper indexing CREATE INDEX idx_user_activity ON user_logs (user_id, activity_date); EXPLAIN ANALYZE SELECT * FROM user_logs WHERE user_id = 123 AND activity_date > NOW() - INTERVAL '7 days';
When conducting load tests:
- Test with production-like data volumes
- Monitor both application and database metrics
- Gradually increase load to identify breaking points
# Extended load test with locust
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 5)
@task
def load_data_page(self):
self.client.get("/data-intensive-page/")
Before going live, ensure you have:
- Proper monitoring (New Relic, Datadog, etc.)
- Horizontal scaling capability
- Database replication setup
- CDN configuration for static assets
When load testing a web server handling database-intensive operations, the 70 requests/second benchmark you're seeing with ab
(ApacheBench) is a solid starting point for development. However, production environments require deeper analysis. Let's break this down pragmatically.
Your test involving 4 table joins with data manipulation suggests the 70 RPS is likely constrained by database I/O. Here's a typical MySQL query pattern that could cause similar behavior:
SELECT users.*, orders.*, products.*, invoices.*
FROM users
JOIN orders ON users.id = orders.user_id
JOIN products ON orders.product_id = products.id
JOIN invoices ON orders.invoice_id = invoices.id
WHERE users.status = 'active'
The 100 concurrent connections in your test represent burst traffic patterns. For production planning, consider:
- Peak hour traffic projections
- Session duration patterns
- Background job overhead
Before concluding about your server capacity:
# More comprehensive load test command
ab -k -c 200 -n 5000 -H "Accept-Encoding: gzip" http://yourserver.com/heavy-page
Key parameters to monitor during tests:
- Database connection pool saturation
- CPU wait times (iowait)
- Query cache hit ratio
For database-heavy applications like yours, these optimizations often help:
# Example Redis caching layer implementation
const cache = require('redis').createClient();
const cacheTTL = 300; // 5 minutes
app.get('/heavy-page', async (req, res) => {
const cacheKey = 'heavy-page-data';
let data = await cache.get(cacheKey);
if (!data) {
data = await complexDatabaseQuery();
cache.setex(cacheKey, cacheTTL, JSON.stringify(data));
}
res.render('page', { data: JSON.parse(data) });
});
When your RPS needs to grow beyond single-server limits:
- Implement read replicas for MySQL
- Consider connection pooling with PgBouncer for PostgreSQL
- Offload static assets to CDN
Essential metrics to track post-launch:
# Sample Prometheus query for request rate
rate(http_requests_total{path="/heavy-page"}[5m])
Remember that optimal RPS varies dramatically based on your specific stack, query complexity, and infrastructure choices. The 70 RPS benchmark indicates a reasonably performant application, but production monitoring will reveal the true capacity requirements.