英文:
Performance Issue on Laravel 9 Application Using TALL Stack (not in Docker or WSL)
问题
我面临着在我的Laravel 9和10应用程序上严重性能问题。我正在使用TALL堆栈(Tailwind,Alpine,Livewire,Laravel),我注意到加载我的资产时存在显着的延迟,我很难解释。
具体来说,如果我将JS和CSS文件放在'vendor'目录中,每个文件大约需要2秒才能加载。然而,如果我手动将这些文件移动到'public'目录,加载时间会显着提高。
这个问题在我的开发环境(PHP FPM 8.1.2,Nginx,Valet Linux,Ubuntu 22.04(不在虚拟机中),Intel Core i5,16Go RAM,SSD M.2 NVMe)和生产环境(PHP FPM 8.2,Apache,Debian 11)都存在,即使进行了cache:view、cache:config等操作后也存在。
作为临时解决方案,我将文件移到了public文件夹,但应用程序本身(除了资产)加载也需要大约2秒。这使得使用Livewire使应用程序具有响应性而不会出现每次2秒左右的表单刷新延迟非常具有挑战性。
从"vendor"目录加载:
/admin/oncalls ████████████████████████████ 1.54秒
/livewire/livewire.js ██████████████████████████████ 1.54秒
/filament/assets/app.js █████████████████████████████ 1.37秒
/filament/assets/echo.js ██████████████████████████████████████████████ 2.32秒
从"public"目录加载:
/admin/oncalls ████████████████████████████ 1.54秒
/livewire/livewire.js █ 9毫秒
/filament/assets/app.js █ 6毫秒
/filament/assets/echo.js █ 6毫秒
应用程序加载时间问题似乎与数据库查询无关,因为Laravel Debugbar显示查询速度很快。
内存使用似乎相当高。不知道如何找出原因。
访问权限似乎也不是问题
drwxrwxr-x 81 david david 4096 mai 17 10:30 vendor
drwxrwxr-x 5 david david 4096 mai 25 13:44 public
我已经寻找解决方案好几个月了,但没有结果。
为了提供更多细节,我添加了从Clockwork显示的xdebug分析:
这是截断的,因为耗时的部分显示在顶部,但如果需要理解问题,我会添加其余部分。
我查看了vendor目录,找到了uasort()在/vendor/symfony/finder/Iterator/SortableIterator.php的getIterator()方法中被调用并在第105行进行了注释,加载时间从2.36秒降低到0.935秒。
回溯显示,是Filament间接调用它:
vendor/symfony/finder/Iterator/SortableIterator.php:116
Composer\Autoload\includeFile
Composer/Autoload/ClassLoader:428
loadClass
Symfony/Component/Finder/Finder:454
sortByName
Illuminate/Filesystem/Filesystem:599
allFiles
Filament/FilamentServiceProvider:152
registerComponents
非常感谢您提供的任何见解或建议。提前感谢您。
英文:
I am facing serious performance issues on my Laravel 9 and 10 applications. I'm using a TALL stack (Tailwind, Alpine, Livewire, Laravel), and I've noticed significant lag when loading my assets, which I'm struggling to explain.
Specifically, each of my JS and CSS files take approximately 2 seconds to load if I keep them in the 'vendor' directory. However, if I manually move these files to the 'public' directory, the load times improve significantly.
This issue occurs both in my development environment (PHP FPM 8.1.2, Nginx, Valet Linux, Ubuntu 22.04 (not in a VM), Intel Core i5, 16Go RAM, SSD M.2 NVMe) and in production (PHP FPM 8.2, Apache, Debian 11) even after cache:view, cache:config, etc.
As a temporary solution, I've moved the files to the public folder, but the application itself (excluding assets) also takes about 2 seconds to load. This makes it challenging to make it responsive with Livewire without experiencing form refresh delays of around 2 seconds each.
Loading from "vendor" directory :
/admin/oncalls ████████████████████████████ 1.54s
/livewire/livewire.js ██████████████████████████████ 1.54s
/filament/assets/app.js █████████████████████████████ 1.37s
/filament/assets/echo.js ███████████████████████████████████████████████ 2.32s
Loading from "public" directory :
/admin/oncalls ████████████████████████████ 1.54s
/livewire/livewire.js █ 9ms
/filament/assets/app.js █ 6ms
/filament/assets/echo.js █ 6ms
The application loading time issue doesn't seem to be related to database queries since the Laravel Debugbar shows rapid queries.
Memory usage seems quite high however. Don't know how to find out why is that so high.
Access right do not seems to be the problem either
drwxrwxr-x 81 david david 4096 mai 17 10:30 vendor
drwxrwxr-x 5 david david 4096 mai 25 13:44 public
I've been looking for a solution for several months now but to no avail.
In order to bring more details, I add this xdebug profiling displayed from Clockwork :
Its truncated because the time consumming part is displayed on top but if the rest of the list is necessary to understand the problem I will add it.
I looked into the vendor dir to find where is uasort() called and commented it in /vendor/symfony/finder/Iterator/SortableIterator.php in the method getIterator() at line 105 and the loading time dropped from 2.36s to 0.935s.
The backtrace shows that it is Filament that calls it indirectly :
vendor/symfony/finder/Iterator/SortableIterator.php:116
Composer\Autoload\includeFile
Composer/Autoload/ClassLoader:428
loadClass
Symfony/Component/Finder/Finder:454
sortByName
Illuminate/Filesystem/Filesystem:599
allFiles
Filament/FilamentServiceProvider:152
registerComponents
Any insights or suggestions would be greatly appreciated. Thank you in advance.
答案1
得分: 0
"php artisan icons:cache" 解决了这个问题。感谢Clément Baconnier提供的解决方案。
英文:
php artisan icons:cache
solved the problem. Thank you Clément Baconnier for the solution.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论