This document provides instructions on how to optimize the DevPerf application for better performance.
The following optimizations have been implemented:
- Route Caching: Routes are now cached for better performance.
- Configuration Caching: Configuration files are cached to reduce file I/O.
- View Caching: Blade views are compiled ahead of time.
- Middleware Optimization: Middleware classes use fully qualified class names.
- Security Headers: Added security headers to all responses.
- Redis for Cache and Session: Configured Redis as the preferred driver for cache and sessions.
- Scheduled Optimization: Added a weekly scheduled task to optimize the application.
To manually optimize the application, run:
php artisan app:optimize
This command will:
- Clear all caches
- Cache configuration
- Cache routes
- Compile views
- Optimize composer autoloader
- Optimize class loader
When deploying to production, the following steps should be taken:
-
Install dependencies with optimized autoloader:
composer install --optimize-autoloader --no-dev
-
Run the optimization command:
php artisan app:optimize
-
Ensure Redis is properly configured in your production environment.
-
Set appropriate environment variables:
APP_ENV=production APP_DEBUG=false CACHE_STORE=redis SESSION_DRIVER=redis QUEUE_CONNECTION=redis
-
Build assets for production:
npm run build
-
Enable content compression on your web server.
-
Utilize a CDN for serving static assets.
- Ensure proper indexes are in place for frequently queried columns.
- Consider adding Redis caching for frequent database queries.
- Run
ANALYZE TABLE
on MySQL/PostgreSQL periodically to update statistics.
Regularly monitor application performance with tools like:
- Laravel Telescope (development)
- Laravel Horizon (for queue monitoring)
- New Relic
- Blackfire.io
- Keep dependencies up to date.
- Periodically clean old log files.
- Prune old records from database where appropriate.
- Monitor queue performance and adjust worker count as needed.