- The bulk of the retained data is a simple data structure (in minecraft’s case its lots of byte)
- The usage of off heap memory can be hidden in abstraction.
- Preset the level-seed=114 in server.properties
- Delete the world* directories
- Start the server with these options to see what the GC is doing
-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps
-XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -Xmx6g
- Connect with one client
- Perform /worldgen village
- Perform /save-all
- It caches block stage in many bytes
- It attempts to cache int used for processing without limit.
A Censum report for the above test looks like this:
Off heap MineCraft
- Use off heap ByteBuffer for long term caching. Unsafe would be more efficient but not as portable.
- Put a cap on the number of int cached.
Note: the problem with the temporary int only became visible to me after moving the bulk of the data off heap. Addressing the biggest problem over reveals more quick fix problems.
Using off heap memory can help you tame you GC pause times, especially if the bulk of your data is in simple data structures which can be easily abstracted. Doing so can also help reveal other simple optimisations you can do to improve the consistency of your performance.
The Source Used
- The source used for the test is available here. https://github.com/peter-lawrey/MineOffHeap
- The logs produced are available here. https://github.com/peter-lawrey/MineOffHeap/tree/master/logs
|Reference:||MineCraft and off heap memory from our JCG partner Peter Lawrey at the Vanilla Java blog.|
Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code
Use Java? If you do, you know that Java software can be used to drive application logic of Web services or Web applications. Perhaps you use it for desktop applications? Or, embedded devices? Whatever your use of Java code, functional errors are the enemy!
To combat this enemy, your team might already perform functional testing. Even so, you're taking significant risks if you have not yet implemented a comprehensive team-wide quality management strategy. Such a strategy alleviates reliability, security, and performance problems to ensure that your code is free of functionality errors.Read this article to learn about this simple four-step strategy that is proven to make Java code more reliable, more secure, and easier to maintain.