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
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
  1. DZone
  2. Coding
  3. Languages
  4. When Using Direct Memory in Java Can be Faster

When Using Direct Memory in Java Can be Faster

Peter Lawrey user avatar by
Peter Lawrey
·
Dec. 03, 12 · Interview
Like (0)
Save
Tweet
Share
14.29K Views

Join the DZone community and get the full member experience.

Join For Free
Using direct memory is no guarantee of improving performance.  Given it adds complexity, it should be avoided unless you have a compelling reason to use it.

This excellent article by Sergio Oliveira Jr shows its not simply a matter of using direct memory to improve performance Which one is faster: Java heap or native memory?

Where direct memory and memory mapped files can help is when you have a large amounts of data and/or you have to perform some IO with that data.

Time series data.

Time series data tends to have both a large number of entries and involve IO to load and store the data.  This makes it a good candidate for memory mapped files and direct memory.

I have provided an example here;  main and tests where the same operations are performed on regular objects and on memory mapped files.  Note: I am not suggesting that the access to the Objects is slow but the overhead of using objects which is the issue. e.g. loading, creating, the size of the object headers, garbage collection and saving the objects.

The test loads time series data with the time and two columns, bid and ask prices (normalised as int values) This is used to calculate and save a simple mid price basis point movement.  The test performs one GC to include the overhead of managing the objects involved.

Storage  1 million 10 million 30 million 100 million 250 million
Objects   0.55s   4.4s   16.7s   86.7s   225s
MMap   0.056s   0.46s   1.3s   4.5s   11s

The full results

Not only is memory mapped data 10x faster for smaller data sets, it scales better for large data sizes because

  • Memory mapped data is available as soon as it is mapped into memory
  • It creates only a small number of objects, which has almost no heap foot print reducing GC times. 
  • It can be arranged in memory as you desire reducing the over head per row as it doesn't have an object per row.
  • It doesn't have to do anything extra to save the data.

 Using direct memory and memory mapped files is not as simple as using Java objects, but if you have big data requirements it can make a big difference.

Using direct memory and memory mapped files can also make a big difference for low latency requirements, something I have discussed in previous articles.

Memory (storage engine) Big data Java (programming language) Object (computer science) Time series garbage collection

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Better Performance and Security by Monitoring Logs, Metrics, and More
  • Kubernetes vs Docker: Differences Explained
  • OpenID Connect Flows
  • Distributed SQL: An Alternative to Database Sharding

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: