DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Memory-Optimized Tables: Implementation Strategies for SQL Server
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Mastering Ownership and Borrowing in Rust
  • Fixing OutOfMemoryErrors in Java Applications

Trending

  • DZone's Article Submission Guidelines
  • Enforcing Architecture With ArchUnit in Java
  • MCP Servers: The Technical Debt That Is Coming
  • The End of “Good Enough Agile”

MineCraft and Off Heap Memory

By 
Peter Lawrey user avatar
Peter Lawrey
·
Jun. 19, 14 · Interview
Likes (0)
Comment
Save
Tweet
Share
7.0K Views

Join the DZone community and get the full member experience.

Join For Free
MineCraft is a really good example of when off heap memory can really help.
The key requirement are
  • 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.

The test

I used the following test for starting minecraft server from a seed from scratch which is a particularly expensive operation for the server.
  • 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 -Xloggc:gc.log 
    -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps 
    -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -Xmx6g
  • Connect with one client
  • Perform /worldgen village
  • Perform /save-all
  • Exit.
To analyse the logs I am using jClarity's Censum.

Standard MineCraft

There is two particularly expensive things it does
  • It caches block stage in many byte[]s
  • It attempts to cache int[] used for processing without limit.
A Censum report for the above test looks like this
The high pause times are partly due to having to manage the large objects.

Off heap MineCraft

Two changes were made to address this
  • 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.
A Censum report for the same test looks like this
There is still some premature promotion i.e. further improvements can be made but you can see that the application is spending.

Conclusion

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.

Footnote

Many organisation treat performance as an enhancement and optional, however if you instil a culture where reasonable performance is a requirement, and failing to meet this requirement is a bug, performance issue are more likely to be fix. c.f.https://bugs.mojang.com/browse/MC-56447

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
Memory (storage engine)

Published at DZone with permission of Peter Lawrey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Memory-Optimized Tables: Implementation Strategies for SQL Server
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Mastering Ownership and Borrowing in Rust
  • Fixing OutOfMemoryErrors in Java Applications

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!