Laravel真的这么慢吗? [英] Is Laravel really this slow?
问题描述
我刚刚开始使用Laravel.我几乎还没有编写任何代码,但是我的页面要花近一秒钟的时间加载!
I just started using Laravel. I've barely written any code yet, but my pages are taking nearly a second to load!
当我的无框架应用程序和NodeJS应用程序耗时约2毫秒时,这让我有些震惊. Laravel在做什么?这不是正常行为吗?需要一些微调吗?
This is a bit shocking to me when my framework-less apps and NodeJS apps take ~2ms. What's Laravel doing? This isn't normal behaviour is it? Does it need some fine-tuning?
推荐答案
Laravel实际上不是 那很慢. 500-1000ms是荒谬的;我在调试模式下将时间缩短到20毫秒.
Laravel is not actually that slow. 500-1000ms is absurd; I got it down to 20ms in debug mode.
问题是Vagrant/VirtualBox +共享文件夹.我没意识到他们招致了如此高的表现.我猜是因为Laravel有这么多的依赖项(可加载约280个文件),并且每个文件的读取速度都很慢,所以加起来确实非常快.
The problem was Vagrant/VirtualBox + shared folders. I didn't realize they incurred such a performance hit. I guess because Laravel has so many dependencies (loads ~280 files) and each of those file reads is slow, it adds up really quick.
kreeves向我指出了正确的方向,此博客文章介绍了Vagrant 1.5中的一项新功能,该功能使您可以将文件重新同步到VM中,而不使用共享文件夹.
kreeves pointed me in the right direction, this blog post describes a new feature in Vagrant 1.5 that lets you rsync your files into the VM rather than using a shared folder.
Windows上没有本地rsync客户端,因此您必须使用 cygwin .安装它,并确保选中Net/rsync.将C:\cygwin64\bin
添加到您的路径. [或者您可以在Win10/Bash上安装它]
There's no native rsync client on Windows, so you'll have to use cygwin. Install it, and make sure to check off Net/rsync. Add C:\cygwin64\bin
to your paths. [Or you can install it on Win10/Bash]
Vagrant引入了新功能.我正在使用Puphet,所以我的Vagrantfile看起来有点有趣.我不得不对其进行调整以使其看起来像这样:
Vagrant introduces the new feature. I'm using Puphet, so my Vagrantfile looks a bit funny. I had to tweak it to look like this:
data['vm']['synced_folder'].each do |i, folder|
if folder['source'] != '' && folder['target'] != '' && folder['id'] != ''
config.vm.synced_folder "#{folder['source']}", "#{folder['target']}",
id: "#{folder['id']}",
type: "rsync",
rsync__auto: "true",
rsync__exclude: ".hg/"
end
end
设置完毕后,请尝试vagrant up
.如果一切顺利,您的计算机应启动,并应复制所有文件.您需要在终端中运行vagrant rsync-auto
,以使文件保持最新状态.您需要支付一点延迟,但是值得将页面加载速度提高30倍!
Once you're all set up, try vagrant up
. If everything goes smoothly your machine should boot up and it should copy all the files over. You'll need to run vagrant rsync-auto
in a terminal to keep the files up to date. You'll pay a little bit in latency, but for 30x faster page loads, it's worth it!
如果您使用的是PhpStorm,它的自动上传功能甚至比rsync更好. PhpStorm创建了许多临时文件,这些文件可以使文件查看器跳闸,但是如果您让它自己处理上传的文件,则它将很好地工作.
If you're using PhpStorm, it's auto-upload feature works even better than rsync. PhpStorm creates a lot of temporary files which can trip up file watchers, but if you let it handle the uploads itself, it works nicely.
另一种选择是使用 lsyncd .我在Ubuntu主机-> FreeBSD guest虚拟机上使用它取得了很大的成功.我还没有在Windows主机上尝试过它.
One more option is to use lsyncd. I've had great success using this on Ubuntu host -> FreeBSD guest. I haven't tried it on a Windows host yet.
这篇关于Laravel真的这么慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!