SlideShare a Scribd company logo
1 of 23
Reservations Gateway Inc.
YOUR LINK to e-TRAVEL SOLUTIONS

- Efficient ProgrammingCreating memory efficient
Applications
“Any intelligent fool can make things bigger and more complex...
It takes a touch of genius - and a lot of courage to move in the
opposite direction”

- Albert Einstein
Indika Maligaspe

October 2013
Intro...


K. Indika Maligaspe


Developer, Designer, Architect , Trainer



Tech Geek specialized in JAVA and .Net



Over 13 years if experience in IT / Web Technologies



Lover of almost all sports...



http://www.linkedin.com/profile/view?id=201732082&trk=nav_responsive_tab_profile

Indika Maligaspe

October 2013
What we will cover



Understanding the memory modal of JVM



Efficient usage of Java



What's in a Collection



How to analyze



QA

Indika Maligaspe

October 2013
Understanding the memory
modal of JVM


The JVM is made up of several areas


Threads & Stack



Heap



Non Heap Permanent generation

Indika Maligaspe

October 2013
Understanding the memory
modal of JVM
Three main areas that effects performance


Young Generation




Short lived, smaller footprints





Newly Created Objects

Broken down to 3 areas as Eden & 2 Survivor Spaces

Old Generation




GC runs less frequently



Indika Maligaspe

Where older objects are maintained

Larger Footprints
October 2013
Understanding the memory
modal of JVM



Three main areas that effects performance cntd.


Permanent Generation


Meta data about the objects in the heap



Information about classes and methods

Indika Maligaspe

October 2013
Understanding the memory
modal of JVM

Indika Maligaspe

October 2013
Efficient usage of Java

Anatomy of a Java Object - Integer
public static void main(String[] args){
int integer = 10;
}
public static void main(String[] args){
Integer integer = new
Integer(10);
}




Indika Maligaspe

Memory allocation of an int = 32bits
Memory allocation of an Integer Object = 128bits (4:1)

October 2013
Efficient usage of Java
Anatomy of a Java Object
public static void main(String[] args){
int integer = 10;
}
public static void main(String[] args){
Integer integer = new
Integer(10);
}

Indika Maligaspe

October 2013
Efficient usage of Java
Anatomy of a Java Object

Indika Maligaspe

October 2013
Efficient usage of Java

Anatomy of a Java Object - Strings
public static void main(String[] args){
String myString = new
String(“MyString”);
}




Indika Maligaspe

128 bits of char data, stored in 480 bits of memory
Maximum overhead is char * 24
October 2013
Efficient usage of Java
Typical inefficient code
public static void main(String[] args){
1. String[] constVals = {“A”,”B”,”C”,”D”};
2. String valToCheck = “D”;
3. Integer indexToCheck = new Integer(0);
While(loop *10){
4. String toSave = new String();
SaveData(....,...,....,toSave);
}
While(loop *10){
5. Integer bookingData = new Integer(rs.getInt(1));
6. Integer retries = new Integer(rs.getString(2));
}
}

Indika Maligaspe

October 2013
Efficient usage of Java
Another String Problem
public static void main(String[] args){
1. String s1 = “Hello”;
2. String s2 = “World”;
3. String s3 = s1 +s2
}
The above is equal to String s3 = new StringBuilder(String.valueOf(s1)).append(s2).toString();



Avoid String appending
Use StringBuffers

Indika Maligaspe

October 2013
Efficient usage of Java
Efficient usage of Java - Summary



Objects are much larger the the data you store in them.



Use PDT's where ever possible



Avoid using new instances and re-use existing instances
as mush as possible



Avoid String operations, at least unless you must



Minimize objects that are long lasting and not used they
will be moved to old generation and a GC in old gen is
stop the world

Indika Maligaspe

October 2013
What's in a Collection
Each Java collection does different functionality and they
have different memory usages
java.util.HashSet
java.util.HashMap
java.util.Hashtable
java.util.LinkedList
java.util.ArrayList

Indika Maligaspe

October 2013
What's in a Collection
HashMap - java.util.HashMap


Implementation - “An Object that maps keys and values
. A map cannot
contain duplicate keys, each key can map to at most one value



Implementation is an array of HashMap$Entry Objects



Default capacity is 16 entries



Empty size is 128 bytes



Overhead is 48 bytes for HasMap, plus (16 + (entries* 4 bytes)) for an array and
the overhead of HashMap$Entry objects

Indika Maligaspe

October 2013
What's in a Collection
LinkedList – java.util.ArrayList


Implementation - “An ordered collection (AKA sequence). The user of this
interface has precise control over where in the list each element is inserted.



Implementation is an array of Objects



Default capacity is 10 entries



Empty size is 88 bytes



Overhead is 32 bytes for ArrayList, plus (16 + (entries* 4 bytes)) for an array



For a 10,000 entry ArrayList, the overhead is - 40k

Indika Maligaspe

October 2013
What's in a Collection
HashMap$Entry


Each HashMap$Entry contains


Int

KeyHash



Object

next



Object

key



Object

value



Additional 32 bytes per key <> value entry



Overhead of a HashMap is therefore – 48 bytes, plus 36 bytes per entry



For a 10,000 entry HashMap, the overhead is - 360k

Indika Maligaspe

October 2013
What's in a Collection
Summary of Collections
Collection

Default Capacity

Empty Size

10k Overhead

HashSet

16

144

360k

HashMap

16

128

360k

Hashtable

11

104

360k

LinkedList

1

48

240k

ArrayList

10

88

40k

StringBuffer

16

72

240k

Indika Maligaspe

October 2013
What's in a Collection
Hash* collections vs Others



Hash collections are much larger (almost 9x of an ArrayList)



Additional size helps search / add / remove (performance is constant to Hash
collections but linear to ArrayList)



Really know when to use what and use properly

Indika Maligaspe

October 2013
How to analyze
Several tools available to analyze performance within the
JVM


VisualVM - Production / Development



Eclipse – Memory Analysis Tool (MAT) - Development



Jconsole - Development



Just reading hprof - Production / Development



Nagios – Production



NewRelic - Production

Indika Maligaspe

October 2013
How to analyze
Most of the tools will give


Memory Usage (Heap / Perm etc..)



CPU stats for JVM



GC usage and behavior



Threads and how threads are being used



Hot spots

Indika Maligaspe

October 2013
Thank You
Reservations Gateway Inc.
YOUR LINK to e-TRAVEL SOLUTIONS
Reservations Gateway Inc.
Reservations Gateway Inc.
11654 Plaza America Drive , Unit 645
Reston, Virginia 20190-4700
USA
Tel :
Fax :
Email :
Web :

Indika Maligaspe

703 286 5331
703 433 0146
info@rezgateway.com
www.rezgateway.com

October 2013

More Related Content

What's hot

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection frameworkankitgarg_er
 
2014.06.24.what is ubix
2014.06.24.what is ubix2014.06.24.what is ubix
2014.06.24.what is ubixJim Cooley
 
Elasticsearch War Stories
Elasticsearch War StoriesElasticsearch War Stories
Elasticsearch War StoriesArno Broekhof
 
Latent Semantic Analysis of Wikipedia with Spark
Latent Semantic Analysis of Wikipedia with SparkLatent Semantic Analysis of Wikipedia with Spark
Latent Semantic Analysis of Wikipedia with SparkSandy Ryza
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesDatabricks
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections frameworkRiccardo Cardin
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Big data week presentation
Big data week presentationBig data week presentation
Big data week presentationJoseph Adler
 
Spark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaSpark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaJose Mº Muñoz
 
World’s Best Data Modeling Tool
World’s Best Data Modeling ToolWorld’s Best Data Modeling Tool
World’s Best Data Modeling ToolArtem Chebotko
 
Ts archiving
Ts   archivingTs   archiving
Ts archivingConfiz
 
Big data distributed processing: Spark introduction
Big data distributed processing: Spark introductionBig data distributed processing: Spark introduction
Big data distributed processing: Spark introductionHektor Jacynycz García
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List Hitesh-Java
 
NoSQL Databases, Not just a Buzzword
NoSQL Databases, Not just a Buzzword NoSQL Databases, Not just a Buzzword
NoSQL Databases, Not just a Buzzword Haitham El-Ghareeb
 
Linked in stream experimentation framework
Linked in stream experimentation frameworkLinked in stream experimentation framework
Linked in stream experimentation frameworkJoseph Adler
 

What's hot (20)

Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
2014.06.24.what is ubix
2014.06.24.what is ubix2014.06.24.what is ubix
2014.06.24.what is ubix
 
Elasticsearch War Stories
Elasticsearch War StoriesElasticsearch War Stories
Elasticsearch War Stories
 
Latent Semantic Analysis of Wikipedia with Spark
Latent Semantic Analysis of Wikipedia with SparkLatent Semantic Analysis of Wikipedia with Spark
Latent Semantic Analysis of Wikipedia with Spark
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFrames
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Big data week presentation
Big data week presentationBig data week presentation
Big data week presentation
 
Predicting the relevance of search results for e-commerce systems
Predicting the relevance of search results for e-commerce systemsPredicting the relevance of search results for e-commerce systems
Predicting the relevance of search results for e-commerce systems
 
Spark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaSpark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest Córdoba
 
Java-7: Collections
Java-7: CollectionsJava-7: Collections
Java-7: Collections
 
World’s Best Data Modeling Tool
World’s Best Data Modeling ToolWorld’s Best Data Modeling Tool
World’s Best Data Modeling Tool
 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
 
Big data distributed processing: Spark introduction
Big data distributed processing: Spark introductionBig data distributed processing: Spark introduction
Big data distributed processing: Spark introduction
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
NoSQL Databases, Not just a Buzzword
NoSQL Databases, Not just a Buzzword NoSQL Databases, Not just a Buzzword
NoSQL Databases, Not just a Buzzword
 
Linked in stream experimentation framework
Linked in stream experimentation frameworkLinked in stream experimentation framework
Linked in stream experimentation framework
 

Similar to Efficient Memory Java Collections Analyze

JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaJavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaChris Bailey
 
Real-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to StreamingReal-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to StreamingDatabricks
 
Strata NYC 2015 - What's coming for the Spark community
Strata NYC 2015 - What's coming for the Spark communityStrata NYC 2015 - What's coming for the Spark community
Strata NYC 2015 - What's coming for the Spark communityDatabricks
 
Lightning fast analytics with Cassandra and Spark
Lightning fast analytics with Cassandra and SparkLightning fast analytics with Cassandra and Spark
Lightning fast analytics with Cassandra and SparkVictor Coustenoble
 
Lightning Fast Analytics with Cassandra and Spark
Lightning Fast Analytics with Cassandra and SparkLightning Fast Analytics with Cassandra and Spark
Lightning Fast Analytics with Cassandra and SparkTim Vincent
 
Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra Matthias Niehoff
 
Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016
Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016
Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016DataStax
 
NET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxNET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxpetabridge
 
A Rusty introduction to Apache Arrow and how it applies to a time series dat...
A Rusty introduction to Apache Arrow and how it applies to a  time series dat...A Rusty introduction to Apache Arrow and how it applies to a  time series dat...
A Rusty introduction to Apache Arrow and how it applies to a time series dat...Andrew Lamb
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack PresentationAmr Alaa Yassen
 
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...DataStax
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Ravi Okade
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020Thodoris Bais
 
Using Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data StoreUsing Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data StoreVolkan Yazıcı
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interviewRussell Childs
 
Apache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster ComputingApache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster ComputingGerger
 
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...Spark Summit
 
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...Databricks
 

Similar to Efficient Memory Java Collections Analyze (20)

JavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient JavaJavaOne 2013: Memory Efficient Java
JavaOne 2013: Memory Efficient Java
 
Real-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to StreamingReal-Time Spark: From Interactive Queries to Streaming
Real-Time Spark: From Interactive Queries to Streaming
 
Strata NYC 2015 - What's coming for the Spark community
Strata NYC 2015 - What's coming for the Spark communityStrata NYC 2015 - What's coming for the Spark community
Strata NYC 2015 - What's coming for the Spark community
 
Lightning fast analytics with Cassandra and Spark
Lightning fast analytics with Cassandra and SparkLightning fast analytics with Cassandra and Spark
Lightning fast analytics with Cassandra and Spark
 
Lightning Fast Analytics with Cassandra and Spark
Lightning Fast Analytics with Cassandra and SparkLightning Fast Analytics with Cassandra and Spark
Lightning Fast Analytics with Cassandra and Spark
 
icpe2019_ishizaki_public
icpe2019_ishizaki_publicicpe2019_ishizaki_public
icpe2019_ishizaki_public
 
Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra Big data analytics with Spark & Cassandra
Big data analytics with Spark & Cassandra
 
Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016
Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016
Myths of Big Partitions (Robert Stupp, DataStax) | Cassandra Summit 2016
 
NET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptxNET Systems Programming Learned the Hard Way.pptx
NET Systems Programming Learned the Hard Way.pptx
 
A Rusty introduction to Apache Arrow and how it applies to a time series dat...
A Rusty introduction to Apache Arrow and how it applies to a  time series dat...A Rusty introduction to Apache Arrow and how it applies to a  time series dat...
A Rusty introduction to Apache Arrow and how it applies to a time series dat...
 
Elastic stack Presentation
Elastic stack PresentationElastic stack Presentation
Elastic stack Presentation
 
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
Elassandra: Elasticsearch as a Cassandra Secondary Index (Rémi Trouville, Vin...
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 
Using Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data StoreUsing Elasticsearch as the Primary Data Store
Using Elasticsearch as the Primary Data Store
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interview
 
Apache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster ComputingApache Spark, the Next Generation Cluster Computing
Apache Spark, the Next Generation Cluster Computing
 
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
Deep Dive into Project Tungsten: Bringing Spark Closer to Bare Metal-(Josh Ro...
 
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
 

More from indikaMaligaspe

Rez gateway (RezOS) innovate the future
Rez gateway  (RezOS) innovate the futureRez gateway  (RezOS) innovate the future
Rez gateway (RezOS) innovate the futureindikaMaligaspe
 
Rez gateway - RezOS - innovate the future
Rez gateway - RezOS -   innovate the futureRez gateway - RezOS -   innovate the future
Rez gateway - RezOS - innovate the futureindikaMaligaspe
 
Delivering Powerful Presentations
Delivering Powerful PresentationsDelivering Powerful Presentations
Delivering Powerful PresentationsindikaMaligaspe
 
How ICT is shaping Travel and Tourism landscapes
How ICT is shaping Travel and Tourism landscapesHow ICT is shaping Travel and Tourism landscapes
How ICT is shaping Travel and Tourism landscapesindikaMaligaspe
 
So you want to be a Software Engineer
So you want to be a Software EngineerSo you want to be a Software Engineer
So you want to be a Software EngineerindikaMaligaspe
 
Designing Rest Services - An Architects Guide
Designing Rest Services - An Architects GuideDesigning Rest Services - An Architects Guide
Designing Rest Services - An Architects GuideindikaMaligaspe
 
Object Oriented Software Design Principles
Object Oriented Software Design PrinciplesObject Oriented Software Design Principles
Object Oriented Software Design PrinciplesindikaMaligaspe
 

More from indikaMaligaspe (8)

Rez gateway (RezOS) innovate the future
Rez gateway  (RezOS) innovate the futureRez gateway  (RezOS) innovate the future
Rez gateway (RezOS) innovate the future
 
Rez gateway - RezOS - innovate the future
Rez gateway - RezOS -   innovate the futureRez gateway - RezOS -   innovate the future
Rez gateway - RezOS - innovate the future
 
Delivering Powerful Presentations
Delivering Powerful PresentationsDelivering Powerful Presentations
Delivering Powerful Presentations
 
How ICT is shaping Travel and Tourism landscapes
How ICT is shaping Travel and Tourism landscapesHow ICT is shaping Travel and Tourism landscapes
How ICT is shaping Travel and Tourism landscapes
 
So you want to be a Software Engineer
So you want to be a Software EngineerSo you want to be a Software Engineer
So you want to be a Software Engineer
 
Designing Rest Services - An Architects Guide
Designing Rest Services - An Architects GuideDesigning Rest Services - An Architects Guide
Designing Rest Services - An Architects Guide
 
Writing Quality Code
Writing Quality CodeWriting Quality Code
Writing Quality Code
 
Object Oriented Software Design Principles
Object Oriented Software Design PrinciplesObject Oriented Software Design Principles
Object Oriented Software Design Principles
 

Recently uploaded

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Efficient Memory Java Collections Analyze

  • 1. Reservations Gateway Inc. YOUR LINK to e-TRAVEL SOLUTIONS - Efficient ProgrammingCreating memory efficient Applications “Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction” - Albert Einstein Indika Maligaspe October 2013
  • 2. Intro...  K. Indika Maligaspe  Developer, Designer, Architect , Trainer  Tech Geek specialized in JAVA and .Net  Over 13 years if experience in IT / Web Technologies  Lover of almost all sports...  http://www.linkedin.com/profile/view?id=201732082&trk=nav_responsive_tab_profile Indika Maligaspe October 2013
  • 3. What we will cover  Understanding the memory modal of JVM  Efficient usage of Java  What's in a Collection  How to analyze  QA Indika Maligaspe October 2013
  • 4. Understanding the memory modal of JVM  The JVM is made up of several areas  Threads & Stack  Heap  Non Heap Permanent generation Indika Maligaspe October 2013
  • 5. Understanding the memory modal of JVM Three main areas that effects performance  Young Generation   Short lived, smaller footprints   Newly Created Objects Broken down to 3 areas as Eden & 2 Survivor Spaces Old Generation   GC runs less frequently  Indika Maligaspe Where older objects are maintained Larger Footprints October 2013
  • 6. Understanding the memory modal of JVM  Three main areas that effects performance cntd.  Permanent Generation  Meta data about the objects in the heap  Information about classes and methods Indika Maligaspe October 2013
  • 7. Understanding the memory modal of JVM Indika Maligaspe October 2013
  • 8. Efficient usage of Java Anatomy of a Java Object - Integer public static void main(String[] args){ int integer = 10; } public static void main(String[] args){ Integer integer = new Integer(10); }   Indika Maligaspe Memory allocation of an int = 32bits Memory allocation of an Integer Object = 128bits (4:1) October 2013
  • 9. Efficient usage of Java Anatomy of a Java Object public static void main(String[] args){ int integer = 10; } public static void main(String[] args){ Integer integer = new Integer(10); } Indika Maligaspe October 2013
  • 10. Efficient usage of Java Anatomy of a Java Object Indika Maligaspe October 2013
  • 11. Efficient usage of Java Anatomy of a Java Object - Strings public static void main(String[] args){ String myString = new String(“MyString”); }   Indika Maligaspe 128 bits of char data, stored in 480 bits of memory Maximum overhead is char * 24 October 2013
  • 12. Efficient usage of Java Typical inefficient code public static void main(String[] args){ 1. String[] constVals = {“A”,”B”,”C”,”D”}; 2. String valToCheck = “D”; 3. Integer indexToCheck = new Integer(0); While(loop *10){ 4. String toSave = new String(); SaveData(....,...,....,toSave); } While(loop *10){ 5. Integer bookingData = new Integer(rs.getInt(1)); 6. Integer retries = new Integer(rs.getString(2)); } } Indika Maligaspe October 2013
  • 13. Efficient usage of Java Another String Problem public static void main(String[] args){ 1. String s1 = “Hello”; 2. String s2 = “World”; 3. String s3 = s1 +s2 } The above is equal to String s3 = new StringBuilder(String.valueOf(s1)).append(s2).toString();   Avoid String appending Use StringBuffers Indika Maligaspe October 2013
  • 14. Efficient usage of Java Efficient usage of Java - Summary  Objects are much larger the the data you store in them.  Use PDT's where ever possible  Avoid using new instances and re-use existing instances as mush as possible  Avoid String operations, at least unless you must  Minimize objects that are long lasting and not used they will be moved to old generation and a GC in old gen is stop the world Indika Maligaspe October 2013
  • 15. What's in a Collection Each Java collection does different functionality and they have different memory usages java.util.HashSet java.util.HashMap java.util.Hashtable java.util.LinkedList java.util.ArrayList Indika Maligaspe October 2013
  • 16. What's in a Collection HashMap - java.util.HashMap  Implementation - “An Object that maps keys and values . A map cannot contain duplicate keys, each key can map to at most one value  Implementation is an array of HashMap$Entry Objects  Default capacity is 16 entries  Empty size is 128 bytes  Overhead is 48 bytes for HasMap, plus (16 + (entries* 4 bytes)) for an array and the overhead of HashMap$Entry objects Indika Maligaspe October 2013
  • 17. What's in a Collection LinkedList – java.util.ArrayList  Implementation - “An ordered collection (AKA sequence). The user of this interface has precise control over where in the list each element is inserted.  Implementation is an array of Objects  Default capacity is 10 entries  Empty size is 88 bytes  Overhead is 32 bytes for ArrayList, plus (16 + (entries* 4 bytes)) for an array  For a 10,000 entry ArrayList, the overhead is - 40k Indika Maligaspe October 2013
  • 18. What's in a Collection HashMap$Entry  Each HashMap$Entry contains  Int KeyHash  Object next  Object key  Object value  Additional 32 bytes per key <> value entry  Overhead of a HashMap is therefore – 48 bytes, plus 36 bytes per entry  For a 10,000 entry HashMap, the overhead is - 360k Indika Maligaspe October 2013
  • 19. What's in a Collection Summary of Collections Collection Default Capacity Empty Size 10k Overhead HashSet 16 144 360k HashMap 16 128 360k Hashtable 11 104 360k LinkedList 1 48 240k ArrayList 10 88 40k StringBuffer 16 72 240k Indika Maligaspe October 2013
  • 20. What's in a Collection Hash* collections vs Others  Hash collections are much larger (almost 9x of an ArrayList)  Additional size helps search / add / remove (performance is constant to Hash collections but linear to ArrayList)  Really know when to use what and use properly Indika Maligaspe October 2013
  • 21. How to analyze Several tools available to analyze performance within the JVM  VisualVM - Production / Development  Eclipse – Memory Analysis Tool (MAT) - Development  Jconsole - Development  Just reading hprof - Production / Development  Nagios – Production  NewRelic - Production Indika Maligaspe October 2013
  • 22. How to analyze Most of the tools will give  Memory Usage (Heap / Perm etc..)  CPU stats for JVM  GC usage and behavior  Threads and how threads are being used  Hot spots Indika Maligaspe October 2013
  • 23. Thank You Reservations Gateway Inc. YOUR LINK to e-TRAVEL SOLUTIONS Reservations Gateway Inc. Reservations Gateway Inc. 11654 Plaza America Drive , Unit 645 Reston, Virginia 20190-4700 USA Tel : Fax : Email : Web : Indika Maligaspe 703 286 5331 703 433 0146 info@rezgateway.com www.rezgateway.com October 2013