Performance Monitoring
What You'll Learn
Prerequisites
Step 1: Enable Query Logging
# src/database.cr
require "log"
# Configure logging
Log.setup do |c|
backend = Log::IOBackend.new
c.bind("cql.*", :debug, backend)
end
AppDB = CQL::Schema.define(
:app_db,
adapter: CQL::Adapter::Postgres,
uri: DATABASE_URL
) do
endStep 2: Create a Query Monitor
Step 3: Wrap Database Operations
Step 4: Detect N+1 Queries
Solution: Eager Loading
Step 5: Create a Dashboard
Step 6: Monitor in Tests
Step 7: Production Monitoring
Optimization Checklist
1. Add Missing Indexes
2. Use Select to Limit Columns
3. Batch Large Operations
4. Cache Expensive Queries
Summary
Next Steps
Last updated
Was this helpful?