Increasing Vagrant performance (synced folders)

vagrant

I have started development of PHP web apps with Vagrant and consider that it is a great way to go, but one thing that is annoying - poor performance of web application inside Vagrant.
The reason is slow performance of disk system in shared/synced folders.

Default VM Shared Folders

By default when you configure Vagrant like
config.vm.synced_folder "./", "/var/www"
it uses a standard VirtualBox synced folders mechanism, but it is slow. And you see it as a long response time for a web app (mostly it is because of autolading classes and all hard disk related operations).

There are couple ways to handle it :

rsync

If to change sync configuration to rsync
config.vm.synced_folder "./", "/var/www", type: "rsync"
then vagrant reload
it will not mount synced folder, but will make initial sync of files to local VB storage. And the interesting thing is that VB virtual file system is very fast (unlike shared) and you will see blazing fast performace of app.

But there are tricky places :

  • to make automatic sync of changes on Host system to VB you need to run vagrant rsync-auto each time you are running Vagrant box

  • after each file change it take 2-3 sec. to sync it to VB

  • this sync is one-direction only, you are not able to sync back changes from VB to Host (Vagrant developer considers to implement dual-side sync in future, but currently no)

So currently I consider rsync way as not really universal, but the fastes.

NFS

Another way is to use NFS mounted disk, Vagrant also natively supports it
config.vm.synced_folder "./", "/var/www", type: "nfs"
don't forget vagrant reload

Now it will look in the same way as with Default VB sharing, no need to wait for sync and manually start sync. And performance will be better (but not so good as with rsync).
The only thing - it will not work on Windows and on Linux requires to have NFS packages installe don Host and Vagrant machines.
On Host sudo apt-get install nfs-kernel-server nfs-common portmap.
On Vagrant sudo apt-get install nfs-common portmap.
Also NFS requires Private network (not public or bridget), it should be something like
config.vm.network :private_network, ip: "10.10.11.11"

So after one-time configuration it will work automatically and reliable (this is my choice at the moment for a local development on Linux Host).

Update 2014.08.14 : After some time working on NFS I have faced slowdown once again. In code I have found that mostly it is in functions that uses FS lock. The following config fixed it :
config.vm.synced_folder "./", "/var/www", type: "nfs", nfs_version: "4,nolock"

PHP opcode caching (or similar)

Another speedup option that plays well with above solutions - to use opcode cache in RAM. For PHP there are couple of options APC or Zend Opcache. I am not sure, but for other script languages there could be similar solutions. For example to enable APC on Ubuntu :
~~~ sudo apt-get install php-apc sudo service apache2 restart ~~~ On Vagrant you will see significant PHP application speedup with APC.

Also you can consider this disk performance issue as a good indicator of your app disk usage :) If it is slow on Vagrant - so it is a possible bottleneck on Production.


Read more ...

Fix double Google Chrome icon in Elementary OS Plank

chrome

After recent Google Chrome update I've got it's icon doubled in Plank (one copy is "locked" in dock, "another copy" appears when you launch Chrome).

To fix it you need to modify desktop launcher file
sudo gedit /usr/share/applications/google-chrome.desktop

Inside you can see 3 sections like "[Desktop Entry]", under each add a following line
StartupWMClass=Google-chrome-stable

Then close Chrome, remove icon fron Plank and restart Chrome. Then re-lock icon.

Troubleshooting

If you will get Your profile could not be opened correctly error on browser launch - try to kill all Chrome processes (some background one could lock your profile data) by
sudo killall -9 chrome


Yii2 dev digest #8 May-Jun'14

May was a good time for a barbeque and trekking :) So here is a brief digest, hopefully not so much news means more bugfix and docs work from Yii Team towards stable RC.


Read more ...

Try Yii2 with Vagrant VM + Ansible provisioning = Complete readymade virtual server playground

yii vagrant ansible

With nowadays web technologies anybody could try any web product with minimal efforts and completely safe. No more need to install and adjust tons of software, no more fear to ruine your working OS with another one server etc. I was dreaming making sandbox for Yii2 playground with Vagrant and Ansible from the first day I have learned them.
And today is this Day :)

So ... here it is on Github. Go !
And those who is not realy familiar with Vagrant and do not understand what I am talkign about - please read my post about Vagrant, you will love it.

In two words ...

"Try Yii2" provides you with Vagrant file and Ansible provsioning scripts. Vagrant will launch the VirtualBox VM, download OS image, deploy it and then run Ansible. It will set up all needed software inside Linux VM, clone Yii2 project, download test DB and connect it with project. Also Vagrant will modify you hosts file and assign special local domain adresses with VM IP address, so you will be able to access test Yii2 prject by humanreadable local domain name. All these steps will be made completely automatically, just run vagrant up and wait !

Now in details, out of the box you will get...

  • Ubuntu 14.04 64 bit ( + bulk of system soft like mc, curl, etc.)
  • PHP-FPM 5.5 ( + modules intl, gd, xdebug etc.)
  • Nginx 1.6
  • MySQL 5.5
  • Composer
  • phpMyAdmin 4.0
  • Adminer 4.1
  • Redis 2.8 ( + PhpRedis)
  • MongoDB 2.6 ( + php_mongo)
  • PostgreSQL 9.3
  • Sqlite 2.8.17
  • Memcached 1.4 ( + php5_memcached)
  • Imported Sakila DB for playing around
  • And of course Yii2 Advanced Project template imported
  • Local IP loop on Host machine /etc/hosts and Virtual hosts in Nginx already set up too !
  • And... I hope to add even more software in the future

Quick start

It was tested on Ubuntu Linux host machine (But after latest changes, when Ansible was transferred to VM, there is no known issues to run it on Windows)
On other host OSes potentially you will need to change some steps (like the way of Vagrant plugins installation and Terminal usage).
If you have issues on other OSes and have solved it - please send me comments here or on GitHub, to add some solutions to the docs.

Install

  • Virtualbox 4.3+ + VirtualBox Extension Pack
  • Vagrant 1.6+ additional Vagrant modules (optional, but provide full automation) :

  • vagrant plugin install vagrant-hostsupdater

  • vagrant plugin install vagrant-vbguest
  • vagrant plugin install vagrant-cachier

You don't need to have Ansible installed on host machine. It will be installed on VM and self-provisioning will be launched. So it is possible to run everything on Windows machine.

Run

  • Clone this from GitHub
  • Go inside cloned folder (where Vagrantfile is)
  • Run vagrant up.
  • It will start VM creation and Provisioning. Could take some time 15-30 min... Drink coffee and get back for complete virtual server with Yi2 project ready for play !

Read more ...

Learning Git - distributed version control system

git branches

Getting started with Git

Actually I was learning Git with these 2 books

A little bit practice and you do not need more books, you will just use Git, but if you want - here are 2 more fresh books

Are you already in touch with all that stuff ? Than get deeper ...

Git shouldn't be so hard to learn.

Are you getting visual information better or want to have clear representation of all Git operations ?

Interactive tutorials

It will help you to start your Git experiments in an free time (while reading a Git books)

Cheatsheets

it's so much of then allover the Internet, so you always can find more and better

GitHub

Huge list of Git books


Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


Have you noticed? Nowadays nobody is doing a New JavaScript framework 😧 These days are over... Everybody is doing their brand new blockchain 😜