Caching with MongoDB




 Charles Blonde
Guillaume Arnaud
  Pablo Lopez
Other caching systems


  In memory                       Centralized
   EHcache                        Memcached
   Gemfire                        Redis
                                   Gemfire




                        www.xebia.fr / blog.xebia.fr   3
The needs


 Switching from statefull EJB to Web services : sessions
  caching

 Highly available

 Speed & Multipurpose

 High volumes

 Future : replace existing cache systems

                             www.xebia.fr / blog.xebia.fr   2
MongoDB as a caching system


  Pros                             Cons
   TTL Support in MongoDB          Speed
    2.2
                                    Disk usage
   Higly available
   Scalable
   Automatic failover
   Easy to use


                         www.xebia.fr / blog.xebia.fr   4
Testing

 Writing a Tomcat valve and a sample Web application

 Setting up an environment :
   ▶   1 MongoDB Replicaset
   ▶   Between 2 and 6 applications servers
   ▶   1 load balancer


 Stress tests

 Results
   ▶   1300 req/sec => 5ms avg



                               www.xebia.fr / blog.xebia.fr   5
Tuning


 Disable journaling

 Write concern /read preferences

 Oplog sizing

 Sharding ?




                            www.xebia.fr / blog.xebia.fr   6

A Morning with MongoDB Paris 2012 - Xebia

  • 1.
    Caching with MongoDB Charles Blonde Guillaume Arnaud Pablo Lopez
  • 2.
    Other caching systems In memory Centralized  EHcache  Memcached  Gemfire  Redis  Gemfire www.xebia.fr / blog.xebia.fr 3
  • 3.
    The needs  Switchingfrom statefull EJB to Web services : sessions caching  Highly available  Speed & Multipurpose  High volumes  Future : replace existing cache systems www.xebia.fr / blog.xebia.fr 2
  • 4.
    MongoDB as acaching system Pros Cons  TTL Support in MongoDB  Speed 2.2  Disk usage  Higly available  Scalable  Automatic failover  Easy to use www.xebia.fr / blog.xebia.fr 4
  • 5.
    Testing  Writing aTomcat valve and a sample Web application  Setting up an environment : ▶ 1 MongoDB Replicaset ▶ Between 2 and 6 applications servers ▶ 1 load balancer  Stress tests  Results ▶ 1300 req/sec => 5ms avg www.xebia.fr / blog.xebia.fr 5
  • 6.
    Tuning  Disable journaling Write concern /read preferences  Oplog sizing  Sharding ? www.xebia.fr / blog.xebia.fr 6