Slow vagrant box, how to improve this?

前端 未结 7 932
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 05:21

We\'ve built a vagrant box for our development box and we are facing some latency issues.

Issues:

  • Assetic:watch is being slow
  • Ove
相关标签:
7条回答
  • 2021-02-06 05:48
    • 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.
    0 讨论(0)
  • 2021-02-06 05:49

    You need also to don't share vendor folder between host and vagrant, if you are doing that. Because reading of shared files are slow. Take look at this link. In order to do that you will need to change composer.json file inside you symfony2 project :

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

    and also change app/autoload.php.

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

    After doing that run composer install.

    There are also some resources for reading :

    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
    0 讨论(0)
  • 2021-02-06 05:50

    If you work with Phpstorm you can use deployement module to syncing files from base machine to virtual

    Then every change on local machine will upload file to virtual machine. This will shoot up your performance. I tried a lot of solutions, but every was not enough for me such as. move cache folder away, unshare vendor folder...

    0 讨论(0)
  • 2021-02-06 06:00

    For any googlers out there:

    In the file .env

    CACHE_DRIVER=memcached
    

    (Instead of CACHE_DRIVER=array)

    Very slow laravel homestead/vagrant/virtualbox on Mac OSX

    0 讨论(0)
  • 2021-02-06 06:07

    Late to the game. For newcomers there are 2 plugins which will increase the speed of the vagrant box right of the bat.

    vagrant-cachier

    Installation Make sure you have Vagrant 1.4+ and run: vagrant plugin install vagrant-cachier

    Vagrant-faster

    vagrant plugin install vagrant-faster
    

    I'm also using MySQL-tuner-perl which is quite good for MySQL fine tuning.

    I hope it helps

    0 讨论(0)
  • 2021-02-06 06:10

    For the test you can try to boot a vagrant without auto sync option for a shared folder, e.g. :

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

    now you will experience the vagrant (web app) maximum speed, everything should be at least twice faster. But now nothing is synced between a host and the virtual machine.

    Now you just add specific folders "without disabled: true" where development is taking place "src", "public", "tests" etc. and now speed should be very similar as first test, e.g. :

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

    Folders with many files like ".git", "vendor", "node_modules", etc. really slow down a vagrant performance.

    My phpunit tests lasted 12 minutes before that optimization and 4.5 min after this optimization (win host)

    Enjoy.

    For reference here is my config for homestead (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"
    
    0 讨论(0)
提交回复
热议问题