Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal very slow in Vagrant environment

I've begun migrating a lot of our development environments to Vagrant. So far, this has been great for almost everything, but our first Drupal migration is unusable. It's unbelievably slow. Our Wordpress, CakePHP and Node.js sites all perform very adequately or better, but not Drupal. This think is just awful.

The box is a Veewee-created Ubuntu 12.04 64bit machine. It's the same base box we use for all of our web-based projects so nothing unique there. In my sites directory, I have a canonical directory (sites/my-site/) with all of the site resources and a symlink to that canonical directory with the domain name (sites/dev.mysite.com -> /vagrant/www/sites/my-site) that is evidently required for some module that the team is using.

This is a mixed Windows/OSX dev team and it's slow across both platforms. The only semi-unconventional snippet from my Vagrantfile is this:

config.vm.forward_port 80, 8080

config.vm.share_folder( "v-root", "/vagrant", ".", :extra => 'dmode=777,fmode=777' )

# Allows symlinks to the host directory.
config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]

Vagrant::Config.run do |config|
  config.vm.provision :shell, :path => "provision.vm.sh"
end

My shell provisioner only does a couple of things:

  • Installs drush
  • Creates the aforementioned symlink to the canonical site directory
  • Writes out an Nginx server block
  • If necessary, creates a settings.php file.

Is there anything I can do to improve performance? Like, a lot?

UPDATE

I've narrowed this down to a point where it looks like the issue is the remote database. To compare apples to apples with no project baggage, I downloaded a fresh copy of Drupal 7.21 and performed a standard install from the Vagrant web server against 3 different databases:

  • A new database created on the same Vagrant VM as the webserver (localhost)
  • A new database created on the shared dev server used in the original question (dev)
  • A new database created on an EC2 instance (tmp)

Once that was done, I logged in to the fresh Drupal install and loaded the homepage (localhost:8080) 5 times. I then connected to each database and loaded the same page, the same way. What I found was that the page loaded 4-6x slower when Drupal was connected to the remote database.

Remember, this is a fresh (standard) install. There is no project baggage.

like image 347
Rob Wilkerson Avatar asked Feb 26 '13 15:02

Rob Wilkerson


4 Answers

I am hit by similar problem, too. It seems that VirtualBox shared folder can be very slow for project tree with +1000 files.

Switching to NFS might be the solution.

like image 142
Pomin Wu Avatar answered Oct 31 '22 13:10

Pomin Wu


The issue is almost certainly either skip_name_resolve (being needed in my.cnf) or VirtualBox's poor handling of shared directories with large numbers of files. Both are easy to track down with strace -c, but you may find it easier just to correct them one at a time and see which one fixes your performance issues.

If you're still seeing slowness after both of these changes, let me know and we can debug it further.

like image 40
BMDan Avatar answered Oct 31 '22 13:10

BMDan


I got here via google for similar, so I'm replying in the hopes others find this useful.

If you're using the precise32 vagrant box as your starting point, it's worth noting that the box by default has only 360MB of RAM.

Up the ram (at least in Vagrant V2 with VirtualBox) like so

config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "1024"]
end

This made Drupal much more responsive for me.

like image 4
rwg1138 Avatar answered Oct 31 '22 13:10

rwg1138


It's just a PHP/MySQL app so there's not much special about Drupal besides how it has been customized. You may have done some of this, but here are some suggestions to isolate the issue.

  • Check the Drupal dblog for errors.
  • Check your nginx & php logs for errors.
  • Consider how many active modules you are running (over 100? That would be a very heavy install)
  • Install a fresh Drupal instance & compare. This may isolate the problem to your instance and not Drupal in general.

If you find that it is your instance of Drupal

  • Install the devel module and enable memory reporting so you know how much memory is being used per page load, as well as to have a base line for improvement.
  • Make sure you have APC or another PHP opcache installed, and make sure the hit rate is good. If you weren't running it before, note the memory usage difference reported by devel.
  • run something like xhprof or disable suspicious modules till you find the major offenders.
  • enable mysql slow & index log to find potential issues, then add indexes or take other action appropriately

If your other apps are running fine, I suspect there is a problem with a particular module, or you have a fat Drupal install in general that needs some optimizing or more memory.

like image 3
Coder1 Avatar answered Oct 31 '22 12:10

Coder1