Permalink
Browse files

Dynamically set memory size to 2/3 of RAM. Use only one CPU in the gu…

…est image, since that is faster according to multiple sources.
  • Loading branch information...
1 parent 6ebc1ae commit 6c23bbf92f1394545d7e51485cca6cb51de7bdee @andreasrosdal andreasrosdal committed Nov 12, 2016
Showing with 19 additions and 8 deletions.
  1. +2 −6 README.md
  2. +17 −2 Vagrantfile
View
@@ -74,19 +74,15 @@ a directory on your computer, by running this git command:
```bash
git clone https://github.com/freeciv/freeciv-web.git --depth=10
```
-4. Review memory usage in Vagrantfile. This is configured by the v.memory variable in the
- Vagrantfile. The default is 6 Gb of memory allocated to the server. This value should
- be less than the total free amount of RAM you have.
-
-5. Run Vagrant with the following commands in your Freeciv-web directory from step 3:
+4. Run Vagrant with the following commands in your Freeciv-web directory from step 3:
```bash
vagrant plugin install vagrant-vbguest
vagrant up
```
This will build, compile, install and run Freeciv-web on the virtual server image. Wait for the installation process to complete, watching for any error messages in the logs.
-6. (Skip this step if you run Windows) For Linux or OS X, then you
+5. (Skip this step if you run Windows) For Linux or OS X, then you
need to setup a SSH tunnel to port 80 like this:
```bash
sudo ssh -p 2222 -gNfL 80:localhost:80 vagrant@localhost -i ~/.vagrant.d/insecure_private_key
View
@@ -39,8 +39,23 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
end
config.vm.provider "virtualbox" do |v|
- v.memory = 6000
- v.cpus = "2"
+ v.cpus = "1"
+ host = RbConfig::CONFIG['host_os']
+
+ # Give VM 2/3 system memory
+ if host =~ /darwin/
+ # sysctl returns Bytes and we need to convert to MB
+ mem = `sysctl -n hw.memsize`.to_i / 1024
+ elsif host =~ /linux/
+ # meminfo shows KB and we need to convert to MB
+ mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i
+ elsif host =~ /mswin|mingw|cygwin/
+ # Windows code via https://github.com/rdsubhas/vagrant-faster
+ mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i / 1024
+ end
+
+ mem = mem / 1024 * 2 / 3
+ v.customize ["modifyvm", :id, "--memory", mem]
end
config.vm.synced_folder "./", "/vagrant"

0 comments on commit 6c23bbf

Please sign in to comment.