Wednesday, 17 August 2011 05:25
Written by VladoPortos
Hello all,
In this tutorial we will look at how to put our minecraft server to ramdisk.
Ramdisk is basically a disk that live in your ram, so you will need a lot of ram for this. We will be putting only maps for our servers there so depends on size of your map how much ram you will need.
I’m also going to show this for Ubuntu linux ( probably works the same for other distributions also ).
Advantages:
Speeeeed ! Read and Write speed is much much higher than at normal disks lets see test here:
vladoportos /minecraft $ dd if=/dev/zero of=/dev/shm/test.data bs=1k count=128k
131072+0 records in
131072+0 records out
134217728 bytes (134 MB) copied, 0.155647 s, 862 MB/s
Above you can see that it wrote 134MB with speed 862 MB/s (higher number is better)
and for normal disk:
vladoportos /minecraft $ dd if=/dev/zero of=/minecraft/test.data bs=1k count=128k
131072+0 records in
131072+0 records out
134217728 bytes (134 MB) copied, 0.298504 s, 450 MB/s
you can see that its almost half time slower ( this is 1+0 disk raid ) so putting your maps in ramdisk is very nice boost.
Disadvantages:
- it is volatile memory, meaning that if server get restarted it will clean up
- well an obvious reason, you will need a lots of memory
Very good tutorial is here: http://www.minecraftwiki.net/wiki/Tutorials/Ramdisk_enabled_server
You can basically follow that one and copy maps as they show there to /dev/shm which is basically your ramdisk.
I have created folder /dev/shm/minecraft and put maps there and my normal maps and bukkit files are in /minecraft, this is important to know when you see my scripts.
My words are called “Svet_MineCraftu” + there is nether, skylands etc… depends on your plugins.
Here is how my soft links looks like in /minecraft ( on disk ) you can see I have used ln -s as in the tutorial above ( the link ) to create soft link that points for folders with maps in ramdisk (/dev/shm/minecraft…) and have same names ending with _perm which are permanent copy stored on disks of maps.. we will keep syncing this between ramdisk maps so when we have restart of server we don’t lose all our data.
Svet_MineCraftu -> /dev/shm/minecraft/Svet_MineCraftu/
Svet_MineCraftu_nether -> /dev/shm/minecraft/Svet_MineCraftu_nether/
Svet_MineCraftu_nether_perm/
Svet_MineCraftu_nightmare -> /dev/shm/minecraft/Svet_MineCraftu_nightmare/
Svet_MineCraftu_nightmare_perm/
Svet_MineCraftu_perm/
Svet_MineCraftu_skylands -> /dev/shm/minecraft/Svet_MineCraftu_skylands/
Svet_MineCraftu_skylands_perm/
Scripts:
Syncing script that keep our ramdisk maps synced with _perm version on disks
rsync_script.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #!/bin/sh
MAIN_DIR="/dev/shm/minecraft"
WORLD_VOLATILE_1="/dev/shm/minecraft/Svet_MineCraftu/"
WORLD_PERM_1="/minecraft/Svet_MineCraftu_perm/"
WORLD_VOLATILE_2="/dev/shm/minecraft/Svet_MineCraftu_nether/"
WORLD_PERM_2="/minecraft/Svet_MineCraftu_nether_perm/"
WORLD_VOLATILE_3="/dev/shm/minecraft/Svet_MineCraftu_nightmare/"
WORLD_PERM_3="/minecraft/Svet_MineCraftu_nightmare_perm/"
WORLD_VOLATILE_4="/dev/shm/minecraft/Svet_MineCraftu_skylands/"
WORLD_PERM_4="/minecraft/Svet_MineCraftu_skylands_perm/"
#check if minecraft folder exist in ramdisk ( you don't wanna sync if it is not there )
if [ -d $MAIN_DIR ] && [ ! -e /minecraft/restore.lock ]; then
# Control will enter here if /dev/shm/minecraft exists
rsync -r -t -v "$WORLD_VOLATILE_1" "$WORLD_PERM_1"
rsync -r -t -v "$WORLD_VOLATILE_2" "$WORLD_PERM_2"
rsync -r -t -v "$WORLD_VOLATILE_3" "$WORLD_PERM_3"
rsync -r -t -v "$WORLD_VOLATILE_4" "$WORLD_PERM_4"
#test message when running from command line
# echo "Sync done... !"
else
echo "Minecraft DIR in ramdisk doesn't exist... ! or Lock is created"
fi |
And one more script, this one will recreate the ramdisk after server reboot
ramdisk_recreate.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #!/bin/sh
MAIN_DIR="/dev/shm/minecraft"
WORLD_VOLATILE_1="/dev/shm/minecraft/Svet_MineCraftu/"
WORLD_PERM_1="/minecraft/Svet_MineCraftu_perm/"
WORLD_VOLATILE_2="/dev/shm/minecraft/Svet_MineCraftu_nether/"
WORLD_PERM_2="/minecraft/Svet_MineCraftu_nether_perm/"
WORLD_VOLATILE_3="/dev/shm/minecraft/Svet_MineCraftu_nightmare/"
WORLD_PERM_3="/minecraft/Svet_MineCraftu_nightmare_perm/"
WORLD_VOLATILE_4="/dev/shm/minecraft/Svet_MineCraftu_skylands/"
WORLD_PERM_4="/minecraft/Svet_MineCraftu_skylands_perm/"
# Create LOCK file, while this file exist other script know restore is in progress
touch /minecraft/restore.lock
# here is check that will look if the directory dont exist, and if it doesnt it will create and sync it
# with permanent storage
if [ ! -d $MAIN_DIR ]; then
# Control will enter here if /dev/shm/minecraft doesn't exist
# first recreate directorys
echo "Recreating directories\n"
mkdir $MAIN_DIR
echo "Done... !\n"
echo "Restoring Maps... !\n"
# now sync
rsync -r -t -v "$WORLD_PERM_1" "$WORLD_VOLATILE_1"
rsync -r -t -v "$WORLD_PERM_2" "$WORLD_VOLATILE_2"
rsync -r -t -v "$WORLD_PERM_3" "$WORLD_VOLATILE_3"
rsync -r -t -v "$WORLD_PERM_4" "$WORLD_VOLATILE_4"
echo "Done... !\n"
echo "Removing LOCK file, syncng will continue as scheduled"
rm -f /minecraft/restore.lock
fi |
And yes I know it could be done by “for” cycle but this way it is more clear for people who have no idea about bash scripts and can easy edit it… feel free to improve the scripts ( would be glad if you post me your modifications )
Don’t forget to use “/” in the end when defining your permanent and volatile map folders or rsync will create new folder inside the one you specified.
You will wont to call rsync_script.sh from cron every 5 min, you can risk 10min intervals but when you loose power and server reboot, depending when it happened, in worst case scenario you will loose 10 min from your map …
For 5 min I use this in my cron:
#Sync ramdisk with permanent map storage on HDD every 5 min
*/5 * * * * cd /minecraft && ./rsync_script.sh &>/dev/null
my script is located in /minecraft so it will cd there and execute it…
I hope this helped a little to all of you, leave a comment !
Regards,
VladoPortos