[WIP] Analysis of your server JVM using VisualVM

Discussion in 'Resources' started by md_5, Mar 21, 2012.

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

    md_5

    Many server owners come to ask the question, why is my server using soo much ram? Why is my server laggy since the <insert version here> update? Well there is an easy way to inspect the insides of your server yourself.
    I point you here to the VisualVM tool. The following thread will be a screenshot laden tutorial on how to use VisualVM to gain an inside view of your server and an edge over the competition.

    Step 1: Download VisualVM from here. It will work on any system with java that has a gui.
    Step 2: Extract it to a folder of your choice.
    [​IMG]
    Step 3: Prepare your server to be introspected by VisualVM, you can do this by adding the following to your server startup script: -Dcom.sun.management.jmxremote
    Now is also a good time to take a look at all those fancy flags people have encouraged you to put in that script. Be warned many of them lead to increased crashes, memory consumption or other nasty effects. Should experimental weapons really be used on your server?
    How this for simple:
    [​IMG]
    Step 4: Start up your server and VisualVM (find it in the bin/ folder), you will be greeted with a screen like so: [​IMG]
    Step 5: Take a look at what you see. I currently have four java applications running on my computer, Netbeans, my Minecraft launcher, my server and of course VisualVM.
    Step 6: Double click on the CraftBukkit entry, you will be greeted with a screen like below. This is the main control panel for all the options you may perform on your Java VM. I will be going through all of them over the next few posts.
    [​IMG]

    Getting to know your way around VisualVM:
    The main feature of VisualVM that we will be using to sample our server is the heap dump. Those of you who develop a lot of plugins will be familiar of the debug function provided by your idea (<3 Netbeans) a heap dump is sort of like this in the sense that it displays the values of variables and classes, but it is very broad in the sense that it dumps the ENTIRE application heap for your inspection.
    [​IMG]
    As we can see from the monitor tab, various metrics about the performance of CraftBukkit are shown, namely CPU, memory, the number of classes loaded and threads active. We are interested in the Heap Dump button, present in the top right corner. Click this button and you will be presented with a new tab, the heap dump you just took.
    [​IMG]
    Now from this view, there is only one tab that we need access to one tab, the Classes one, click this and you are presented with a myriad of complicated strings.
    [​IMG]

    Advanced use of VisualVM:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
    jtjj222, hawkfalcon and Don Redhorse like this.
  2. *cricket*
    Good so far, going to setup tomorrow!
     
  3. Offline

    md_5

    Sarcasm?
     
  4. No, serious. Joke twas about the blank Advanced use of VisualVM
     
  5. Offline

    md_5

    Originally it was "--Reserved for future use"
    But I didn't think that really fitted. Part 2 isn't finished either.
     
  6. Offline

    Technius

    Looks pretty useful.
     
  7. Offline

    gaz492

    Shame that the screen shots are missing as i would like to know how to set it up properly.
     
  8. Offline

    md_5

    Restored via Dropbox :)
     
  9. Offline

    gaz492

    Thanks :D
     
  10. Offline

    chaseoes

    Ever going to finish it?
     
  11. Offline

    md_5

    I don't plan to :|
     
  12. Offline

    hawkfalcon

    Please do:)
    How do you look at each plugin individually?
     
  13. Offline

    TNTUP

    Gotta try it, seems useful and awesome.

    is the bottom right the TPS? I see 20, I think its the TPS.

    EDIT: sadly it doesn't monitor TPS... well tps are minecraft only, not oracle java. Btw I like the visualVM program.
     
  14. Offline

    ray73864

    Can this monitor a remote server? i see no benefit in something like this when the server and the computer with VisualVM are 2 completely different systems if it cannot do that.
     
  15. Offline

    zack6849

    file>add remote host, so i assume you most certainly
    can.
     
  16. Offline

    Gyldenglad

    I'm trying to use this program to analyse why my server suddenly goes "Read timed out". To see where the error might be.
    However it seems that this guide lacks the part where it actually explains what to look at. What exactly does these tabs mean and so on.

    Here's my thread: http://forums.bukkit.org/threads/server-time-out-error.105596/#post-1378307

    Please continue/update this guide so I can stop the daily crashes on my server, would be much appreciated.
     
  17. So I got it all setup on a Linux mashine with no desktop environment.

    Is there still a way to live debug the server without having to download the heap dump when its generated?
     
  18. Offline

    md_5

    I think X11 forwarding is apparently the way to go.
     
  19. Offline

    FTWin01Gurl

    The way you said Heap Dump made me chuckle. It sounded like a pile of poop in this statement:

     
    -_Husky_- likes this.
  20. Offline

    Kainzo

    You mind helping me re-setup mine? It keeps me giving me a unknown host and I'm not sure what exactly is going wrong. Everything appears to be setup correctly, ports forwarded etc.
     
  21. Offline

    NotYetRated

    This is excellent, much more indepth than the nolagg/examine that I have been using. Thanks!
     
  22. Offline

    iZanax

    But how can I determine if there is a Memory Leak?
    Or something else what causes too many RAM usage?

    I got some several graphics pictures and head dump classes, but I don't understand what I can do with them to see if the plugin is doing something strange, I need a reference point to know what is normal..

    Head Dump - Classes: (is this acceptable?)
    • char[] 25%
    • String 25%
    • Object 13%
    • byte 10%
    Some explanation to use this program to debug some problems would be nice.
    Since problems with RAM is the most common and this could help.
    Thank in advance,
    Zanax
     
  23. Offline

    lDucks

    md_5 great guide on VisualVM, this would have been helpful when I was learning how to use it ;P

    I added a link to your guide in my guide.
     
  24. Offline

    NotYetRated


    You are having RAM issues? Got a plugins list? I have been through quite a few plugins and do not tend to have any RAM issues really. Not while using MD_5's excellent tweaks anyways.
     
  25. Offline

    iZanax

    Tweaks? where...

    The problem is I've one main server plugin and I find it hard to determine if it is using too much RAM for what it does or not. So what can I do?
     
  26. Offline

    kaise123

    Is this going to be updated? :D it's been a while and the 'advanced usage' is still blank. This is a very useful guide, Thanks :D
     
  27. Offline

    Eaglesight

    I'd like to extend my deepest gratitude to both nallar and md_5 for helping me understand VisualVM better. In return, I shall continue on this matter and inform others who want to analyse their servers.

    Once you have VisualVM setup, and have selected your server process. During times of low TPS, click Sampler and then the CPU button. Wait 5 minutes~ and click Snapshot. Order by Time(CPU) and then you'll have loads of data to analyse. This way you can see what functions are taking up abnormal amounts of CPU Time.

    Expand the threads & functions which take alot of time to perform.

    In the end, you should have something like this, which will tell you exactly what function is causing problems.
    [​IMG]
     
  28. Offline

    Chunkr

    Ooh, Thanks for this! :)
     
  29. Offline

    wrradecki

    Cannot take Heap Dump for CraftBukkit.Jar (pid 8136)
     
Thread Status:
Not open for further replies.

Share This Page