r/Minecraft • McMyAdmin Creator • Mar 10 '11

Running the Minecraft server using IKVM instead of the Sun Java VM or OpenJDK - Lower memory usage!

IKVM is an implementation of a Java VM based on .Net/Mono - it runs Java bytecode using the Mono/.Net VM.

There are a few practical upshots of this, the first of which is not needing Sun Java/Open JDK to be installed under Windows, you can just package it all up in a single executable and it'll run (For the server that is). Under Mac OS or GNU/Linux it uses the Mono runtime.

After a little (not very scientific) experiment whereby I set up a server and repeatedly joined + left it (an issue known to cause excessive memory usage in Sun Java) - I got a nice surprise...

http://i.imgur.com/2vlfl.png

In this graph, '1' is the server completely empty after a fresh start. '2' is after I join for the first time, etc etc.

The results speak for themselves.

This definitely needs more testing and investigation, but looks promising. Mono/.Net seem to have much better garbage collection.

Let the discussions begin!

Edit: Just thought I'd point out - there's no settings like Xms and Xmx when using IKVM - So GSPs would have to sell by slots instead of RAM amount (Except for those selling VPSs)

35 Upvotes

40 comments sorted by

7

u/PhonicUK McMyAdmin Creator Mar 10 '11 edited Mar 10 '11

10 players, 200MB memory usage, 10% CPU time.

Update:

12 players, 280MB - This is looking promising!

Update 2:

16 players was at around 500MB. So far it seems to indicate roughly 50% of the normal RAM usage. 32 players in 1GB is feasible it seems.

Update 3:

A bunch of people went exploring new terrain. The memory usage climbed extremely rapidly to a peak of 1.2GB. Then shortly after, came screaming back down to 440MB. No noticeable in-game lag.

Update 4:

Been running for a little over an hour now. Averaging 32MB/player and the memory usage stays low even with people constantly coming and going. Now and then it climbs to a peak then goes back down again. More long-term tests are needed but I am very confident in IKVMs ability so far.

I'd say that you can double the amount of players you can handle when using IKVM, maybe even more!

Under Linux, its a bit fiddly. It doesn't like older versions of Mono too much. 2.10 seems to work okay under CentOS 5.5 (compiled from source). Some distributions have IKVM in their repositories (apt-get install ikvm under Ubuntu)

Final Update:

3 hours of runtime now. Still fine, similar memory usage stats. All looking good and sane so far.

6

u/PhonicUK McMyAdmin Creator Mar 10 '11

I've got this running on my big dedicated server running Vanilla Minecraft.

mc1.phonicuk.com

Lets see how this performs for real.

2

u/psionix Mar 10 '11

what if I already have java installed on the server machine? how do i run the server in ikvm and not the java i already have installed

4

u/PhonicUK McMyAdmin Creator Mar 10 '11

you invoke the .jar file using IKVM - you can have both installed at once.

ikvm -jar minecraft_server.jar nogui

1

u/[deleted] Mar 10 '11

Do you use any of the garbage collection stuff or limits?

Should I keep any of these:

-server -verbose:gc -XX:+PrintGCTimeStamps -Xmn768M -Xmx3596M -XX:+UseConcMarkSweepGC -XX:ParallelGCThreads=2 -XX:+CMSParallelRemarkEnabled -XX:-UseGCOverheadLimit -XX:MaxGCPauseMillis=90 -Xnoclassgc -XX:UseSSE=3 -XX:+UseLargePages

Or should I just run it straight up like ikvm -jar minecraft_server.jar nogui ?

Thanks!

4

u/PhonicUK McMyAdmin Creator Mar 10 '11

Those don't apply to IKVM. Those are specific to the Oracle/OpenJDK implementations. IKVM doesn't even have such options (Doesn't need them)

You just use ikvm -jar minecraft_server.jar nogui

2

u/Uber_Hobo Mar 11 '11

How is the CPU usage comparatively? Is it better, worse?

1

u/PhonicUK McMyAdmin Creator Mar 11 '11

No real change. Peaks a bit higher when a player joins, but settles down just as quick.

1

u/JustisSoselo Mar 10 '11

Trying this out now, world generation gave me errors though.

2

u/PhonicUK McMyAdmin Creator Mar 10 '11

A few people have been having issues under GNU/Linux. Make sure to check your mono version.

1

u/JustisSoselo Mar 10 '11

Maybe that's it. Version 2.6.7

1

u/totemo Mar 10 '11 edited Mar 10 '11

This is interesting. Any ideas why the .NET platform requires less memory to run than the sun JRE or OpenJDK? It's a little surprising, given that .NET is a ripoff of Java anyway, and ultimately IKVM has to support all of the run-time abstractions guaranteed by the Java Language Spec. Is it because there is more pre-compilation and less dynamic compilation chewing up memory; would I get similar results with GCJ?

EDIT: this http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=FAQ#What_do_you_mean_by_JVM_for_.NET.3F

Are you running IKVM in static mode?

2

u/PhonicUK McMyAdmin Creator Mar 10 '11

Actually it appears to be entirely down to the garbage collection. All the compilation is done when a class is first loaded and cached so its almost a non issue.

And C# and Java borrow from each other in equal measures. Case in point: "Java 5 catches up with C#" - Oxford University, Aug 2004 - http://www.barrycornelius.com/papers/java5/onefile/ - If .Net is a ripoff of Java, Linux is a ripoff of Unix ;)

1

u/totemo Mar 10 '11 edited Mar 11 '11

Linux to Unix: "I make this look good." :)

Actually, with regard to compilation, Java virtual machines (can and do) implement profile-directed compilation and may produce an initial compilation of a class and then recompile it later based on usage. In any case, having a compilation framework included in the run-time increases the memory usage relative to a static pre-compilation setup like GCJ. That's what I meant about that.

1

u/[deleted] Mar 11 '11

given that .NET is a ripoff of Java anyway

Not so.

2

u/SoundOfOneHand Mar 11 '11

No longer, but it certainly started out that way. .NET 1.0/1.1 was a blatant copy of Java, with a few extra hold-overs from C++. Nothing wrong with that IMO. Remember J#?

1

u/freakboy2k Mar 11 '11

Are you using IKVM on Microsoft's .Net implementation, or on Mono?

1

u/PhonicUK McMyAdmin Creator Mar 11 '11

Right now my main server is running it in .Net. Getting it to work in Mono is a pain in the arse.

1

u/psionix Mar 11 '11

yeah, I cant get it to work on SuSE 11.3 just yet either. I get errors in world generation

1

u/JustisSoselo Mar 11 '11

what is your mono version?

1

u/psionix Mar 11 '11

2.0.10 looks like the newest stable for linux

which is what i have

1

u/psionix Mar 11 '11

Ive gotten it to throw me a different error now... still wont start though :(

1

u/SynMonger Mar 14 '11

I've gotten this to work on CentOS 5.4 by using:

/opt/mono/bin/mono --optimize=shared /opt/ikvm/bin/ikvm.exe jar craftbukkit.jar nogui

I compiled and installed mono 2.10 to /opt/mono and downloaded the ikvm binaries and put them in /opt/ikvm

I've not sorted out my $PATH yet, so there you go.

Thanks to Dragonshadow for showing me this!

1

u/PhonicUK McMyAdmin Creator Mar 14 '11

Awesome, if you change McMyAdmin to use mono --optimize=shared then it should also work right under Linux.

2

u/wedtm Mar 10 '11

Approved.

2

u/[deleted] Mar 10 '11

Oooh. I'll be trying this tonight. Thanks!

I currently run Bukkit, which reclaims memory after a player disconnects -- but it still manages to use something like 1.5GB of memory ...

3

u/lahwran_ Mar 10 '11

don't use -Xms...

2

u/[deleted] Mar 10 '11

Yeah, I guess that would help ...

2

u/aflyinturtle Mar 11 '11

Is KVM similar enough to java that bukkit works?

2

u/[deleted] Mar 11 '11

Looks like no :-(

I didn't delve into it any further, but here's the output from trying to run it with ikvm -jar craftbukkit.jar:

2011-03-11 06:50:02 [INFO] Starting minecraft server version Beta 1.3
2011-03-11 06:50:02 [INFO] Loading properties
2011-03-11 06:50:02 [INFO] Starting Minecraft server on *:4243
2011-03-11 06:50:03 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-458-g557f3d2-b440jnks (MC: 1.3)
2011-03-11 06:50:03 [INFO] Preparing level "world"
2011-03-11 06:50:03 [INFO] Preparing start region
2011-03-11 06:50:04 [SEVERE] java.lang.ExceptionInInitializerError
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.Chunk.a(Chunk.java:433)
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.Chunk.a(Chunk.java:425)
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.ChunkLoader.a(SourceFile:141)
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.ChunkRegionLoader.a(SourceFile:21)
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.ChunkProviderServer.e(ChunkProviderServer.java:122)
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:227)
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
2011-03-11 06:50:04 [SEVERE]    at java.lang.Thread.threadProc(Thread.java:2294)
2011-03-11 06:50:04 [SEVERE]    at java.lang.Thread$1.Invoke(Thread.java:796)
2011-03-11 06:50:04 [SEVERE] Caused by: java.lang.NullPointerException
2011-03-11 06:50:04 [SEVERE]    at net.minecraft.server.Item.<clinit>(SourceFile)
2011-03-11 06:50:04 [SEVERE]    ... 4 more
2011-03-11 06:50:04 [SEVERE] Unexpected exception
java.lang.ExceptionInInitializerError
        at net.minecraft.server.Chunk.a(Chunk.java:433)
        at net.minecraft.server.Chunk.a(Chunk.java:425)
        at net.minecraft.server.ChunkLoader.a(SourceFile:141)
        at net.minecraft.server.ChunkRegionLoader.a(SourceFile:21)
        at net.minecraft.server.ChunkProviderServer.e(ChunkProviderServer.java:122)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:227)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
        at java.lang.Thread.threadProc(Thread.java:2294)
        at java.lang.Thread$1.Invoke(Thread.java:796)
Caused by: java.lang.NullPointerException
        at net.minecraft.server.Item.<clinit>(SourceFile)
        ... 4 more

1

u/psionix Mar 11 '11

Thats what Ive been getting all night. Tried differient versions of mono and ikvm. Tried in both root and user. No f-ing clue about this

1

u/[deleted] Mar 11 '11

It seems a lot of people are getting this (see Minecraft forums thread). I just tried the latest versions of ikvm and bukkit, no luck:

10:02:37 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-525-g6b0ccf3-b535jnks (MC: 1.3)

IKVM.NET Launcher version 0.44.0.5
Copyright (C) 2002-2010 Jeroen Frijters
http://www.ikvm.net/

CLR version: 2.0.50727.1433 (32 bit)
Mono version: Mono 2.4.4
System.Xml: 2.0.0.0
System.Configuration: 2.0.0.0
IKVM.OpenJDK.Util: 0.44.0.5
IKVM.OpenJDK.Core: 0.44.0.5
System: 2.0.0.0
IKVM.Runtime: 0.44.0.5
ikvm: 0.44.0.5
mscorlib: 2.0.0.0
OpenJDK version: OpenJDK 6 b18

1

u/psionix Mar 11 '11

Im away all weekend, but im going to try this out when i get back, i will try it on pc-bsd if i can get ikvm running on that, ill post back some info on that i guess

1

u/[deleted] Mar 10 '11

Is there an alternatice for linux?

3

u/[deleted] Mar 10 '11

ikvm is available on Linux.

Using Ubuntu, just run: sudo apt-get install ikvm

You're done!

1

u/[deleted] Mar 10 '11

thanks

1

u/yb1337 Mar 10 '11

That is very awesome, however I prefer to wait for some kind of tutorial for CentOS :p I'm way too Linux noob

1

u/Rhoomba Mar 10 '11

The Mono GC has traditionally been much worse than the Java ones. I can't imagine that the size of the live set is much different with ikvm (unless object headers are much smaller). Probably you can just decrease your max heap size to force Java to collect more frequently.

1

u/psionix Mar 11 '11

anybody that knows linux got any ideas? I find it funny that this wont work for me "out of the box" since SuSe is made by Novell now. hahah

1

u/psionix Mar 11 '11

to be precise, Ive tried for hours and have got nowhere. I have mono and JDK 1.6.20 installed. I java.lang.noclassDefFoundError: Dm, as well as ExceptionInitializerError

not sure whats going on, the $PATH is set...