SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
Memory

API

Java	
  -­‐	
  Advanced	
  Memory	
  Management	
  
Chris6an	
  Campo	
  -­‐	
  EclipseCon	
  Europe	
  2013	
  
Agenda	
  
• 	
  Overview	
  

• 	
  Challenges	
  
• 	
  Cache	
  Problems	
  
• 	
  API	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Overview	
  
Private filesystem
Hierarchical datastructure
• root, folders, files, attributes, binary content

Simultaneous read/write from multiple threads
• application UI, synchronizer, filesystem driver etc.

Stored in sql database

Schema is dynamic (columns added at runtime)

No OR-Mapper

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Data	
  model	
  
"/"

/docs

/docs/a.txt

<root>

"docs"

"images"

"a.txt"
Attributes:
-  lastmodified
-  length
-  owner
-  customernumber

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0

/images
Components	
  
Application

Synchronizer(Daemon)
Store API
Files / Directories
Nodes
SQL Access

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0

Virtual File System
Challenges	
  
• 	
  Repe66ve	
  queries	
  (aHributes)	
  
›  Windows	
  assumes	
  any	
  FileSystem	
  opera6on	
  as	
  cheap	
  
• 	
  Applica6on	
  developer	
  don't	
  think	
  about	
  internals	
  
›  they	
  assume	
  that	
  any	
  API	
  call	
  is	
  cheap	
  and	
  fast	
  
• 	
  Data	
  structure	
  is	
  dynamic	
  
• 	
  Growing	
  size	
  of	
  data	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Developer	
  stereotypes	
  

Application
Developer
Framework
Developer
DB Developer
• ACID
• transactions
• logic should be a
stored procedure
• db has buffer
(=cache)

• clean and small API
• refactor often
• DBs are too slow à
cache

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0

• never refactor :-)
• wrap every framework
• Framework is too slow
à cache
• why cant I access the
DB directly ? :-)
Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Cache	
  -­‐	
  Requirements	
  

Rule #1: Cache improves speed but does not change functionality
Rule #2: Cache must not lead to OOM

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Virtual	
  File	
  System	
  -­‐	
  FileCache	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Virtual	
  File	
  System	
  -­‐	
  FileCache	
  

tempting
to add a
cache

often lists
children of a
directory

build
"MyCache" :-)

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
VFS	
  -­‐	
  "MyCache"	
  V1.0	
  
private WeakHashMap<String, List<GFile> > cache =
new WeakHashMap<String, List<GFile> >();
private Store store;
public synchronized List<GFile> list( final GFile gFile ) {
List<GFile> list = cache.get(gFile.getPath());
if ( list == null) {
list = store.list(goyaFile );
cache.put(gFile.getPath(), list );
}
return list;
}

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
VFS	
  -­‐	
  "MyCache"	
  V1.0	
  -­‐	
  junit	
  test	
  
// create + write content
for (int x=0; x<100; x++) {
GFile file = store.create(new GFile("/docs/test" +x+ ".txt"));
}
// check
for (int x=0; x<100; x++) {
List<GFile> list = list(new GFile("/docs"));
assertTrue(list.contains(new GFile("/docs/test" +x+ ".txt")));
}
// list from "MyCache"
public synchronized List<GFile> list( final GFile gFile ) {}

OK + FASTER with Cache

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
VFS	
  -­‐	
  "MyCache"	
  V1.0	
  -­‐	
  junit	
  test	
  
// create + write content + check
for (int x=0; x<100; x++) {
GFile file = store.create(new GFile("/docs/test“ +x+ ".txt"));
List<GFile> list = list(new GFile("/docs"));
assertTrue(list.contains(new GFile("/docs/test“ +x+ ".txt")));
}
// list from "MyCache"
public synchronized List<GFile>
list( final Store store, final GFile gFile ) {}

FAILS with Cache
-> expiration time for cache entries

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
VFS	
  -­‐	
  MyCache	
  V2.0	
  
private long EXPIRATION_TIME = 200;
private WeakHashMap<String, MyCacheEntry> cache =
new WeakHashMap<String, MyCacheEntry>();
public synchronized List<GFile> list( final LocalStore store, final GFile gFile ) {
final MyCacheEntry myCacheEntry = cache.get(gFile.getPath());
if ( myCacheEntry == null || System.currentTimeMillis() - {
class MyCacheEntry
public List<GFile> listGFiles;
EXPIRATION_TIME > myCacheEntry.currentTimeMillis ) {
public long currentTime;
final List<GoyaFile> listGoyaFiles = store.list( goyaFile );
MyCacheEntry( final List<GFile>
cache.put(gFile.getPath(), new MyCacheEntry( listGoyaFiles ) ); listGFiles ) {
this.listGFiles = listGFiles;
return listGoyaFiles;
this.currentTime = System.currentTimeMillis();
}
} else {
}
return myCacheEntry.listGoyaFiles;
}

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Virtual	
  FS	
  -­‐	
  MyCache	
  V2.0	
  -­‐	
  more	
  problems	
  ...	
  
• 	
  It	
  was	
  hard	
  to	
  find	
  a	
  good	
  value	
  for	
  EXPIRATION_TIME	
  
›  200	
  ms	
  effec6ve	
  but	
  it	
  was	
  easy	
  to	
  get	
  wrong	
  HITS	
  
›  10	
  ms	
  beFer	
  (not	
  always	
  right)	
  but	
  not	
  many	
  HITS	
  
• 	
  implement	
  a	
  maximum	
  number	
  of	
  entries	
  
• 	
  find	
  means	
  to	
  "know"	
  when	
  CacheEntries	
  are	
  invalid	
  
• 	
  sta6s6cs	
  ?	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Virtual	
  FS	
  -­‐	
  LoadingCache	
  (Guava)	
  
private final LoadingCache<String, List<GFile>> cache =
CacheBuilder.newBuilder()
.maximumSize( 10 )
.softValues()
.expireAfterWrite( 200, TimeUnit.MILLISECONDS)
.build( new CacheLoader<String, List<GFile>>() {
public List<GFile> load( final String path ) {
return store.list( new GFile( path ) );
}
} );

Rule #3: Never write your own Cache implementation

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Virtual	
  FS	
  -­‐	
  invalida6ng	
  CacheEntries	
  
public GFile create(GFile file) {
GFile g = store.create(file);
cache.flush();
return g;
}
public GFile create(GFile file) {
GFile g = store.create(file);
cache.remove(getParent(file).getPath());
return g;
}
Rule #4: Have a strategy for removing cache entries
(expiration timing alone does not work)

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  
• 	
  heavy	
  load	
  on	
  the	
  db	
  
• 	
  a	
  lot	
  of	
  read	
  opera6ons	
  on	
  aHributes	
  
• 	
  not	
  many	
  writes	
  
• 	
  à	
  cache	
  aHributes	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  
private final Map<String, String> attributesCache;
public String getAttribute( final String name ) {
String value = attributesCache.get( name );
if (value!=null) {
return value;
}
... // read it from DB
}
public void setAttribute( final String name, String value) {
if ( !Objects.equal( value, attributesCache.get( name ) ) ) {
attributesCache.put( name, value );
... // update attribute in the database
}
}

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  -­‐	
  Junit	
  test	
  
// previous value of length = "1057"
db.transaction(new DbRunnable() {
protected void run() {
file.setAttribute("length", "0");
long newLength = store.put(file, inputStream);
file.setAttribute("length", new String(newLength))
public void setAttribute(final String name,String value) {
}
if(!Objects.equal(value, attributeCache.get(name))){
});
attributesCache.put( name, value );
...
... // update attribute in the database
}

file.setAttribute("length", "0");
• 
• 
• 
• 

IOException reading inputStream
transaction rolls back
attribute length = "0" in Cache and has "1057" in DB
setAttribute("length","0") after Transaction, does not reach DB
Rule #5: Cache should be aware of transaction rollbacks

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  -­‐	
  Transac6ons	
  
private final Map<String, Optional<String>> attributesCache;
private void init() {
getTransaction().register(this);
}
public String getAttribute( final String key ) {
...
}
public void setAttribute( final String name, String value) {}
public void rollback() { // called when transaction rolls back
attributesCache.flush();
}

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  -­‐	
  Transac6ons	
  
db.transaction(new DbRunnable() {
try {
store.put(file, inputStream);
file.setAttribute("loaded","true");
} catch (IOException ioe) {
file.setAttribute("loaded","false");
throw ioe; }
});

•  IOException -> transaction rollback
•  loaded = "false" NOT in Cache, NOT in DB
•  Cache changes behaviour once it does Transaction rollback.
•  Rule #6 Dont return with Exception if data should not rollback

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHribute	
  Cache	
  -­‐	
  Isola6on	
  
Component A

Component B

Transaction 1

Transaction 2

???

x=?
GFile

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHributeCache	
  -­‐	
  Isola6on	
  -­‐	
  Solu6on	
  1	
  
public void setAttribute( final String name, String value ) {
...
getTransaction().getContext().set( ... + name, value );
...
}
public String getAttribute(String name) {
...
String value = getTransaction().getContext().get( ... + name );
...
}

•  store cached values global IN the transaction context
•  however all attribute values are stored in Transaction

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
AHributeCache	
  -­‐	
  Isola6on	
  -­‐	
  Solu6on	
  2	
  (beHer)	
  
private HashMap<String, String> cache=new HashMap<String,String>();
public void setAttribute( final String name, String value) {
...
cache.put(getTransactionId() + name, value);
...
}
public String getAttribute(String name) {
...
String value = cache.get(getTransactionId() + name);
...
}
store cached values local depending on transaction-id

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
ChunkCache	
  -­‐	
  data	
  with	
  dirty	
  state	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
ChunkCache	
  -­‐	
  data	
  with	
  dirty	
  state	
  
Virtual FileSystem
• 
• 
• 
• 
• 
• 

ChunkFileStore

"write offset=110.000 length=2000"
"write..."
"write..."
"write..."
"write..."
"write..."

010110010101
010101010101
010110010101
010101101000
010101010101
010110010101
11110101
010101101000
010101010101
010110010101
11110101
010101101000
010101010101
11110101
010101101000
11110101

• VFS	
  writes	
  and	
  reads	
  data	
  in	
  random	
  "segments"	
  
›  i.e.	
  "write	
  offset	
  110.000	
  length	
  200"	
  
• 	
  Stored	
  on	
  disk	
  in	
  1	
  MB	
  "Chunks"	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0

Chunks (1 MB)
ChunkCache	
  -­‐	
  data	
  with	
  dirty	
  state	
  
Virtual FileSystem
•  "write offset=110.000 length=200"
•  "write..."

ChunkCache
010110010101
010101010101
010110010101
010101101000
010101010101
11110101
010101101000
11110101

• 	
  Cache	
  writes	
  lazy	
  
• 	
  Cache	
  maintained	
  in	
  dirty	
  state	
  
• 	
  LoadingCache	
  used	
  
• 	
  6meout,	
  maxsize	
  

ChunkFileStore
010110010101
010101010101
010110010101
010101101000
010101010101
010110010101
11110101
010101101000
010101010101
010110010101
11110101
010101101000
010101010101
11110101
010101101000
11110101

Chunks (1 MB)
Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
ChunkCache	
  -­‐	
  data	
  with	
  dirty	
  state	
  
private final LoadingCache<Integer, Chunk> cache =
CacheBuilder.newBuilder()
.maximumSize(4)
.expireAfterAccess(2, TimeUnit.SECONDS)
.removalListener(new RemovalListener<Integer, Chunk>() {
public void onRemoval(final RemovalNotification<Integer,
Chunk> notification ) {
if ( notification.getValue().isDirty() ) {
// write chunk
•  write to disk on remove
}
•  cache entries only expire on access !!
}
•  no automatic housekeeping
})
.build( new CacheLoader<Integer, Chunk>() {
public Chunk load( final Integer key ) throws Exception {
// load Chunk for key
}
} );

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
API	
  -­‐	
  query	
  -­‐	
  list	
  
query	
  for	
  resources	
  sa6sfying	
  a	
  condi6on	
  
	
  

ArrayList<GFile> query("type='file' and lastmodified>'20130901' ");

• 
• 
• 
• 

can produce a lot of instances
returns only upon complete resultset
returns all result instances
memory footprint unpredicable (maybe large)

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
API	
  -­‐	
  query	
  -­‐	
  lazy	
  list	
  

List<GFile> query("type='file' and lastmodified>'20130901'");

•  List can be lazy and custom implementation
•  that only stores primkeys
•  builds instance on demand
•  returns only upon complete resultset
•  less memory footprint

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
API	
  -­‐	
  query	
  -­‐	
  iterator	
  

Iterator<GFile> query("type='file' and lastmodified>'20130901'");

•  Iterator can be lazy and custom implementation
•  and builds instance on demand
•  uses DB cursor and reads on demand
•  less memory footprint
•  result can only be consumed once

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
API	
  -­‐	
  track	
  objects	
  "idea"	
  
• 	
  track	
  "framework"	
  objects	
  that	
  the	
  applica6on	
  holds	
  on	
  too	
  
• 	
  for	
  sta6s6cs	
  
• 	
  for	
  error	
  logging	
  
›  i.e.	
  "more	
  than	
  10.000	
  file	
  resources	
  WARN"	
  
• 	
  Implementa6on	
  
›  store	
  all	
  returned	
  object	
  in	
  a	
  WeakHashMap	
  
›  GC	
  removes	
  objects	
  when	
  there	
  is	
  no	
  hard	
  reference	
  
›  WeakHashMap.size()	
  can	
  give	
  you	
  an	
  ESTIMATE	
  	
  

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
API	
  -­‐	
  famous	
  "count"	
  implementa6on	
  

public long notYetSyncFiles() {
localStore.query("type='file' and changed='true'").size();
}

WASTE

public long notYetSyncFiles() {
localStore.queryCount("type='file' and changed='true'");
}

OK

looks trivial, but its a real world example :-)

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
API	
  -­‐	
  mapping	
  to	
  String	
  
• 	
  fields	
  that	
  have	
  a	
  limited	
  number	
  of	
  values	
  
›  true	
  /	
  false	
  
›  bitsets	
  (1,8,128,32)	
  
›  filetypes	
  'file'	
  /	
  'directory'	
  

•  intern() is expensive
•  PermGen stores 'intern'
•  small space
•  since Java7 in Heap

›  etc.	
  
• 	
  if	
  you	
  read	
  those	
  a	
  lot	
  from	
  DB	
  or	
  remote	
  services*	
  
›  you	
  quickly	
  have	
  10.000	
  or	
  more	
  instances	
  of	
  'true'	
  
if (value.equals("true") || value.equals("false") || ... {
value = value.intern(value);
}

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Cache	
  /	
  API	
  -­‐	
  Summary	
  

Cache must not
change the
behaviour

Use existing
Cache
implementations

Caches must be
aware of
database
behaviour (ACID)

API must scale

Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
Copyright © 2009 compeople AG, Made available under the Eclipse Public License v 1.0

Más contenido relacionado

La actualidad más candente

How Helm, The Package Manager For Kubernetes, Works
How Helm, The Package Manager For Kubernetes, WorksHow Helm, The Package Manager For Kubernetes, Works
How Helm, The Package Manager For Kubernetes, WorksMatthew Farina
 
Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013
Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013
Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013Puppet
 
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법Open Source Consulting
 
OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2Amar Kapadia
 
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDrupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDropsolid
 
OpenStack DevStack Tutorial
OpenStack DevStack TutorialOpenStack DevStack Tutorial
OpenStack DevStack TutorialSaju Madhavan
 
開放運算&GPU技術研究班
開放運算&GPU技術研究班開放運算&GPU技術研究班
開放運算&GPU技術研究班Paul Chao
 
Installation Openstack Swift
Installation Openstack SwiftInstallation Openstack Swift
Installation Openstack Swiftymtech
 
Introductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformIntroductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformMichael Heyns
 
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data EngineeraConfitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data EngineeraPiotr Wikiel
 
Async and Non-blocking IO w/ JRuby
Async and Non-blocking IO w/ JRubyAsync and Non-blocking IO w/ JRuby
Async and Non-blocking IO w/ JRubyJoe Kutner
 
Install elasticsearch, logstash and kibana
Install elasticsearch, logstash and kibana Install elasticsearch, logstash and kibana
Install elasticsearch, logstash and kibana Chanaka Lasantha
 
tack Deployment in the Enterprise
tack Deployment in the Enterprisetack Deployment in the Enterprise
tack Deployment in the EnterpriseCisco Canada
 
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on DockerRunning High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on DockerSematext Group, Inc.
 
HBaseConEast2016: HBase on Docker with Clusterdock
HBaseConEast2016: HBase on Docker with ClusterdockHBaseConEast2016: HBase on Docker with Clusterdock
HBaseConEast2016: HBase on Docker with ClusterdockMichael Stack
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Antonios Giannopoulos
 

La actualidad más candente (20)

How Helm, The Package Manager For Kubernetes, Works
How Helm, The Package Manager For Kubernetes, WorksHow Helm, The Package Manager For Kubernetes, Works
How Helm, The Package Manager For Kubernetes, Works
 
Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013
Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013
Deploying VMware vCloud Hybrid Service with Puppet - PuppetConf 2013
 
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법[오픈소스컨설팅] EFK Stack 소개와 설치 방법
[오픈소스컨설팅] EFK Stack 소개와 설치 방법
 
OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2OpenStack Swift Command Line Reference Diablo v1.2
OpenStack Swift Command Line Reference Diablo v1.2
 
Geode on Docker
Geode on DockerGeode on Docker
Geode on Docker
 
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google CloudDrupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
Drupaljam 2017 - Deploying Drupal 8 onto Hosted Kubernetes in Google Cloud
 
OpenStack DevStack Tutorial
OpenStack DevStack TutorialOpenStack DevStack Tutorial
OpenStack DevStack Tutorial
 
3 Git
3 Git3 Git
3 Git
 
開放運算&GPU技術研究班
開放運算&GPU技術研究班開放運算&GPU技術研究班
開放運算&GPU技術研究班
 
Installation Openstack Swift
Installation Openstack SwiftInstallation Openstack Swift
Installation Openstack Swift
 
Why Go Lang?
Why Go Lang?Why Go Lang?
Why Go Lang?
 
Introductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformIntroductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with Terraform
 
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data EngineeraConfitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
Confitura 2018 — Apache Beam — Promyk Nadziei Data Engineera
 
Docker
DockerDocker
Docker
 
Async and Non-blocking IO w/ JRuby
Async and Non-blocking IO w/ JRubyAsync and Non-blocking IO w/ JRuby
Async and Non-blocking IO w/ JRuby
 
Install elasticsearch, logstash and kibana
Install elasticsearch, logstash and kibana Install elasticsearch, logstash and kibana
Install elasticsearch, logstash and kibana
 
tack Deployment in the Enterprise
tack Deployment in the Enterprisetack Deployment in the Enterprise
tack Deployment in the Enterprise
 
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on DockerRunning High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
 
HBaseConEast2016: HBase on Docker with Clusterdock
HBaseConEast2016: HBase on Docker with ClusterdockHBaseConEast2016: HBase on Docker with Clusterdock
HBaseConEast2016: HBase on Docker with Clusterdock
 
Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018 Elastic 101 tutorial - Percona Europe 2018
Elastic 101 tutorial - Percona Europe 2018
 

Similar a Ece2013 Java Advanced Memorymanagement

Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Gaetano Giunta
 
Developingapiplug insforcs-151112204727-lva1-app6891
Developingapiplug insforcs-151112204727-lva1-app6891Developingapiplug insforcs-151112204727-lva1-app6891
Developingapiplug insforcs-151112204727-lva1-app6891NetApp
 
Solid fire cloudstack storage overview - CloudStack European User Group
Solid fire cloudstack storage overview - CloudStack European User GroupSolid fire cloudstack storage overview - CloudStack European User Group
Solid fire cloudstack storage overview - CloudStack European User GroupShapeBlue
 
CloudStack Meetup London - Primary Storage Presentation by SolidFire
CloudStack Meetup London - Primary Storage Presentation by SolidFire CloudStack Meetup London - Primary Storage Presentation by SolidFire
CloudStack Meetup London - Primary Storage Presentation by SolidFire NetApp
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Hyun-Mook Choi
 
Goroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoGoroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoYu-Shuan Hsieh
 
Think Distributed: The Hazelcast Way
Think Distributed: The Hazelcast WayThink Distributed: The Hazelcast Way
Think Distributed: The Hazelcast WayRahul Gupta
 
Distributed caching and computing v3.7
Distributed caching and computing v3.7Distributed caching and computing v3.7
Distributed caching and computing v3.7Rahul Gupta
 
Philipp Krenn, Elastic. From Containers to Kubernetes Operators
Philipp Krenn, Elastic. From Containers to Kubernetes OperatorsPhilipp Krenn, Elastic. From Containers to Kubernetes Operators
Philipp Krenn, Elastic. From Containers to Kubernetes OperatorsIT Arena
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeMarco Gralike
 
Earth Engine on Google Cloud Platform (GCP)
Earth Engine on Google Cloud Platform (GCP)Earth Engine on Google Cloud Platform (GCP)
Earth Engine on Google Cloud Platform (GCP)Runcy Oommen
 
Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2Imesh Gunaratne
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best PracticesBurt Beckwith
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedToru Wonyoung Choi
 
Scale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App FabricScale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App FabricChris Dufour
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins buildacloud
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Leejaxconf
 
StorageQuery: federated querying on object stores, powered by Alluxio and Presto
StorageQuery: federated querying on object stores, powered by Alluxio and PrestoStorageQuery: federated querying on object stores, powered by Alluxio and Presto
StorageQuery: federated querying on object stores, powered by Alluxio and PrestoAlluxio, Inc.
 
Painless ruby deployment on shelly cloud
Painless ruby deployment on shelly cloudPainless ruby deployment on shelly cloud
Painless ruby deployment on shelly cloudGiedrius Rimkus
 

Similar a Ece2013 Java Advanced Memorymanagement (20)

Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
 
Developingapiplug insforcs-151112204727-lva1-app6891
Developingapiplug insforcs-151112204727-lva1-app6891Developingapiplug insforcs-151112204727-lva1-app6891
Developingapiplug insforcs-151112204727-lva1-app6891
 
Solid fire cloudstack storage overview - CloudStack European User Group
Solid fire cloudstack storage overview - CloudStack European User GroupSolid fire cloudstack storage overview - CloudStack European User Group
Solid fire cloudstack storage overview - CloudStack European User Group
 
CloudStack Meetup London - Primary Storage Presentation by SolidFire
CloudStack Meetup London - Primary Storage Presentation by SolidFire CloudStack Meetup London - Primary Storage Presentation by SolidFire
CloudStack Meetup London - Primary Storage Presentation by SolidFire
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부
 
Goroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoGoroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in Go
 
Caching. api. http 1.1
Caching. api. http 1.1Caching. api. http 1.1
Caching. api. http 1.1
 
Think Distributed: The Hazelcast Way
Think Distributed: The Hazelcast WayThink Distributed: The Hazelcast Way
Think Distributed: The Hazelcast Way
 
Distributed caching and computing v3.7
Distributed caching and computing v3.7Distributed caching and computing v3.7
Distributed caching and computing v3.7
 
Philipp Krenn, Elastic. From Containers to Kubernetes Operators
Philipp Krenn, Elastic. From Containers to Kubernetes OperatorsPhilipp Krenn, Elastic. From Containers to Kubernetes Operators
Philipp Krenn, Elastic. From Containers to Kubernetes Operators
 
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco GralikeBoost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
Boost Your Environment With XMLDB - UKOUG 2008 - Marco Gralike
 
Earth Engine on Google Cloud Platform (GCP)
Earth Engine on Google Cloud Platform (GCP)Earth Engine on Google Cloud Platform (GCP)
Earth Engine on Google Cloud Platform (GCP)
 
Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2
 
Grails Plugin Best Practices
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best Practices
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO Extended
 
Scale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App FabricScale Your Data Tier With Windows Server App Fabric
Scale Your Data Tier With Windows Server App Fabric
 
Storage Plug-ins
Storage Plug-ins Storage Plug-ins
Storage Plug-ins
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
 
StorageQuery: federated querying on object stores, powered by Alluxio and Presto
StorageQuery: federated querying on object stores, powered by Alluxio and PrestoStorageQuery: federated querying on object stores, powered by Alluxio and Presto
StorageQuery: federated querying on object stores, powered by Alluxio and Presto
 
Painless ruby deployment on shelly cloud
Painless ruby deployment on shelly cloudPainless ruby deployment on shelly cloud
Painless ruby deployment on shelly cloud
 

Último

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Ece2013 Java Advanced Memorymanagement

  • 1. Memory API Java  -­‐  Advanced  Memory  Management   Chris6an  Campo  -­‐  EclipseCon  Europe  2013  
  • 2. Agenda   •   Overview   •   Challenges   •   Cache  Problems   •   API   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 3. Overview   Private filesystem Hierarchical datastructure • root, folders, files, attributes, binary content Simultaneous read/write from multiple threads • application UI, synchronizer, filesystem driver etc. Stored in sql database Schema is dynamic (columns added at runtime) No OR-Mapper Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 4. Data  model   "/" /docs /docs/a.txt <root> "docs" "images" "a.txt" Attributes: -  lastmodified -  length -  owner -  customernumber Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0 /images
  • 5. Components   Application Synchronizer(Daemon) Store API Files / Directories Nodes SQL Access Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0 Virtual File System
  • 6. Challenges   •   Repe66ve  queries  (aHributes)   ›  Windows  assumes  any  FileSystem  opera6on  as  cheap   •   Applica6on  developer  don't  think  about  internals   ›  they  assume  that  any  API  call  is  cheap  and  fast   •   Data  structure  is  dynamic   •   Growing  size  of  data   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 7. Developer  stereotypes   Application Developer Framework Developer DB Developer • ACID • transactions • logic should be a stored procedure • db has buffer (=cache) • clean and small API • refactor often • DBs are too slow à cache Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0 • never refactor :-) • wrap every framework • Framework is too slow à cache • why cant I access the DB directly ? :-)
  • 8. Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 9. Cache  -­‐  Requirements   Rule #1: Cache improves speed but does not change functionality Rule #2: Cache must not lead to OOM Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 10. Virtual  File  System  -­‐  FileCache   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 11. Virtual  File  System  -­‐  FileCache   tempting to add a cache often lists children of a directory build "MyCache" :-) Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 12. VFS  -­‐  "MyCache"  V1.0   private WeakHashMap<String, List<GFile> > cache = new WeakHashMap<String, List<GFile> >(); private Store store; public synchronized List<GFile> list( final GFile gFile ) { List<GFile> list = cache.get(gFile.getPath()); if ( list == null) { list = store.list(goyaFile ); cache.put(gFile.getPath(), list ); } return list; } Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 13. VFS  -­‐  "MyCache"  V1.0  -­‐  junit  test   // create + write content for (int x=0; x<100; x++) { GFile file = store.create(new GFile("/docs/test" +x+ ".txt")); } // check for (int x=0; x<100; x++) { List<GFile> list = list(new GFile("/docs")); assertTrue(list.contains(new GFile("/docs/test" +x+ ".txt"))); } // list from "MyCache" public synchronized List<GFile> list( final GFile gFile ) {} OK + FASTER with Cache Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 14. VFS  -­‐  "MyCache"  V1.0  -­‐  junit  test   // create + write content + check for (int x=0; x<100; x++) { GFile file = store.create(new GFile("/docs/test“ +x+ ".txt")); List<GFile> list = list(new GFile("/docs")); assertTrue(list.contains(new GFile("/docs/test“ +x+ ".txt"))); } // list from "MyCache" public synchronized List<GFile> list( final Store store, final GFile gFile ) {} FAILS with Cache -> expiration time for cache entries Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 15. VFS  -­‐  MyCache  V2.0   private long EXPIRATION_TIME = 200; private WeakHashMap<String, MyCacheEntry> cache = new WeakHashMap<String, MyCacheEntry>(); public synchronized List<GFile> list( final LocalStore store, final GFile gFile ) { final MyCacheEntry myCacheEntry = cache.get(gFile.getPath()); if ( myCacheEntry == null || System.currentTimeMillis() - { class MyCacheEntry public List<GFile> listGFiles; EXPIRATION_TIME > myCacheEntry.currentTimeMillis ) { public long currentTime; final List<GoyaFile> listGoyaFiles = store.list( goyaFile ); MyCacheEntry( final List<GFile> cache.put(gFile.getPath(), new MyCacheEntry( listGoyaFiles ) ); listGFiles ) { this.listGFiles = listGFiles; return listGoyaFiles; this.currentTime = System.currentTimeMillis(); } } else { } return myCacheEntry.listGoyaFiles; } Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 16. Virtual  FS  -­‐  MyCache  V2.0  -­‐  more  problems  ...   •   It  was  hard  to  find  a  good  value  for  EXPIRATION_TIME   ›  200  ms  effec6ve  but  it  was  easy  to  get  wrong  HITS   ›  10  ms  beFer  (not  always  right)  but  not  many  HITS   •   implement  a  maximum  number  of  entries   •   find  means  to  "know"  when  CacheEntries  are  invalid   •   sta6s6cs  ?   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 17. Virtual  FS  -­‐  LoadingCache  (Guava)   private final LoadingCache<String, List<GFile>> cache = CacheBuilder.newBuilder() .maximumSize( 10 ) .softValues() .expireAfterWrite( 200, TimeUnit.MILLISECONDS) .build( new CacheLoader<String, List<GFile>>() { public List<GFile> load( final String path ) { return store.list( new GFile( path ) ); } } ); Rule #3: Never write your own Cache implementation Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 18. Virtual  FS  -­‐  invalida6ng  CacheEntries   public GFile create(GFile file) { GFile g = store.create(file); cache.flush(); return g; } public GFile create(GFile file) { GFile g = store.create(file); cache.remove(getParent(file).getPath()); return g; } Rule #4: Have a strategy for removing cache entries (expiration timing alone does not work) Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 19. AHribute  Cache   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 20. AHribute  Cache   •   heavy  load  on  the  db   •   a  lot  of  read  opera6ons  on  aHributes   •   not  many  writes   •   à  cache  aHributes   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 21. AHribute  Cache   private final Map<String, String> attributesCache; public String getAttribute( final String name ) { String value = attributesCache.get( name ); if (value!=null) { return value; } ... // read it from DB } public void setAttribute( final String name, String value) { if ( !Objects.equal( value, attributesCache.get( name ) ) ) { attributesCache.put( name, value ); ... // update attribute in the database } } Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 22. AHribute  Cache  -­‐  Junit  test   // previous value of length = "1057" db.transaction(new DbRunnable() { protected void run() { file.setAttribute("length", "0"); long newLength = store.put(file, inputStream); file.setAttribute("length", new String(newLength)) public void setAttribute(final String name,String value) { } if(!Objects.equal(value, attributeCache.get(name))){ }); attributesCache.put( name, value ); ... ... // update attribute in the database } file.setAttribute("length", "0"); •  •  •  •  IOException reading inputStream transaction rolls back attribute length = "0" in Cache and has "1057" in DB setAttribute("length","0") after Transaction, does not reach DB Rule #5: Cache should be aware of transaction rollbacks Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 23. AHribute  Cache  -­‐  Transac6ons   private final Map<String, Optional<String>> attributesCache; private void init() { getTransaction().register(this); } public String getAttribute( final String key ) { ... } public void setAttribute( final String name, String value) {} public void rollback() { // called when transaction rolls back attributesCache.flush(); } Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 24. AHribute  Cache  -­‐  Transac6ons   db.transaction(new DbRunnable() { try { store.put(file, inputStream); file.setAttribute("loaded","true"); } catch (IOException ioe) { file.setAttribute("loaded","false"); throw ioe; } }); •  IOException -> transaction rollback •  loaded = "false" NOT in Cache, NOT in DB •  Cache changes behaviour once it does Transaction rollback. •  Rule #6 Dont return with Exception if data should not rollback Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 25. AHribute  Cache  -­‐  Isola6on   Component A Component B Transaction 1 Transaction 2 ??? x=? GFile Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 26. AHributeCache  -­‐  Isola6on  -­‐  Solu6on  1   public void setAttribute( final String name, String value ) { ... getTransaction().getContext().set( ... + name, value ); ... } public String getAttribute(String name) { ... String value = getTransaction().getContext().get( ... + name ); ... } •  store cached values global IN the transaction context •  however all attribute values are stored in Transaction Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 27. AHributeCache  -­‐  Isola6on  -­‐  Solu6on  2  (beHer)   private HashMap<String, String> cache=new HashMap<String,String>(); public void setAttribute( final String name, String value) { ... cache.put(getTransactionId() + name, value); ... } public String getAttribute(String name) { ... String value = cache.get(getTransactionId() + name); ... } store cached values local depending on transaction-id Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 28. ChunkCache  -­‐  data  with  dirty  state   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 29. ChunkCache  -­‐  data  with  dirty  state   Virtual FileSystem •  •  •  •  •  •  ChunkFileStore "write offset=110.000 length=2000" "write..." "write..." "write..." "write..." "write..." 010110010101 010101010101 010110010101 010101101000 010101010101 010110010101 11110101 010101101000 010101010101 010110010101 11110101 010101101000 010101010101 11110101 010101101000 11110101 • VFS  writes  and  reads  data  in  random  "segments"   ›  i.e.  "write  offset  110.000  length  200"   •   Stored  on  disk  in  1  MB  "Chunks"   Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0 Chunks (1 MB)
  • 30. ChunkCache  -­‐  data  with  dirty  state   Virtual FileSystem •  "write offset=110.000 length=200" •  "write..." ChunkCache 010110010101 010101010101 010110010101 010101101000 010101010101 11110101 010101101000 11110101 •   Cache  writes  lazy   •   Cache  maintained  in  dirty  state   •   LoadingCache  used   •   6meout,  maxsize   ChunkFileStore 010110010101 010101010101 010110010101 010101101000 010101010101 010110010101 11110101 010101101000 010101010101 010110010101 11110101 010101101000 010101010101 11110101 010101101000 11110101 Chunks (1 MB) Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 31. ChunkCache  -­‐  data  with  dirty  state   private final LoadingCache<Integer, Chunk> cache = CacheBuilder.newBuilder() .maximumSize(4) .expireAfterAccess(2, TimeUnit.SECONDS) .removalListener(new RemovalListener<Integer, Chunk>() { public void onRemoval(final RemovalNotification<Integer, Chunk> notification ) { if ( notification.getValue().isDirty() ) { // write chunk •  write to disk on remove } •  cache entries only expire on access !! } •  no automatic housekeeping }) .build( new CacheLoader<Integer, Chunk>() { public Chunk load( final Integer key ) throws Exception { // load Chunk for key } } ); Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 32. Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 33. API  -­‐  query  -­‐  list   query  for  resources  sa6sfying  a  condi6on     ArrayList<GFile> query("type='file' and lastmodified>'20130901' "); •  •  •  •  can produce a lot of instances returns only upon complete resultset returns all result instances memory footprint unpredicable (maybe large) Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 34. API  -­‐  query  -­‐  lazy  list   List<GFile> query("type='file' and lastmodified>'20130901'"); •  List can be lazy and custom implementation •  that only stores primkeys •  builds instance on demand •  returns only upon complete resultset •  less memory footprint Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 35. API  -­‐  query  -­‐  iterator   Iterator<GFile> query("type='file' and lastmodified>'20130901'"); •  Iterator can be lazy and custom implementation •  and builds instance on demand •  uses DB cursor and reads on demand •  less memory footprint •  result can only be consumed once Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 36. API  -­‐  track  objects  "idea"   •   track  "framework"  objects  that  the  applica6on  holds  on  too   •   for  sta6s6cs   •   for  error  logging   ›  i.e.  "more  than  10.000  file  resources  WARN"   •   Implementa6on   ›  store  all  returned  object  in  a  WeakHashMap   ›  GC  removes  objects  when  there  is  no  hard  reference   ›  WeakHashMap.size()  can  give  you  an  ESTIMATE     Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 37. API  -­‐  famous  "count"  implementa6on   public long notYetSyncFiles() { localStore.query("type='file' and changed='true'").size(); } WASTE public long notYetSyncFiles() { localStore.queryCount("type='file' and changed='true'"); } OK looks trivial, but its a real world example :-) Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 38. API  -­‐  mapping  to  String   •   fields  that  have  a  limited  number  of  values   ›  true  /  false   ›  bitsets  (1,8,128,32)   ›  filetypes  'file'  /  'directory'   •  intern() is expensive •  PermGen stores 'intern' •  small space •  since Java7 in Heap ›  etc.   •   if  you  read  those  a  lot  from  DB  or  remote  services*   ›  you  quickly  have  10.000  or  more  instances  of  'true'   if (value.equals("true") || value.equals("false") || ... { value = value.intern(value); } Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 39. Cache  /  API  -­‐  Summary   Cache must not change the behaviour Use existing Cache implementations Caches must be aware of database behaviour (ACID) API must scale Copyright © 2013 compeople AG, Made available under the Eclipse Public License v 1.0
  • 40. Copyright © 2009 compeople AG, Made available under the Eclipse Public License v 1.0