慢流浪盒,如何改善这一点?

时间:2016-01-11 19:50:13

标签: php performance symfony vagrant

我们为开发盒构建了一个流浪盒,我们面临着一些延迟问题。

的问题:

  • 资产:手表很慢
  • (app_dev.php)中的整体应用程序访问速度很慢
  • 使用"找到"流浪盒上共享文件夹中的命令超级慢

关于包装盒:

  • 在虚拟机上运行(在Mac和Linux上运行)
  • LAMP env(ubuntu)
  • 大代码库(10K +文件)
  • Symfony 2 application

为改善绩效所做的事情:

  • 使用NTFS(使用bindfs)
  • Vagrant configs:
  

config.vm.synced_folder"#{文件夹['来源']}"," / mnt / vagrant - #{i}",   id:"#{i}",输入:' nfs',mount_options:[' rw',' vers = 3',& #39; tcp',' fsc'   '成了actimeo = 2']

  • 将缓存和日志移出共享文件夹(AppKernel更新)

我们可以清楚地看到,无论何时访问共享文件夹中的文件," bindfs"进程正在吃很多cpu。

首先是正常的吗?我希望流浪汉能够在盒子上复制文件,无论何时访问这些文件都是在本地完成的。

我们可以看到盒子本身工作正常,因为当访问缓存数据(共享文件夹之外)时,事情进展得足够快,那么我该怎么做才能提高盒子性能并避免这些延迟问题呢?

8 个答案:

答案 0 :(得分:3)

如果您这样做,您还需要在主机和流浪者之间不共享供应商文件夹。因为共享文件的读取速度很慢。看看这个link。 为此,您需要在symfony2项目中更改composer.json文件:

"config": {
  ...,
  "vendor-dir": "/some_new_location/vendor"
},

并更改app/autoload.php

$loader = require '/some_new_location/vendor/autoload.php';

完成后运行composer install。

还有一些阅读资源:

  1. http://www.erikaheidi.com/blog/optimizing-symfony-applications-on-vagrant-boxes/
  2. http://www.whitewashing.de/2013/08/19/speedup_symfony2_on_vagrant_boxes.html
  3. Symfony2 Slow Initialization Time

答案 1 :(得分:3)

比赛结束。对于新手来说,有2个插件可以提高蝙蝠右边的流浪盒的速度。

vagrant-cachier

安装 确保您拥有Vagrant 1.4+并运行:vagrant plugin install vagrant-cachier

Vagrant-faster

vagrant plugin install vagrant-faster

我也在使用MySQL-tuner-perl,这对于MySQL微调非常有用。

我希望它有所帮助

答案 2 :(得分:1)

如果您使用Phpstorm,您可以使用deployement模块将文件从基本机器同步到虚拟

然后本地计算机上的每次更改都会将文件上传到虚拟机。这会打击你的表现。我尝试了很多解决方案,但对我来说,每一个都是不够的。移动缓存文件夹,取消共享供应商文件夹......

答案 3 :(得分:0)

  • consider allowing the VM to use one or two additional CPU core. This can be controlled from virtualbox gui interface or with a vagrant config. See bottom of this page https://www.vagrantup.com/docs/virtualbox/configuration.html

  • make sure your VM is running on a SSD drive (if budget is ok with that)

  • If you have xdebug enabled or xdebug profiling enabled in your php.ini, it can slow down php. We noticed a real performance improvement when disabling xdebug.remote_autostart on our vagrant boxes where I work. This does force your to start debugging sessions differently though.

答案 4 :(得分:0)

使用NFS时,在共享目录中创建大量文件非常慢。作为一种解决方法   - 将您的vagrant供应商文件夹更改为非共享文件夹

"config": {
  "bin-dir": "bin",
  "secure-http" : false,
  "vendor-dir" : "/vendor"
},

- 在应用程序文件夹中创建一个符号链接,因为构建过程的某些部分可能通过相对链接引用vendor / bin目录

project-dir$ sudo ln -s /vendor vendor
  • 安装作曲家,这会快得多

  • Zip / vendor文件夹并将zip压缩到NFS共享项目文件夹

  • 通过主机提取拉链
  • 再次运行composer install以确保其不再下载文件

答案 5 :(得分:0)

对于该测试,您可以尝试为共享文件夹引导一个没有自动同步选项的无业游民,例如:

config.vm.synced_folder "./", "/home/vagrant/APP/", disabled: true

现在您将体验到流浪者(Web应用程序)的最大速度,一切应该至少快两倍。但是现在主机与虚拟机之间没有任何同步。

现在,您只需添加特定的文件夹“不禁用:true” ,即可在其中进行开发的“ src”,“ public”,“ tests”等,现在速度应该与首次测试非常相似,例如:

config.vm.synced_folder "./src", "/home/vagrant/APP/src", disabled: true
config.vm.synced_folder "./public", "/home/vagrant/APP/public", disabled: true

包含许多文件的文件夹,例如“。git” “供应商” “ node_modules” 等,确实降低了流浪汉的性能

我的phpunit测试在该优化之前持续了12分钟,在优化之后持续了4.5分钟(获胜主机)

享受。

作为参考,这是我的宅基地(laravel)配置:

folders:
 - map: "./"
   to: "/home/vagrant/APP"
   type: "nfs"
   options:
     disabled: true
 - map: "./app"
   to: "/home/vagrant/APP/app"
   type: "nfs"
 - map: "./resources"
   to: "/home/vagrant/APP/resources"
   type: "nfs"
 - map: "./routes"
   to: "/home/vagrant/APP/routes"
   type: "nfs"
 - map: "./tests"
   to: "/home/vagrant/APP/tests"
   type: "nfs"
 - map: "./public"
   to: "/home/vagrant/APP/public"
   type: "nfs"

答案 6 :(得分:0)

对于任何谷歌员工:

在.env文件中

CACHE_DRIVER=memcached

(而不是 CACHE_DRIVER=array)

Very slow laravel homestead/vagrant/virtualbox on Mac OSX

答案 7 :(得分:0)

这些问题主要与vbfs的性能有关,vbfs是VirtualBox中使用的默认文件系统。根据我的经验,在继续测试 NFS 之前,加快速度的最佳方法是更新虚拟机中的 Guest Additions。最简单的方法是使用 vagrant-vbguest 插件,它会在后台更新 GA。我的编辑速度提高了三倍。

要在 Vagrant 中使用它,请编辑文件并将其添加到开头:

# NOTE: Auto-install vagrant plugins
required_plugins = %w(vagrant-vbguest)

plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
    puts "Installing plugins: #{plugins_to_install.join(' ')}"
    if system "vagrant plugin install #{plugins_to_install.join(' ')}"
        exec "vagrant #{ARGV.join(' ')}"
    else
        abort "Installation of one or more plugins has failed. Aborting."
    end
end
相关问题