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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations

Added Memory Mapped support to HugeCollections

Peter Lawrey user avatar by
Peter Lawrey
·
Sep. 01, 11 · Interview
Like (0)
Save
Tweet
Share
5.91K Views

Join the DZone community and get the full member experience.

Join For Free

The Huge collections library is designed to support large collections on data in memory efficiently without GC impact. It does this using heap less memory and generated code for efficiency.

One of the benefits of this approach is memory mapped files can be larger than the available memory, use trivial heap and no direct memory.

Memory mapping

Loading large amounts of data is time consuming so being able to re-use a store persisted to disk can improve efficiency. With the use of SSD drives the amount of "memory" a Java system can access is effectively extended provided it can be used.

How does it perform

Adding an object with 12 fields and reading objects sequentially takes about 110 ns for one billion elements. It takes less than two minutes to add all the entries, and the same to read all the elements.

Random access is much more expensive until all the data is in memory, with a fast SSD drive it takes about 600 ns when most of the data is in cache, slower if this is not the case.

Java has a collection with one billion elements. (Top)


As you can see the machine has only 24 GB and yet it the Java process is using 37.6G of virtual memory as this includes 33 GB of mapped files.  The actual memory used is 3.4 GB as this is how much is kept in memory.

The shared memory is the same as the memory mapped files can be shared with other processes (however writing to them in a safe manner is not supported)

Creating the huge collection

Like previous huge collections, an anonymous sub-class of the builder is used to create the collection. The baseDirectory is the base directory of where the list is stored.

HugeArrayList list = new HugeArrayBuilder() {{
    baseDirectory = TEMPORARY_SPACE;
    capacity = length;
    allocationSize = 32 * 1024 * 1024;
}}.create();

// update or lookup the collection
list.add(...);

MutableType mt = list.get(900*1000*1000);

// close to flush the data, close files and un-map the collection.
list.close();

Links

Wiki
Downloads
Unit Tests and examples

To follow

Support for a Huge Map with one index under development. Additional non-unique indexes also planned.

 

From http://vanillajava.blogspot.com/2011/08/added-memory-mapped-support-to.html

Memory (storage engine)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Collaborative Development of New Features With Microservices
  • The Beauty of Java Optional and Either
  • DeveloperWeek 2023: The Enterprise Community Sharing Security Best Practices
  • What’s New in Flutter 3.7?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: