Aleksey Razbakov
Aleksey Razbakov

Reputation: 634

PHP on Vagrant VirtualBox on Linux is 10 times slower then PHP on Linux

I used php-benchmark-script to check php benchmark on (a) Ubuntu Linux and (b) Vagrant with Ubuntu Linux running on the same Ubuntu Linux and (c) Vagrant on My Mac

For vagrant I use this configuration.

(a) Ubuntu Linux

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
PHP version : 5.5.23-1+deb.sury.org~precise+2
Platform : Linux
--------------------------------------
test_math                 : 0.969 sec.
test_stringmanipulation   : 1.028 sec.
test_loops                : 0.709 sec.
test_ifelse               : 0.589 sec.
--------------------------------------
Total time:               : 3.295 sec.

(b) Vagrant with Ubuntu Linux running on the same Ubuntu Linux

no vm.synced_folder

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
PHP version : 5.5.9-1ubuntu4.11
Platform : Linux
--------------------------------------
test_math                 : 17.078 sec.
test_stringmanipulation   : 15.038 sec.
test_loops                : 1.468 sec.
test_ifelse               : 1.790 sec.
--------------------------------------
Total time:               : 35.374 sec.

(c) Vagrant on My Mac:

vm.synced_folder: type: "nfs"

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
PHP version : 5.5.9-1ubuntu4.11
Platform : Linux
--------------------------------------
test_math                 : 2.849 sec.
test_stringmanipulation   : 2.631 sec.
test_loops                : 1.614 sec.
test_ifelse               : 1.760 sec.
--------------------------------------
Total time:               : 8.854 sec.

What should I do to make it work faster?


hypernode benchmarks

(d) hypernode on vagrant on ubuntu:

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
PHP version : 5.4.26-1~ppa1~precise
Platform : Linux
--------------------------------------
test_math                 : 1.004 sec.
test_stringmanipulation   : 1.111 sec.
test_loops                : 0.591 sec.
test_ifelse               : 0.609 sec.
--------------------------------------
Total time:               : 3.315 sec.

(e) hypernode on vagrant on mac:

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
PHP version : 5.4.26-1~ppa1~precise
Platform : Linux
--------------------------------------
test_math                 : 1.041 sec.
test_stringmanipulation   : 1.064 sec.
test_loops                : 0.650 sec.
test_ifelse               : 0.636 sec.
--------------------------------------
Total time:               : 3.391 sec.

With hypernode benchmarks are better. But Magento loading time is still not so good. And I don't know which script to use to show how to reproduce the speed issue.

Upvotes: 2

Views: 542

Answers (1)

Ivan Chepurnyi
Ivan Chepurnyi

Reputation: 9233

Seems, that your are using badly configured vagrant box on your system. E.g. no optimized virtualization, low memory, not all CPUs are shared.

I got absolutely different results on my own machine:

OSX Yosemite, PHP5.5

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
Start : 2015-07-31 11:42:45
Server : @
PHP version : 5.5.24
Platform : Darwin
--------------------------------------
test_math                 : 1.078 sec.
test_stringmanipulation   : 1.514 sec.
test_loops                : 0.813 sec.
test_ifelse               : 0.695 sec.
--------------------------------------
Total time:               : 4.1 sec.

Vagrant Box (nfs server is on guest OS) Ubuntu, PHP5.4

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
Start : 2015-07-31 11:43:28
Server : @
PHP version : 5.4.26-1~ppa1~precise
Platform : Linux
--------------------------------------
test_math                 : 1.143 sec.
test_stringmanipulation   : 1.171 sec.
test_loops                : 0.728 sec.
test_ifelse               : 0.642 sec.
--------------------------------------
Total time:               : 3.684 sec.

I have such a configuration of Vagrantfile:

VAGRANTFILE_API_VERSION = "2"
BOX_NAME='project'
HOSTNAME="#{BOX_NAME}.box"
ALIASES=%w(subdomain.project.box subdomain2.project.box)
ALIASES << HOSTNAME

%w(vagrant-hostmanager vagrant-nfs_guest vagrant-auto_network).each do |plugin|
  unless Vagrant.has_plugin?(plugin)
    raise 'In order to use this box, you must install plugin: ' + plugin
  end
end

AutoNetwork.default_pool = '33.33.33.0/24'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.forward_agent = true
  config.vm.provider 'virtualbox' do |vb|
    # Clean up network interface after tests.
    vb.destroy_unused_network_interfaces = true
  end

  config.vm.box = "hypernode"
  config.vm.box_url = "http://vagrant.hypernode.com/catalog.json"

  config.vm.provision "shell", path: "vagrant/provisioning/hypernode.sh"
  config.vm.provision "shell", path: "vagrant/provisioning/project.sh"

  config.vm.synced_folder '.', '/vagrant/', disabled: true

  if Vagrant.has_plugin?("vagrant-nfs_guest")
     config.vm.synced_folder 'server', '/data/web', type: 'nfs_guest', create: true,
        linux__nfs_options: ["rw", "no_subtree_check", "all_squash", "insecure", "async"],
        map_uid: Process.euid, map_gid: Process.egid
  end

  if Vagrant.has_plugin?("vagrant-hostmanager")
    config.hostmanager.enabled = true
    config.hostmanager.manage_host = true
    config.hostmanager.ignore_private_ip = false
    config.hostmanager.include_offline = true
    config.vm.define 'hypernode' do |node|
      node.vm.hostname = "#{BOX_NAME}.hypernode.box"
      node.vm.network :private_network, auto_network: true
      node.hostmanager.aliases = ALIASES
    end
  end
end

You can find more info on a vagrant box I am using at the following url: https://github.com/ByteInternet/hypernode-vagrant

This box has been developed by ByteInternet from a subset of their hosting environment configurations, optimized out of the box for Magento.

Upvotes: 2

Related Questions