Linux Server Using Ramdisk for Minecraft

Ramdisk Introduction

Conventionally, files and directories are stored on hard disk drives which, by today's standards, offer a lot of space at mediocre data transfer rates (between 80 MB/s - 250 MB/s). Ramdisks are virtual file systems (unlike HDDs which are hardware) that live completely inside the computer's RAM. They offer significantly higher data transfer rates (1300 MB/s - 3200 MB/s) at the cost of volatility (= data will be lost after restarting the computer) and space (limited by the amount of RAM installed on the system, including swap space).

Advantages and Disadvantages

Advantages

* 빠르다.

Disadvantages

* 컴이 꺼지면 날라감 * 램용량

Why it makes sense for Minecraft servers

In a Minecraft server, one of the strongest bottlenecks are disk I/O related operations (e.g. chunk management). By moving the data into the RAM, access times will be near instant and data transfer rates will be significantly faster, making chunk loading and saving much faster operations. Since a Minecraft world currently consists of of very many chunk files split over many folders, seek time is equally, if not more, important for overall speed.

Basic Minecraft and ramdisk setup

(Make sure to back up your files if you don't know exactly what you are going to do!)

Linux

On most Linux distributions there is already a ramdisk set up (usually mounted to /dev/shm ('sh'ared 'm'emory)) which defaults to using at most half of your total installed RAM. If there is not one already set up, resources on how to do it are widely available on the Internet.

It is possible to move anything into the ramdisk, but here I will focus on just moving the map into it and leaving the server files on the conventional drive.

Given the following basic server directory "minecraft_server/", inside a user's home directory, containing the world "world" and all other required files

We will want to move "world/" into the shared memory. Because of the volatility of ramdisks, we will also want to create a new folder into which an automated script will periodically save the current snapshot of the world, called (for example) "world_storage" by copying the current world to a new name

$ cd ~/minecraft_server/
$ cp world/ world_storage/

Now with the old world in a safe location, we can go ahead and move the world into the ram-disk

$ mkdir /dev/shm/minecraft
$ mv world/ /dev/shm/minecraft

By now, the world is loaded into the RAM, but the Minecraft server doesn't see it in it's directory anymore, causing it to recreate it when started. To stop it from doing that, we have to create a symbolic link to the world in the ramdisk by running

$ ln -s /dev/shm/minecraft/world/ .

This will create a link to "/dev/shm/minecraft/world/" called "world/" in the server's directory, which the server will use like the actual world folder, but now inside the RAM.

Now we need to take care of the volatility of the ramdisk, by periodically saving the world from the RAM into "world_storage/". I'm going to use cron for scheduling and rsync for synching here.

First, we need a script that can be called by cron (it doesn't have to be a script, you could call rsync directly from the cron command line, but this allows for easy customizing later on)

#!/bin/sh

VOLATILE="/home/$USER/minecraft_server/world/"
PERMANENT="/home/$USER/minecraft_server/world_storage/"

#TODO: Check if both directories actually exist, skipped here for clearness
rsync -r -t -v "$VOLATILE" "$PERMANENT"

이제 crontab을 이용하여 자동 싱크…

$ crontab -e

You will be put into an editor (more precisely: the editor in your "EDITOR" environment variable) for editing your user cron table. Add the following line:

*/5 * * * * bash /home/<your_username>/minecraft/save_world.sh &>/dev/null

* 출처 http://www.minecraftforum.net/viewtopic.php?f=1013&t=106367

배슬로넷 마인크래프트 위키입니다. 마음에 안드는 내용이 있으면 욕하지 말고 니가 고치세요. 퍼가면 가문의 영광. 댓글은 굽신굽신. 게시판은 여기.

역링크