from i/o to ram
DESCRIPTION
IO is slow, memory is fast. For many applications, the main performance and scalability bottleneck is disk and network access. This session will cover strategies that can help you utilize your RAM efficiently even in a distributed environment.Discover how a clustering solution like Terracotta can help you reduce overall application latency.TRANSCRIPT
![Page 1: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/1.jpg)
Riding The Memory Bus
Ophir Radnitz
![Page 2: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/2.jpg)
Agenda
• RAM vs. IO
• Tools of the Trade
• Introducing Terracotta
• RAM Patterns with Terracotta
![Page 3: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/3.jpg)
Anatomy of an Application
Network
Access disk,Serialization
Start a request Get a DB connection, start transactioning
Get a bunch of data
Release resources
Render stuff
![Page 4: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/4.jpg)
I/O Issues
• Scalability issues• Excessive network chatter• How do you scale the database?
• Only as fast as your slowest query• Implies serialization/deserialization
![Page 5: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/5.jpg)
Bandwidths (1 of 2)
Device BandwidthRAMFSB 1,333MHz, DDR3 10 GB/s
PCI Express x16 8 GB/sDMI Interface 1 GB/sSATA 300 MB/sGigabit ethernet 100 MB/sSustained Disk IO(minimal seeks) ~60 MB/s
![Page 6: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/6.jpg)
Bandwidths (1 of 2)
Device BandwidthFirewire 800 ~55 MB/sUSB 2.0 ~30 MB/s100 Mbit ethernet 10 MB/s10 Mbit ethernet 1 MB/sInternet(8Mbit down/1Mbit up)
1.1 MB/s down0.17 MB/s up
![Page 7: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/7.jpg)
RAM vs. Disk
RAM DiskCo-located with CPU Shared storage
Mapped (Indexed) Sequential storage (stream of bytes)
Average access: ~83 ns
Read Seek ~13.7msWrite seek ~15ms
Internet: ~80ms
![Page 8: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/8.jpg)
RAM Goodness
• RAM = High Bandwidth & Low
Latency
• No serialization costs
• Less network
![Page 9: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/9.jpg)
Use Cases
• Low level cache• SQL, HTTP
• Application cache• Hibernate 2nd level cache
• Short lived entities• Queues
![Page 10: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/10.jpg)
Generic Tools
• Memcached• A high-performance, distributed memory
caching system• Used EVRYWHERE: Facebook, Twitter,
Digg, Wikipedia, Slashdot, LiveJournal, Sourceforge etc.
• Squid• Routing and load balancing • HTTP cache
![Page 11: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/11.jpg)
Memcached Limitations for Java
• Remote cache
• Serialization
• 2Gb limit
![Page 12: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/12.jpg)
Java In-Memory Tools
• Prevayler, Space4J• Persist objects in memory, supports
ACID and file system journaling• Db4O in memory, Perst
• Object oriented database• Jofti
• A high-performance object indexing and searching solution. Supports Map.
![Page 13: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/13.jpg)
In-Memory Considerations
• Reliability requires redundancy• And/or durability
• In a cluster state must be synced
• Requires state distribution
![Page 14: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/14.jpg)
Java Distribution Tools
• Coherence• GigaSpace• Ehcache• Infinispan• Terracotta• Hazelcast
![Page 15: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/15.jpg)
Introducing Terracotta
• Network-Attached Memory infrastructure for the JVM
• Open source• (TPL, based on Mozilla License)
• Current version: 3.0.1
![Page 16: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/16.jpg)
Terracotta Customers
![Page 17: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/17.jpg)
Introducing Terracotta
• Highly Available• Highly Scalable• Avoids excessive state
replication• Hub and spoke architecture
![Page 18: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/18.jpg)
A Nice Diagram
Application
ApplicationApplication
Application
Application
TerracottaServer
TerracottaServer
TerracottaServer
![Page 19: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/19.jpg)
How Terracotta Works
Application
TerracottaServer
JVM
Terracotta Libraries
Bootjar instrumenting your application
TC handles JVM locks and
data access
TerracottaClient
![Page 20: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/20.jpg)
How Terracotta Works, take 2
Terracotta Server
Application Application Application
Actual instance
Reference
![Page 21: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/21.jpg)
Terracotta Features
• Cross-JVM object identity • Automatic Persistence to disk• Virtual Memory
• spill heap to TC and/or to disk, transparently• Cluster profiling & visualization• JMX-based monitoring and
management
![Page 22: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/22.jpg)
Terracotta Advantages
• Easy to integrate, Maven support• Great scalability• No proprietary API (optional)• Ready made integration modules• Great diagnostics• In/out of process
![Page 23: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/23.jpg)
Terracotta Development Console
![Page 24: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/24.jpg)
Integrating Terracotta
1. Download & extract
2. Write a tc-config.xml
3. Create a bootjar
4. Run your app with the bootjar
5. Add elements & refactor
![Page 25: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/25.jpg)
TIM - Terracotta Integration Modules
• Packaged functionality• Easy to integrate
• Handles locks details• Examples:
• Concurrent collections, Ehcache• Lucene/Compass, Spring Security• Pipes, Wicket, Tomcat, Jetty • Hibernate, JBoss, Spring etc.
![Page 26: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/26.jpg)
Terracotta Elements
• HTTP Session Replication• Cache Evictor• Queues• Master-Worker• Asynchronous Processor• Cluster membership events
![Page 27: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/27.jpg)
Terracotta Patterns
• Data Cache
• Intermediate persistence
• Queues / work distribution
• Write behind to database
![Page 28: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/28.jpg)
Data Cache Considerations
• Figure out data lifecycle• Read-only, metadata, configuration, session
• Where cache is applicable• Single point of update
• Set eviction policies• LRU, FIFO
![Page 29: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/29.jpg)
Data Cache
• Session cache is easier, entity cache needs real distribution
• Use a generic cache• ConcurrentMap + Map Evictor (+ Jofti)
• Or a Hibernate 2nd level cache• ehcache, TC-Cache
![Page 30: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/30.jpg)
Where Should My Objects Live?Ap
prop
riat
enes
s
Data Lifetime
Memory Database
dies quickly stays forever
![Page 31: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/31.jpg)
Intermediate Data Lifetime
• Some data doesn’t have to be stored in the database
• Session information• Messages / Tokens• Transaction• Unfinished stuff
Data Lifetime
![Page 32: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/32.jpg)
TIM Pipes: Queues
• Execute time consuming tasks asynchronously• In a reliable way• Load balanced
• Examples:• Send emails, process images
• Supports pub/sub, routing• No need for JMS
![Page 33: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/33.jpg)
CommonJ – Work Distribution
• A joint API spec by Oracle and IBM• Provides interfaces for:
• Worker / WorkItem / WorkManager• Scheduler• etc…
• TIM-Messaging provides an implementation• Pipes• Master / Worker
![Page 34: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/34.jpg)
Write Behind to System Of Record
• Asynchronously persist to DB• Work queue• “1.5 phase commit”
• Flags objects as dirty• Avoids syncing dirty objects• Flushes objects• Flags objects as clean
![Page 35: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/35.jpg)
Terracotta Drawbacks
• Concurrency awareness• Massive scalability is a commercial
feature• Requires another machine(s)• Sharing objects across applications
requires configuration• TIMs documentation
![Page 36: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/36.jpg)
Terracotta Pros
• Concurrency awareness• Fits into your application• Provides great visibility• Very versatile usage• Scales massively• Doesn’t use serialization• Great community
![Page 37: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/37.jpg)
Summary
• Does it belong in the DB?
• Do I have to go to the DB for that?
• Do I have to do it now?
Ask yourself:
![Page 38: From I/O To RAM](https://reader033.vdocument.in/reader033/viewer/2022050815/5408754e8d7f7205088b47e9/html5/thumbnails/38.jpg)
Terracotta Pros
Any Questions?