Performance
CQL integrates with Azu's development dashboard to provide database performance monitoring and optimization tools.
N+1 Query Detection
The development dashboard automatically detects N+1 query patterns when CQL is installed.
What is N+1?
N+1 occurs when loading associations triggers separate queries for each record:
# N+1 problem: 1 query for posts + N queries for users
posts = Post.all
posts.each do |post|
puts post.user.name # Query executed for each post
endSolution: Eager Loading
# Single query loads posts with users
posts = Post.preload(:user).all
posts.each do |post|
puts post.user.name # No additional query
endDashboard Integration
When CQL is available, the development dashboard shows:
N+1 Query Alerts: Detected repeated query patterns
Slow Query Log: Queries exceeding threshold
Query Statistics: Execution counts and timing
Database Health Score: Overall performance indicator
Access the dashboard at /_dev in development mode.
Slow Query Detection
Configure slow query threshold:
Logged slow queries appear in the dashboard with:
Query text
Execution time
Stack trace origin
Suggested optimizations
Query Optimization
Use Indexes
Select Only Needed Columns
Batch Processing
Limit Results
Connection Pooling
Configure connection pool for high concurrency:
Pool Size Guidelines
Development
5
Small production
10-15
High traffic
25-50
Per-worker (multi-process)
5-10
Query Caching
Cache frequently-accessed queries:
Cache Invalidation
Monitoring in Production
Query Logging
Metrics Collection
Performance Checklist
Development Dashboard
The Azu development dashboard automatically integrates CQL performance monitoring:
Dashboard features when CQL is available:
Query count per request
Average query time
N+1 detection alerts
Slow query highlighting
Database connection status
Access via /_dev/database in development mode.
Next Steps
Queries - Write efficient queries
Relationships - Optimize association loading
Development Dashboard - Full dashboard documentation
Last updated
Was this helpful?
