SlideShare a Scribd company logo
1 of 47
Download to read offline
1
<Insert Picture Here>




The Native NDB Engine for Memcached
John David Duncan
john.duncan@oracle.com

                                      2
Program Agenda


                                   <Insert Picture Here>




•   MySQL Cluster Today
•   A little bit about memcached
•   Design Decisions
•   Configuration
•   Performance
•   Links
•   Demo




                                                           3
The following is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any features
or functionality described for Oracle’s products
remains at the sole discretion of Oracle.




                                                       4
<Insert Picture Here>



MySQL Cluster Today




                                              5
The Basics

                      API Nodes




     Node Group 1                Node Group 2
                    NDB Data Nodes


                                                6
The Basics – Data Storage

  • High Read and Write Performance
  – Automatic data partitioning, multi-master, parallel execution
  • High Availability
  • Fast Failover
  – sub-second fault detection and reconfiguration
  • Scalable
  – Using commodity hardware




      Node Group 1                  Node Group 2
                       NDB Data Nodes


                                                                    7
The Basics – Data Access

                         API Nodes




 • High throughput
 – tens-to-hundreds of thousands of transactions per second
 • Low latency
 – sub-millisecond response
 • Multiple Acceess Methods
 – SQL and NoSQL




                                                              8
Recent History

• Cluster 6.3 (2008)
  – multi-master replication, key-distribution awareness
• Cluster 7.0 (2009)
  – Multi-threaded NDB nodes
  – Ability to add nodes online to a running cluster
• Cluster 7.1 (2010)
  –   ClusterJ
  –   MySQL Cluster Manager
  –   ndbinfo (and then MEM support for Cluster)
  –   Windows support
• Plus
  – Extensive improvements to BLOB performance, locking
    behavior, node restart times, etc. in monthly releases



                                                             9
ClusterJ Example


Employee findEmployee(long id) {
   Employee employee = session.find(Employee.class, id);
   return employee;
}


• Runs faster than JDBC
• Almost as fast as the C++ NDB API
• 3 lines of code




                                                          10
MySQL Cluster 7.2 Beta


• Push-Down Joins
  – Many “SPJ” (Select/Project/Join) operations can be executed
    at the data nodes rather than the MySQL server
  – Long-term effort (presented at this conference last year)
  – 50x improvement for some queries
• MySQL privilege tables can be stored in cluster
• Memcache API




                                                                  11
<Insert Picture Here>



About memcache




           • It’s a cache!
           • It’s not your data store!
           • If it fails, you get a cache miss!



                                                                  12
Two levels of hashing




                                           memcached
  httpd

                                                        hash key
PHP/Perl                               r   memcached
                               k serve                 to find data
                      y to pic
Memcache     ha sh ke

       friends:12389                       memcached
      memcache Key




                                                                 13
Cache hit




  httpd

                                                                    hash key
PHP/Perl                                  r   memcached
                                  k serve                          to find data
                         y to pic
Memcache        ha sh ke

          friends:12389          VALUE friends:12389 0 31rn
                                 101, 11009, 11150, 55881, 77798 rn




                                                                             14
Cache miss (1): fetch from DB




  httpd

                                                       hash key
PHP/Perl                             r   memcached
                             k serve                  to find data
                    y to pic
Memcache   ha sh ke
                          F OUND
                    NOT
 mysql
           SELECT
                   friend_id
           FROM u                                    MySQL
                  ser_frien
           WHERE            ds
                 user_id =                           Slave
                             ?



                                                                15
Cache miss (2): manage cache




  httpd

                                                               hash key
PHP/Perl                                          memcached
                                                              to find data
Memcache
                                     n             n
                              9 31r        9 8 r
                       : 1238      81 , 777
                  iends 1150, 558
           set fr 09, 1
            10 1, 110




                                                                        16
Data change (1): Write to DB




 httpd


PHP/Perl

 mysql
            INSERT INTO user_friends
            (user_id, friend_id)
            VALUES ( 12389, 999101);
MySQL
Master




                                       17
Data change (2): manage cache




 httpd


PHP/Perl                                   memcached

 mysql                                n
                              3 89 r
                       nds:12
           dele te frie


MySQL
Master




                                                       18
Expected Latency & Throughput




  httpd
                                ons/sec.
                      f operati
           10 ,000s o
                        u nd trip
PHP/Perl   ~2 00 µs ro                 memcached

memcache

 mysql
             1,000s of
                       operatio
             ~ 2 ms ro          ns/sec.            MySQL
                       und trip                    Slave



                                                           19
Cost per n active users




  httpd


PHP/Perl                    $1

memcache

 mysql


                                 $10




                                       20
A little bit more history

• Memcached 1.2 (2007)
  – The 2000-line Facebook patch
     • UDP support
     • Vector I/O and other “details”
        – adding up to 25% improved CPU efficiency
     • Multithreaded (for a small number of libevent threads)
     • Compare-And-Set operation (CAS)
• Memcached 1.4 (2009):
  – Binary Protocol
  – SASL Authentication
• Memcached 1.6 (upcoming)
  – Storage Engines
  – Logging modules
  – Windows platform support


                                                                21
<Insert Picture Here>



Design Decisions




                                           22
Goals



• Access NDB data from memcache clients

 – Memcached perspective:
   • NDB is a reliable, write-scalable, replicated data store

 – MySQL Cluster perspective:
   • memcache is an easy-to-use high performance API




                                                                23
Goals

• Support existing schemas and all MySQL data types

• Cache NDB data inside memcached
  – with automatic cache management
  – and flexibility to fine-tune (or disable) the cache policies


• Support the whole memcache protocol

• Acheive superior performance
  – latency as expected from memcached
  – throughput as expected from memcached



                                                                   24
Which codebase?

                  memcached.org libmemcached   build our own

 Text Protocol         ✔

Binary Protocol        ✔             ✔
     TCP               ✔             ✔
     UDP               ✔
Authentication         ✔
                       ✔



                                                               25
Server Architecture

• Memcached separate from ndbd        • Memcached inside ndbd
  – Definitely!                       – Maybe!
  – “m:n” ratio of memcache servers   – we know how to do it
    to data nodes                        – “embedded” API-to-TC
                                           channel
                                      – lower latency
                                         – network round trip + tens of
                                           microseconds
                                      – Not as flexible
   memcached        memcached
                                               memcached




                                                                          26
Decisions


• Use memcached 1.6 tree
• Isolate the NDB-specific code into an ndb_engine
  – which currently exists outside the memcached source tree
  – and runs in an unmodified memcached server
• Build a standalone server binary
• Possibly also build an ndbmtd-embedded server
• Share code with InnoDB Memcache team
  – on basic configuration and user-visible concepts
  – and on changes that would allow a memcache server module
    to be loaded into either ndbmtd or mysqld




                                                               27
Other decisions


• Memcache INCR & DECR
  – Fully supported
  – Atomic operations
  – Performed at the data node
• Memcache CAS (version id check)
  – Fully Supported
     • either at local cache or at database
  – CAS check is pushed down to the data node
  – Ideally an update that comes from a non-memcache API node
    should invalidate the CAS
     • we still need to decide the best design for this




                                                                28
Limitations


• The size of stored values is limited to the NDB row size
  – currently just less than 8 KB
  – vs. 1 MB typical limit for memcached
  – due to the lack of BLOB support in the async NDB API




                                                             29
Architecture Overview

       Application                     Application




 memcached                      mysqld
                                                         Wide-area
           Local Cache                                   Replication

      NDB Engine                InnoDB     NDB Engine

                                                     binlog stream



 NDB          Data       Data   Data         Data
 Cluster      Node       Node   Node         Node




                                                                     30
<Insert Picture Here>



Configuring It




                                         31
What’s Configurable


• Does it use local cache?
• Does it use NDB?
• What columns hold the keys?
• What columns hold the data?
• Are memcache commands like DELETE and FLUSH
  allowed to delete records from the database?
• You decide all of this ...
• on a “per-key-prefix” basis.




                                                 32
A Key Prefix




                   user:1248

      the prefix               the database key




                                                  33
Fundamentals


• memcached command line specifies a connectstring for
  a primary cluster
• primary = “where the config is stored”
• The NDB Engine reads the configuration tables from
  the ndbmemcache database on the primary cluster
• You, the administrator, manage the config via SQL
• An NDB Memcache server can operate on data in the
  primary cluster or in other clusters
• Different NDB Memcache servers can fetch different
  configurations




                                                         34
Standard Tables in ndbmemcache


• meta
    – stores configuration schema version (for upgrade
      compatibility); consider it to be read-only
• ndb_clusters
• containers
    – where data is stored
• cache_policies
    – how it can be accessed
•   key_prefixes
•   memcache_server_roles
•   last_memcached_signon
•   demo_table


                                                         35
ndb_clusters


• cluster_id
  – int, referenced by key_prefixes
• ndb_connectstring
  – varchar(128) – how to reach this cluster
• microsec_rtt
  – default 250; used for internal performance tuning




                                                        36
containers


•   name
•   schema_name
•   table_name (the existing table where your data lives)
•   key_columns (comma-separated)
•   value_columns (comma-separated)
•   flags (either a constant number, or a column name)
•   increment_column (optional, for INCR/DECR)
•   cas_column (optional)
•   expire_time_column (optional)




                                                            37
cache_policies


• policy_name
• get_policy
  – enum (cache_only, ndb_only, caching, disabled)
• set_policy
  – enum (cache_only, ndb_only, caching, disabled)
• delete_policy
  – enum (cache_only, ndb_only, caching, disabled)
• flush_from_db
  – enum(false, true)




                                                     38
A key-prefix mapping




Memcache
                                              Cache
   key                  Cluster   Container
                                              Policy
  prefix




                                                       39
A memcache server role
                      key                Con-    Cache
                              Cluster
                     prefix             tainer   Policy

 Server               key                Con-    Cache
  Role                        Cluster
                     prefix             tainer   Policy
   ID

                      key                Con-    Cache
                              Cluster
                     prefix             tainer   Policy


                      key                Con-    Cache
                              Cluster
                     prefix             tainer   Policy




                                                          40
key_prefixes


•   server_role_id
•   key_prefix
•   cluster_id
•   policy
•   container




                     41
demo_table


• Not really part of the configuration ...

• mkey
  – varchar(250) NOT NULL PRIMARY KEY
• math_value
  – bigint unsigned
• cas_value
  – bigint unsigned
• string_value
  – varchar(7500)




                                             42
<Insert Picture Here>



Performance




                                      43
Measured Latency            memcachetest -t 2 -M 7000 -c 25000

1000




500
                                                        95th

                           351             374
                                                       avg.

               184                                      min.
       98

!sec
               Memcached          NDB         NDB         Write
       ICMP
                 Default         1-Node      2-Node
        ping                                              Read
                 Engine          Cluster     Cluster


                                                                  44
Links
• This Presentation
  – http://en.oreilly.com/mysql2011/

• Memcached 1.6 development tree
  – git clone git://github.com/memcached/memcached
  – cd memcached
  – git checkout -t origin/engine-pu

• MySQL Cluster 7.2 with Memcached Engine
  – bzr clone lp:~mysql/mysql-server/mysql-cluster-7.2-labs-memcached
  – or look for it at labs.mysql.com

• Mailing List
  – cluster@lists.mysql.com




                                                                    45
Demo


• What we’ll see:
  – Memcache Server Window
     • start memcached “sandbox”
        – default role (NDB-only)
        – mc-only role (plain memcached)
        – ndb-caching role (NDB with local cache)
  – Client Window
     • run memcapable
  – MyQSL Window
     • examine data and configuration




                                                    46
47

More Related Content

What's hot

Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesOracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Sven Sandberg
 
Paris Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra DriversParis Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra Drivers
Michaël Figuière
 
Cassandra & the Acunu Data Platform
Cassandra & the Acunu Data PlatformCassandra & the Acunu Data Platform
Cassandra & the Acunu Data Platform
Acunu
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deployment
zeeg
 
Oracle 10g Performance: chapter 11 SQL*Net
Oracle 10g Performance: chapter 11 SQL*NetOracle 10g Performance: chapter 11 SQL*Net
Oracle 10g Performance: chapter 11 SQL*Net
Kyle Hailey
 

What's hot (20)

Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesOracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
 
Paris Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra DriversParis Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra Drivers
 
Growing in the Wild. The story by CUBRID Database Developers.
Growing in the Wild. The story by CUBRID Database Developers.Growing in the Wild. The story by CUBRID Database Developers.
Growing in the Wild. The story by CUBRID Database Developers.
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Keith Larson Replication
Keith Larson ReplicationKeith Larson Replication
Keith Larson Replication
 
Elastic Scalability in MySQL Fabric Using OpenStack
Elastic Scalability in MySQL Fabric Using OpenStackElastic Scalability in MySQL Fabric Using OpenStack
Elastic Scalability in MySQL Fabric Using OpenStack
 
Conference slides: MySQL Cluster Performance Tuning
Conference slides: MySQL Cluster Performance TuningConference slides: MySQL Cluster Performance Tuning
Conference slides: MySQL Cluster Performance Tuning
 
Sharding using MySQL and PHP
Sharding using MySQL and PHPSharding using MySQL and PHP
Sharding using MySQL and PHP
 
Cassandra & the Acunu Data Platform
Cassandra & the Acunu Data PlatformCassandra & the Acunu Data Platform
Cassandra & the Acunu Data Platform
 
Cosbench apac
Cosbench apacCosbench apac
Cosbench apac
 
MySQL Fabric: Easy Management of MySQL Servers
MySQL Fabric: Easy Management of MySQL ServersMySQL Fabric: Easy Management of MySQL Servers
MySQL Fabric: Easy Management of MySQL Servers
 
Exchange 2010 ha ctd
Exchange 2010 ha ctdExchange 2010 ha ctd
Exchange 2010 ha ctd
 
cosbench-openstack.pdf
cosbench-openstack.pdfcosbench-openstack.pdf
cosbench-openstack.pdf
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]
 
Practicing Continuous Deployment
Practicing Continuous DeploymentPracticing Continuous Deployment
Practicing Continuous Deployment
 
State of the Dolphin, at db tech showcase Osaka 2014
State of the Dolphin, at db tech showcase Osaka 2014State of the Dolphin, at db tech showcase Osaka 2014
State of the Dolphin, at db tech showcase Osaka 2014
 
Oracle 10g Performance: chapter 11 SQL*Net
Oracle 10g Performance: chapter 11 SQL*NetOracle 10g Performance: chapter 11 SQL*Net
Oracle 10g Performance: chapter 11 SQL*Net
 
MySQL Cluster 8.0 tutorial text
MySQL Cluster 8.0 tutorial textMySQL Cluster 8.0 tutorial text
MySQL Cluster 8.0 tutorial text
 
Introduction to Galera
Introduction to GaleraIntroduction to Galera
Introduction to Galera
 
NoSQL Database
NoSQL DatabaseNoSQL Database
NoSQL Database
 

Similar to The Native NDB Engine for Memcached

Scaling Rails with memcached
Scaling Rails with memcachedScaling Rails with memcached
Scaling Rails with memcached
elliando dias
 
Membase Meetup Chicago - january 2011
Membase Meetup Chicago - january 2011Membase Meetup Chicago - january 2011
Membase Meetup Chicago - january 2011
Membase
 
Moving from C#/.NET to Hadoop/MongoDB
Moving from C#/.NET to Hadoop/MongoDBMoving from C#/.NET to Hadoop/MongoDB
Moving from C#/.NET to Hadoop/MongoDB
MongoDB
 
A memcached implementation in Java
A memcached implementation in JavaA memcached implementation in Java
A memcached implementation in Java
elliando dias
 
SQL on Hadoop: Defining the New Generation of Analytic SQL Databases
SQL on Hadoop: Defining the New Generation of Analytic SQL DatabasesSQL on Hadoop: Defining the New Generation of Analytic SQL Databases
SQL on Hadoop: Defining the New Generation of Analytic SQL Databases
OReillyStrata
 
Memcache - Lightning fast object retrieval
Memcache - Lightning fast object retrievalMemcache - Lightning fast object retrieval
Memcache - Lightning fast object retrieval
elliando dias
 
MySQL cluster 72 in the Cloud
MySQL cluster 72 in the CloudMySQL cluster 72 in the Cloud
MySQL cluster 72 in the Cloud
Marco Tusa
 

Similar to The Native NDB Engine for Memcached (20)

Scaling Rails with memcached
Scaling Rails with memcachedScaling Rails with memcached
Scaling Rails with memcached
 
Give Your Site a Boost with Memcache
Give Your Site a Boost with MemcacheGive Your Site a Boost with Memcache
Give Your Site a Boost with Memcache
 
Membase Meetup Chicago - january 2011
Membase Meetup Chicago - january 2011Membase Meetup Chicago - january 2011
Membase Meetup Chicago - january 2011
 
Moving from C#/.NET to Hadoop/MongoDB
Moving from C#/.NET to Hadoop/MongoDBMoving from C#/.NET to Hadoop/MongoDB
Moving from C#/.NET to Hadoop/MongoDB
 
NoSQL with MySQL
NoSQL with MySQLNoSQL with MySQL
NoSQL with MySQL
 
Memcached Presentation
Memcached PresentationMemcached Presentation
Memcached Presentation
 
Implementing High Availability Caching with Memcached
Implementing High Availability Caching with MemcachedImplementing High Availability Caching with Memcached
Implementing High Availability Caching with Memcached
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal Sites
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
A memcached implementation in Java
A memcached implementation in JavaA memcached implementation in Java
A memcached implementation in Java
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Memcached And MySQL
Memcached And MySQLMemcached And MySQL
Memcached And MySQL
 
NoSQL Data Stores: Introduzione alle Basi di Dati Non Relazionali
NoSQL Data Stores: Introduzione alle Basi di Dati Non RelazionaliNoSQL Data Stores: Introduzione alle Basi di Dati Non Relazionali
NoSQL Data Stores: Introduzione alle Basi di Dati Non Relazionali
 
SQL on Hadoop: Defining the New Generation of Analytic SQL Databases
SQL on Hadoop: Defining the New Generation of Analytic SQL DatabasesSQL on Hadoop: Defining the New Generation of Analytic SQL Databases
SQL on Hadoop: Defining the New Generation of Analytic SQL Databases
 
No sql presentation
No sql presentationNo sql presentation
No sql presentation
 
Memcache - Lightning fast object retrieval
Memcache - Lightning fast object retrievalMemcache - Lightning fast object retrieval
Memcache - Lightning fast object retrieval
 
MySQL cluster 72 in the Cloud
MySQL cluster 72 in the CloudMySQL cluster 72 in the Cloud
MySQL cluster 72 in the Cloud
 
Vote NO for MySQL
Vote NO for MySQLVote NO for MySQL
Vote NO for MySQL
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbase
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
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
Safe Software
 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
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
 
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...
 
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
 

The Native NDB Engine for Memcached

  • 1. 1
  • 2. <Insert Picture Here> The Native NDB Engine for Memcached John David Duncan john.duncan@oracle.com 2
  • 3. Program Agenda <Insert Picture Here> • MySQL Cluster Today • A little bit about memcached • Design Decisions • Configuration • Performance • Links • Demo 3
  • 4. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 4
  • 5. <Insert Picture Here> MySQL Cluster Today 5
  • 6. The Basics API Nodes Node Group 1 Node Group 2 NDB Data Nodes 6
  • 7. The Basics – Data Storage • High Read and Write Performance – Automatic data partitioning, multi-master, parallel execution • High Availability • Fast Failover – sub-second fault detection and reconfiguration • Scalable – Using commodity hardware Node Group 1 Node Group 2 NDB Data Nodes 7
  • 8. The Basics – Data Access API Nodes • High throughput – tens-to-hundreds of thousands of transactions per second • Low latency – sub-millisecond response • Multiple Acceess Methods – SQL and NoSQL 8
  • 9. Recent History • Cluster 6.3 (2008) – multi-master replication, key-distribution awareness • Cluster 7.0 (2009) – Multi-threaded NDB nodes – Ability to add nodes online to a running cluster • Cluster 7.1 (2010) – ClusterJ – MySQL Cluster Manager – ndbinfo (and then MEM support for Cluster) – Windows support • Plus – Extensive improvements to BLOB performance, locking behavior, node restart times, etc. in monthly releases 9
  • 10. ClusterJ Example Employee findEmployee(long id) { Employee employee = session.find(Employee.class, id); return employee; } • Runs faster than JDBC • Almost as fast as the C++ NDB API • 3 lines of code 10
  • 11. MySQL Cluster 7.2 Beta • Push-Down Joins – Many “SPJ” (Select/Project/Join) operations can be executed at the data nodes rather than the MySQL server – Long-term effort (presented at this conference last year) – 50x improvement for some queries • MySQL privilege tables can be stored in cluster • Memcache API 11
  • 12. <Insert Picture Here> About memcache • It’s a cache! • It’s not your data store! • If it fails, you get a cache miss! 12
  • 13. Two levels of hashing memcached httpd hash key PHP/Perl r memcached k serve to find data y to pic Memcache ha sh ke friends:12389 memcached memcache Key 13
  • 14. Cache hit httpd hash key PHP/Perl r memcached k serve to find data y to pic Memcache ha sh ke friends:12389 VALUE friends:12389 0 31rn 101, 11009, 11150, 55881, 77798 rn 14
  • 15. Cache miss (1): fetch from DB httpd hash key PHP/Perl r memcached k serve to find data y to pic Memcache ha sh ke F OUND NOT mysql SELECT friend_id FROM u MySQL ser_frien WHERE ds user_id = Slave ? 15
  • 16. Cache miss (2): manage cache httpd hash key PHP/Perl memcached to find data Memcache n n 9 31r 9 8 r : 1238 81 , 777 iends 1150, 558 set fr 09, 1 10 1, 110 16
  • 17. Data change (1): Write to DB httpd PHP/Perl mysql INSERT INTO user_friends (user_id, friend_id) VALUES ( 12389, 999101); MySQL Master 17
  • 18. Data change (2): manage cache httpd PHP/Perl memcached mysql n 3 89 r nds:12 dele te frie MySQL Master 18
  • 19. Expected Latency & Throughput httpd ons/sec. f operati 10 ,000s o u nd trip PHP/Perl ~2 00 µs ro memcached memcache mysql 1,000s of operatio ~ 2 ms ro ns/sec. MySQL und trip Slave 19
  • 20. Cost per n active users httpd PHP/Perl $1 memcache mysql $10 20
  • 21. A little bit more history • Memcached 1.2 (2007) – The 2000-line Facebook patch • UDP support • Vector I/O and other “details” – adding up to 25% improved CPU efficiency • Multithreaded (for a small number of libevent threads) • Compare-And-Set operation (CAS) • Memcached 1.4 (2009): – Binary Protocol – SASL Authentication • Memcached 1.6 (upcoming) – Storage Engines – Logging modules – Windows platform support 21
  • 23. Goals • Access NDB data from memcache clients – Memcached perspective: • NDB is a reliable, write-scalable, replicated data store – MySQL Cluster perspective: • memcache is an easy-to-use high performance API 23
  • 24. Goals • Support existing schemas and all MySQL data types • Cache NDB data inside memcached – with automatic cache management – and flexibility to fine-tune (or disable) the cache policies • Support the whole memcache protocol • Acheive superior performance – latency as expected from memcached – throughput as expected from memcached 24
  • 25. Which codebase? memcached.org libmemcached build our own Text Protocol ✔ Binary Protocol ✔ ✔ TCP ✔ ✔ UDP ✔ Authentication ✔ ✔ 25
  • 26. Server Architecture • Memcached separate from ndbd • Memcached inside ndbd – Definitely! – Maybe! – “m:n” ratio of memcache servers – we know how to do it to data nodes – “embedded” API-to-TC channel – lower latency – network round trip + tens of microseconds – Not as flexible memcached memcached memcached 26
  • 27. Decisions • Use memcached 1.6 tree • Isolate the NDB-specific code into an ndb_engine – which currently exists outside the memcached source tree – and runs in an unmodified memcached server • Build a standalone server binary • Possibly also build an ndbmtd-embedded server • Share code with InnoDB Memcache team – on basic configuration and user-visible concepts – and on changes that would allow a memcache server module to be loaded into either ndbmtd or mysqld 27
  • 28. Other decisions • Memcache INCR & DECR – Fully supported – Atomic operations – Performed at the data node • Memcache CAS (version id check) – Fully Supported • either at local cache or at database – CAS check is pushed down to the data node – Ideally an update that comes from a non-memcache API node should invalidate the CAS • we still need to decide the best design for this 28
  • 29. Limitations • The size of stored values is limited to the NDB row size – currently just less than 8 KB – vs. 1 MB typical limit for memcached – due to the lack of BLOB support in the async NDB API 29
  • 30. Architecture Overview Application Application memcached mysqld Wide-area Local Cache Replication NDB Engine InnoDB NDB Engine binlog stream NDB Data Data Data Data Cluster Node Node Node Node 30
  • 32. What’s Configurable • Does it use local cache? • Does it use NDB? • What columns hold the keys? • What columns hold the data? • Are memcache commands like DELETE and FLUSH allowed to delete records from the database? • You decide all of this ... • on a “per-key-prefix” basis. 32
  • 33. A Key Prefix user:1248 the prefix the database key 33
  • 34. Fundamentals • memcached command line specifies a connectstring for a primary cluster • primary = “where the config is stored” • The NDB Engine reads the configuration tables from the ndbmemcache database on the primary cluster • You, the administrator, manage the config via SQL • An NDB Memcache server can operate on data in the primary cluster or in other clusters • Different NDB Memcache servers can fetch different configurations 34
  • 35. Standard Tables in ndbmemcache • meta – stores configuration schema version (for upgrade compatibility); consider it to be read-only • ndb_clusters • containers – where data is stored • cache_policies – how it can be accessed • key_prefixes • memcache_server_roles • last_memcached_signon • demo_table 35
  • 36. ndb_clusters • cluster_id – int, referenced by key_prefixes • ndb_connectstring – varchar(128) – how to reach this cluster • microsec_rtt – default 250; used for internal performance tuning 36
  • 37. containers • name • schema_name • table_name (the existing table where your data lives) • key_columns (comma-separated) • value_columns (comma-separated) • flags (either a constant number, or a column name) • increment_column (optional, for INCR/DECR) • cas_column (optional) • expire_time_column (optional) 37
  • 38. cache_policies • policy_name • get_policy – enum (cache_only, ndb_only, caching, disabled) • set_policy – enum (cache_only, ndb_only, caching, disabled) • delete_policy – enum (cache_only, ndb_only, caching, disabled) • flush_from_db – enum(false, true) 38
  • 39. A key-prefix mapping Memcache Cache key Cluster Container Policy prefix 39
  • 40. A memcache server role key Con- Cache Cluster prefix tainer Policy Server key Con- Cache Role Cluster prefix tainer Policy ID key Con- Cache Cluster prefix tainer Policy key Con- Cache Cluster prefix tainer Policy 40
  • 41. key_prefixes • server_role_id • key_prefix • cluster_id • policy • container 41
  • 42. demo_table • Not really part of the configuration ... • mkey – varchar(250) NOT NULL PRIMARY KEY • math_value – bigint unsigned • cas_value – bigint unsigned • string_value – varchar(7500) 42
  • 44. Measured Latency memcachetest -t 2 -M 7000 -c 25000 1000 500 95th 351 374 avg. 184 min. 98 !sec Memcached NDB NDB Write ICMP Default 1-Node 2-Node ping Read Engine Cluster Cluster 44
  • 45. Links • This Presentation – http://en.oreilly.com/mysql2011/ • Memcached 1.6 development tree – git clone git://github.com/memcached/memcached – cd memcached – git checkout -t origin/engine-pu • MySQL Cluster 7.2 with Memcached Engine – bzr clone lp:~mysql/mysql-server/mysql-cluster-7.2-labs-memcached – or look for it at labs.mysql.com • Mailing List – cluster@lists.mysql.com 45
  • 46. Demo • What we’ll see: – Memcache Server Window • start memcached “sandbox” – default role (NDB-only) – mc-only role (plain memcached) – ndb-caching role (NDB with local cache) – Client Window • run memcapable – MyQSL Window • examine data and configuration 46
  • 47. 47