The alian-structure backend includes comprehensive performance monitoring and profiling capabilities to identify bottlenecks, track memory usage, and detect performance regressions. This system builds on top of existing OpenTelemetry tracing and Prometheus metrics to provide deep insights into application performance.
- Capture CPU profiles for any duration (default: 30 seconds)
- Profiles are saved in Chrome DevTools compatible format
- Download and analyze in Chrome's Performance tab
- Automatic tracking of profiling metadata
- Trigger heap snapshots at any time via API
- Captures complete memory state
- Download and analyze in Chrome's Memory tab
- Automatic memory leak detection with alerts
- Middleware-level timing tracking
- Database query duration tracking
- OpenTelemetry spans for full request timeline
- Performance API integration for detailed timings
- Automatic tracking of frequently called functions
- Calculates average and total execution time
- Returns top 20 hottest functions sorted by impact
- Updates in real-time as requests are processed
- Monitors memory usage every 60 seconds
- Triggers warnings when memory exceeds 90% of heap limit
- Sends alerts to Sentry with full memory statistics
- Tracks historical memory usage patterns
- All profiles available for download
- JSON format compatible with standard analysis tools
- Profile metadata includes timestamps and file sizes
- Automatic cleanup capability via API
- Establishes baseline performance on startup
- Continuously compares current metrics against baseline
- Alerts on CPU or memory usage increases >50%
- Sends regression reports to Sentry with context
All profiling endpoints are available under /api/v1/profiling/ and require admin permissions except the UI.
GET /api/v1/profiling/ui- Access the profiling dashboard- Real-time updates every 5 seconds
- Visual interface for all profiling operations
POST /api/v1/profiling/cpu/start?duration=30000- Start CPU profiling- Duration in milliseconds (default: 30000 = 30s)
POST /api/v1/profiling/heap/snapshot- Capture immediate heap snapshot
GET /api/v1/profiling/profiles- List all saved profilesGET /api/v1/profiling/profiles/:id/download- Download profile fileDELETE /api/v1/profiling/profiles/:id- Delete a profile
GET /api/v1/profiling/hot-functions- Get top hot functionsGET /api/v1/profiling/timelines- Get request waterfall dataGET /api/v1/profiling/regressions/check- Check for performance regressionsGET /api/v1/profiling/memory/stats- Get current memory statistics
- Download the
.cpuprofilefile from the dashboard - Open Chrome DevTools > Performance tab
- Click "Load profile..." and select the downloaded file
- Analyze the flame chart to identify bottlenecks
- Download the
.heapsnapshotfile from the dashboard - Open Chrome DevTools > Memory tab
- Load the snapshot to analyze memory retention
- Use the Retainers view to find memory leaks
- Access the dashboard's Request Timelines section
- View all recent requests with their durations
- Identify slow endpoints that need optimization
The system automatically establishes a performance baseline when the application starts:
- Baseline CPU usage (1, 5, 15 minute load averages)
- Baseline memory usage patterns
- Initial metric values from Prometheus
Any significant deviations (>50% increase in CPU, >30% increase in memory) trigger regression alerts.
- All profiling integrates with existing OpenTelemetry tracing
- Request spans include profiling context
- Distributed tracing continues to work alongside profiling
- Builds on existing Prometheus client metrics
- Correlates profiling data with business metrics
- Maintains all existing alerting capabilities
- Performance alerts sent to Sentry
- Memory leak warnings with full context
- Regression tracking for historical analysis
- Endpoints validate profile creation
- Files are properly written to disk
- Metadata tracked accurately
- All profiles use standard formats
- CPU profiles: Chrome DevTools format
- Heap snapshots: V8 heap snapshot format
- Profiling has minimal overhead when inactive
- CPU profiling only runs when explicitly started
- Memory monitoring uses <1% additional resources
- The profiling system is automatically enabled when the application starts
- Access the dashboard at
http://your-server/api/v1/profiling/ui - Start with capturing memory stats to establish a baseline
- Use CPU profiling to investigate slow endpoints
- Monitor the dashboard for automatic regression alerts