[TUTORIAL] Reducing lag and (possibly) fixing corrupt worlds

Discussion in 'Bukkit Help' started by ichingpow, Jun 11, 2011.

Thread Status:
Not open for further replies.
  1. Offline



    This tutorial focuses on reducing lag or even fixing it and reducing the "Can't keep up!" spam. This tutorial is written for craftbukkit and Vanilla. This tutorial does not cover client lag (lag you get in single player) or latency (internet lag). I will also explain how to fix corrupted worlds.

    • Tweak the Java VM by using proper garbage collection. Here is a good launch line for 64bit Java users.
    java -Xmx1024M -XX:ParallelGCThreads=8 -server -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:PermSize=128m -XX:LargePageSizeInBytes=4m -jar craftbukkit-0.0.1-SNAPSHOT.jar nogui
    If can't get a 64bit operating system and in effect 64bit Java then you can use this:
    java -Xmx1024M -XX:ParallelGCThreads=8 -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:PermSize=128m -XX:LargePageSizeInBytes=4m -jar craftbukkit-0.0.1-SNAPSHOT.jar nogui
    The only thing you have to change is the amount of garbage collection threads and the amount of RAM used. 1 gigabyte of RAM is -Xmx1024M but if you have a 64bit operating system and 64bit Java then you can assign more than 4 gigabytes of RAM, for example -Xmx2560M for 3.5 gigabytes. You will also have to change the amount of garbage collection threads, if you have a quad core like me then set it to 8 threads however if you only have a dual core then set it to 4, for example -XX:parallelGCThreads=4.

    • Install PerformanceTweaks. Do note it is not thread safe and it conflicts with SimpleSave.

    • You should also clear out your world of useless stuff. Use WorldGuard + WorldEdit and type /butcher and /remove drops -1 and /remove arrows -1 (do this for each world if you have a multiworld set up). You'll want to do this every 30 minutes or so and do it when there are several players online as it only kills mobs and remove drops and arrows in loaded chunks. If your server is extremely overloaded, type /stoplag (This is part of WorldGuard).

    • Don't use too many plugins. I think a good limit is 50 plugins. Don't double up on plugins (2 permissions plugins like Permissions and GroupManager) and also remember not to use plugins you don't really need. For example (no offence) I don't really need EatSugar, it's a cool idea but how often does a user use it? Never on my server. You also shouldn't use a poorly written plugin, an example that can cause lag is Essentials. Try temporarily removing it and if there is less lag then you need to switch to CommandBook. :p

    • Excessive water and lava flowing is expensive. If you ever get a disconnected with overflow then you definitely have this problem. You can use WorldEdit's /removenear movingwater 90 and /removenear water 90 when you get close to the area you get disconnected or start getting lag.

    • Redstone circuits can cause lag when it is large especially when its looped (a clock or pulser). You can stop the loop by breaking redstone wire adjacent.

    • Raging fire (especially when a forest is on fire) can cause a lot of lag. This isn't as prominent in 1.6 but to remove fire, use WorldEdit's /ex when you are near the fire. This will extinguish it.

    • Install Java 1.7. Make sure to uninstall all other versions of Java before you install 1.7.
    • Get a real server operating system like CentOS or Ubuntu. Windows and Mac OS X aren't good server operating systems.

    Corrupted regions are very annoying but luckily they can be fixed most of the time. You will need to use a utility called Chunkster (You get Chunkster from Chunkster/dist). To use it, make a new directory and put your broken world and Chunkster.jar in it. Then run java -jar Chunkster.jar <world>. Let Chunkster run through your world and if you get an error like
    then look at the first line, world\region\r.-1.-2.mcr that means region r.-1.-2 is corrupt. Go into your world's folder then into region and then make a back up of the corrupted region and then delete the original. Run Chunkster again and again until it doesn't crash or give errors.

    If you are still having issues, ask in this post (or make a new one) and if I can't help you then you'll have to make a new world.
  2. Offline


    Thanks for this detailed explanation! It has helped a lot, it sums up everything new and existing admins should know. I'd also want to give a tip to people to not over-do certain plug-ins, for example: do not make a city full of NPC's or create 10 pvp arena's and/or mob arenas which are controlled by plugins. Keep it simple, don't over-do it, just keep it minimalistic.

    P.S. I'm trying to learn a fair bit of Java, could you explain all the arguments and what they are for? Thanks :D
  3. Offline


    I'll tell you the ones I know :p

    java = Tells the operating system to look launch java
    -Xmx1024M = Tells Java that it shouldn't exceed 1024 megabytes (1gb)
    -XX:parallelGCThreads=8 = Tells Java to make 8 new threads to do garbage collection instead of pausing the main thread
    -server = Tells Java to run it in server mode (x64 only)
    -Xincgc = Used instead of -Xms, tells application to use as little or as much as it needs while not exceeding -Xmx
    -Xnoclassgc = Tells Java not to remove classes inside the .jar from the memory
    -jar craftbukkit-0.0.1-SNAPSHOT.jar = Tells Java to launch a jar named craftbukkit-0.0.1-SNAPSHOT.jar
    nogui = Tells craftbukkit not to try launching the GUI
    Mrlovecraft and RaCooN like this.
  4. Offline


    Thanks mah friend for this =D
    I want to use Chunkster on one if my worlds, but it's been corrupted for ages and people have built on the messed up chunks, but i don't think they'll care =p
  5. Offline


    Thanks for the help, and a detailed description. What is the difference of the server on the Java Sun 7 or JDK 1.7?
  6. Offline


    It's the same thing? Unless you mean openjdk.
  7. Offline


    I mean, it's better to use a server - Java Sun 7b145 or JDKb145?
  8. Offline


    JDK contains Java Sun SE...JDK is for developers who make Java stuff, like the bukkit team.
  9. Offline


    Understandable. I have a machine, tell me what it should run?

    Windows 7 x64 Ultimate
    Intel Core 2 Quad
    4GB memory

    I need to provide 2 - 2.5GB of RAM, about 10-20 people.
  10. Offline


    Sorry, I don't understand the question.
  11. Offline


    That you will forgive me, I have little knowledge of the language. I wanted to ask with what arguments, I'd better start the server?
  12. Offline


    Thanks for the Guide, helps me a lot ;)
  13. Offline


    @ichingpow well written guid, thx for sharing info!

    I tried using this line: java -Xmx1024M -XX:parallelGCThreads=8 -server -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:permSize=128m -XX:LargePageSizeInBytes=4m -jar craftbukkit-0.0.1-SNAPSHOT.jar nogui

    1st removed java at the begining of the line, next removed -server - java said unknown function, then I changed XX:parallelGCThreads=8 to 4, becouse I use dualcore, and I changed -Xmx1024M to 1524.
    Now I think or it actually runs better.
    But still I just posted this topic here -> http://forums.bukkit.org/threads/pc-ram-limited-to-3gs-while-4-are-installed-why.21101/
    becouse my PC is still overloaded.

    Using Win 7 x64, 4gb ram and dual core on 2.6, as you can see from the screenshots there.

    My server is limited to 20 people, most of the time full, when the screens were taken the server was with 20 people.

    So I installed PerformanceTweaks, didnt change any settings, except for the animals - I limited them... alot...

    About /butcher and /remove drops -1 and /remove arrows -1 - can this be done automatically? I cant retype these comands every 30 minutes :/

    I cant go to ubuntu. Tried. Several times. Just they dont have these freaky .exe files where you just google something, you dl it and you use it. On ubuntu you have to write "easy to do comamnds" in the prompt and it downloads everythink automatically, but for me it didnt work. I just don't know what to type in. I couldn't even get my drivers for the video card... c'mon...

    My lane for start.bet looks like this:

    SET BINDIR=%~dp0
    CD /D "%BINDIR%"
    "C:\Program Files (x86)\Java\jre6\bin\java.exe" -Xmx1524M -XX:parallelGCThreads=4 -Xincgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:TargetSurvivorRatio=90 -XX:+UseAdaptiveGCBoundary -XX:-UseGCOverheadLimit -Xnoclassgc -XX:UseSSE=3 -XX:permSize=128m -XX:LargePageSizeInBytes=4m -jar craftbukkit-0.0.1-SNAPSHOT.jar nogui

    Is it wrong? It is in Program Files (x86), shouln't it be in just Program Files? -> x64 programs?

    Thank you for your time!
  14. Offline

    Don Redhorse

    hmm about performance tweaks and simple save... which versions have the problem? all ? I need a good backup plugin and simple save is doing a good job... I think.. so any idea what the issue is or how to fix the problems?
  15. Offline


    Thanks for the support :D

    Its LexManos' fault (The guy who made PerformanceTweaks) and he has no plans to make it compatible. At the moment I use McMyAdmin scheduler to do the task of SimpleSave. You could also set up a cron job or the windows equivalent to run a backup script every X minutes.

    Thank you :D

    I think your problem is you don't actually have Java x64. Evidence to support that is that you can't use -server and you can't assign more than 2.5 gb. I suggest you uninstall all Java completely from the control panel and reinstall Java 1.7 x64, as suggested in my guide.

    As for your start.bat, you don't need to put SET BINDIR=%~dp0
    CD /D "%BINDIR%"
    "C:\Program Files (x86)\Java\jre6\bin\java.exe" in front of it. You can simply replace that with "java", as shown in my guide.
  16. Offline


    Thanks, I sort of helped. I used to have the CPU was loaded at 60-80%, after reading your manual and setting PerfomanceTweaks, my CPU is loaded at 1-14% with online in 20 people. PerfomanceTweaks works fine on craftbukkit # 860.
  17. Offline


    you're close, but your description of -xincgc is off. It is actually an alternative to -concmarksweepgc, so you should just take it out.
  18. Offline


    Ah, thank you. I want to redo my launch line but with the G11 garbage collector some time soon.
  19. Offline


    Just to tell you a tip, my server was also corrupted, ran Chunkster and got no errors. I figured my level.dat was corrupted, loaded my world in MCEdit and saved the world, and some how it was working again.
    Noppoly likes this.
  20. Offline

    Don Redhorse

    sigh.. i don't use mcmyadmin so that isn't an option, what is the sympton of the problem because atm I don't see any :-/
  21. Offline


    Well when I was using it, the save-ll feature added in 0.07 conflicted with how simple save works.
  22. Offline


    written with google translate

    Hello experts, we have a I7-950 with 12GB of RAM and uses the HT (4 / 8 cores)
    should we use HT and how many threads 8 / 16?
  23. Offline


    I actually have this Java Version :
    java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
    Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
    (getting this by java -version)
    I want to install Java 1.7 x64 as said in your post, but I don't know how to, I just want to have Java 1.7 working on my server to run craftbukkit with Java 1.7 for less lag.
    So I downloaded this : http://www.java.net/download/jdk7/a...dk-7-ea-bin-b145-linux-x64-07_jun_2011.tar.gz but I don't know what to run, what to do to install Java 1.7 ...
    I searched some tutorials but I don't know what's the good tutorial, can you help me or give me a link to a good tutorial on how to install Java 1.7 x64 ?

    Thanks ! And sorry for bad english :S
  24. Offline


    You'll want 8 threads.

    "tar xzf jdk-7-ea-bin-b145-linux-x64-07_jun_2011.tar.gz" in Terminal/Console/w.e. should do the trick.
  25. Offline


    I did that, but this command extract the jdk-7-ea-bin-b145-linux-x64-07_jun_2011.tar.gz file, and I have now a directory called "jdk1.7.0" and I don't know what to do with this... May you help me ?

    Thanks !
  26. Offline


    First things first, where did you extract the tarball? Make sure you're extracting it somewhere reasonable and just not throwing it in root. I tend to like to use /opt/ for these kind of tasks, so extract it there. You'll have the directory /opt/jdk1.7.0/ once finished.

    Open up your profile file, /etc/profile, and add the following lines onto the end of it.
    export JAVA_HOME PATH
    Finally type into the console.
    source /etc/profile
    and then...
    java -version
    If you did it correctly you'll get a string of text similar to this.
    java version "1.7.0-ea"
    Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
    Java HotSpot(TM) 64-Bit Server VM (build 21.0-b15, mixed mode)
  27. Offline


    Yes, I did that, but after when I do "java -version" I get that again :
    java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
    Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
    And if I do :
    export PATH=$PATH:/opt/jdk1.7.0/bin
    I get that again "java -version" :
    java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
    Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
    [Edit] : If you want I can give you more informations.
  28. Offline


    Make sure you uninstall all previous versions of Java first, then go through with installing the latest version again.
  29. Offline


    How do I make sure that all previous versions of Java are uninstalled ?
    I launched apt-get remove sun-java6-jdk, apt-get remove sun-java6-bin, apt-get remove sun-java6-jre
    Isn't that enough ?
  30. Offline


    After you have uninstalled java, type "java -version" again. If it says "Unknown command", then it is uninstalled.
Thread Status:
Not open for further replies.

Share This Page