developing high-throughput services with no sql ap-is to innodb and mysql cluster

40
Developing High-Throughput Services with NoSQL APIs to Services with NoSQL APIs to InnoDB and MySQL Cluster Andrew Morgan – MySQL Product Management John Duncan MySQL Cluster Engineering John Duncan MySQL Cluster Engineering Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30 th 2012 1

Upload: andrew-morgan

Post on 27-Jan-2015

111 views

Category:

Documents


2 download

DESCRIPTION

Ever-increasing performance demands of Web-based services have generated significant interest in providing NoSQL access methods to MySQL (MySQL Cluster from Oracle and the InnoDB storage engine of MySQL), enabling users to maintain all the advantages of their existing relational databases while providing blazing-fast performance for simple queries. Get the best of both worlds: persistence; consistency; rich SQL queries; high availability; scalability; and simple, flexible APIs and schemas for agile development. This session describes the memcached connectors and examines some use cases for how MySQL and memcached fit together in application architectures. It does the same for the newest MySQL Cluster native connector, an easy-to-use, fully asynchronous connector for Node.js.

TRANSCRIPT

Page 1: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Developing High-Throughput Services with NoSQL APIs toServices with NoSQL APIs to InnoDB and MySQL Cluster

Andrew Morgan – MySQL Product ManagementJohn Duncan – MySQL Cluster EngineeringJohn Duncan MySQL Cluster Engineering

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20121

Page 2: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Program Agenda

Why NoSQLWhy NoSQL

MySQL Cluster Attributes

NoSQL APIs for MySQL Cluster

Memcached API for InnoDB Memcached API for InnoDB

Node.js – Native javascript access

Next Steps

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20122

Page 3: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Disclaimer

Th f ll i i i t d d t tli l d t di ti It iThe following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated i t t t It i t it t t d li t i linto any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making

h i d i i Th d l t l d ti i fpurchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at th l di ti f O lthe sole discretion of Oracle.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20123

Page 4: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

NoSQL – Why the demand?

W b li ti2.1BN USERS

Web applications demanding: Development velocity:

40% DATA GROWTH PER

8X DATA GROWTH IN 5 YRS

70+ NEW DOMAINS EVERY 60 SECONDS

900M USERS

20M APPS PER DAY

Development velocity: Simplicity & flexibility of data model & APIs

Scalability &

YEAR

$1TR BY 2014

60 HOURSUPLOADED

EVERY MINUTE

Scalability & performance: high write throughput and Key/Value access

$1TR BY 2014

$700BN IN 2011350m TWEETS

PER DAY

Key/Value access Support for “Big Data” 5.9BN MOBILE SUBS IN 2011

1 BILLION iOS & ANDROID 85% HANDSETS SHIPPED WITH A

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20124

APPS DOWNLOADED PER WEEK SHIPPED WITH A BROWSER

Page 5: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

What NoSQL must deliver

Massive scalability No application-level shardingScalability o app cat o e e s a d g

Performance High Availability/Fault Tolerance Ease of use

Performance

HA Ease of use Simple operations/administration Simple APIs Quickly evolve application & schema

Ease of use

Quickly evolve application & schema

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20125

Page 6: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Still a role for the RDBMS?

No best single solution fits all

Mix and matchNoSQL

Si l tt

RDBMS

C l i ith j iSimple access patterns

Compromise on consistency for performance

Complex queries with joins

ACID transactions

Scalability

Performance for performance

Ad-hoc data format Well defined schemasHA

Ease of use

Simple operation Rich set of tools

ase o use

SQL/Joins

ACID Transactions

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20126

ACID Transactions

Page 7: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster introduction• Shared-nothing in-memory parallel database server• ACID compliant relational database• Shared-nothing in-memory parallel database server• ACID compliant relational database

Carrier Grade Database

• Five nines (99.999%) availability• Self-healing, sub-second failover• Five nines (99.999%) availability• Self-healing, sub-second failoverHighly Available

• High load, real-time performance• Predictable low latency, bounded access times• High load, real-time performance• Predictable low latency, bounded access times

Real-time Performance

• Incrementally grow out with application demands• Linearly scale with distribution awareness• Incrementally grow out with application demands• Linearly scale with distribution awarenessLinearly Scalable yy

• Open Source, multiple data access• High performance APIs (C++, Java, SQL, LDAP)• Open Source, multiple data access• High performance APIs (C++, Java, SQL, LDAP)Open Development

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20127

High performance APIs (C , Java, SQL, LDAP)High performance APIs (C , Java, SQL, LDAP)

Page 8: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Who’s Using MySQL Cluster?

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20128

Page 9: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster ArchitectureScalability

Performance

HA

Ease of use

SQL/J iSQL/Joins

ACID Transactions Clients

Application Layer

Data Layer

Application Layer

Management

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 20129

MySQL Cluster Data Nodes

Page 10: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster ArchitectureScalability

Performance

HA

Ease of use

SQL/J iSQL/Joins

ACID Transactions Clients

Application Layer

Data Layer

Application Layer

ManagementManagement

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201210

MySQL Cluster Data Nodes

Page 11: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster ArchitectureScalability

Performance

HA

Ease of use

SQL/J iSQL/Joins

ACID Transactions Clients

Application Layer

Data Layer

Application Layer

ManagementManagement

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201211

MySQL Cluster Data Nodes

Page 12: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

On-line Scheduled MaintenanceScalability

Performance

HA

Ease of use

SQL/J iSQL/Joins

ACID Transactions

Scale Backup

UpgradeEvolve

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201212

pg

Page 13: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Extreme performanceScalability

Performance

HA

Ease of use

SQL/J iSQL/Joins

ACID Transactions

writes

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201213

Page 14: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Creating & running your first ClusterThe traditional way (pre-MCM) – Up and running in 15 mins

Download & Extract

Configure•Cluster wide

Start processes•Management NodesExtract

•edelivery.oracle.com•www.mysql.com•dev.mysql.com

•Cluster-wide “config.ini”

•Per-mysqld “my.cnf”

•Management Nodes•Data Nodes•MySQL Servers

Up & running in 10-15 minutes using Quick Start guides from http://dev mysql com/downloads/cluster/

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201214

Up & running in 10-15 minutes using Quick Start guides from http://dev.mysql.com/downloads/cluster/– Versions for Linux, Windows & Solaris

Page 15: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Scalability Scalability

Performance Performance

HA

Ease of use

SQL/Joins

ACID Transactions

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201215

Page 16: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster ManagerB t t i l h t Cl tBootstrap single host Cluster

1. Download MCM/Cluster package from edelivery.oracle.com:2. Unzip3. Run agent, define, create & start Cluster!$> bin\mcmd –bootstrap$ b \ c d bootst apMySQL Cluster Manager 1.1.2 startedConnect to MySQL Cluster Manager by running "D:\Andrew\Documents\MySQL\mcm\bin\mcm" -a NOVA:1862Configuring default cluster 'mycluster'...Starting default cluster 'mycluster'...Cluster 'mycluster' started successfully

db d NOVA 1186ndb_mgmd NOVA:1186ndbd NOVAndbd NOVAmysqld NOVA:3306mysqld NOVA:3307ndbapi *

Connect to the database by running "D:\Andrew\Documents\MySQL\mcm\cluster\bin\mysql" -h NOVA -P 3306 -u root

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201216

Page 17: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster 7.3 labs: Auto-Installer

• Fast configuration Specify Auto-

• Auto-discovery

W kl d ti i d

p yWorkload Discover

• Workload optimized

• Repeatable best tipractices

• For MySQL Cluster 7 2 + 7 3

ConfirmDeploy7.2 + 7.3 TopologyDeploy

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201217

Page 18: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster 7.3 labs: Auto-Installer

• Fast configuration

• Auto-discovery

W kl d ti i d• Workload optimized

• Repeatable best tipractices

• For MySQL Cluster 7 2 + 7 37.2 + 7.3

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201218

Page 19: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Scalability Scalability

Performance Performance

HA

Ease of use

SQL/Joins

ACID Transactions

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201219

Page 20: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

NoSQL Access to MySQL Cluster data

Apps

JPA

Apps Apps Apps Apps Apps Apps Apps Apps AppsApps Apps

ClusterJMySQL

JDBC

JPA

JNIPython Ruby

ClusterJPA

Node.js

JSONmod-ndb

Apache

ndb-eng

MemcachedPHP PERL

NDB API (C++)

MySQL Cluster Data Nodes

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201220

Page 21: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster 7.1: ClusterJ/JPA

• Domain Object Model Persistence API (ClusterJ):• Java API• High performance, low latency• Feature rich

• JPA interface built upon this new Java layer:• Java Persistence API compliant

• Implemented as an OpenJPA plugin• Implemented as an OpenJPA plugin• Uses ClusterJ where possible, reverts to JDBC for

some operations• Higher performance than JDBC• More natural for most Java designers

Easier Cl ster adoption for eb applications

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201221

• Easier Cluster adoption for web applications

Page 22: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster 7.2: Memcached

• Memcached is a distributed memory based hash-k / l t ith i t t di kkey/value store with no persistence to disk

• NoSQL, simple API, popular with developers• MySQL Cluster already provides scalable, in-y y p

memory performance with NoSQL (hashed) access as well as persistence

• Provide the Memcached API but map to NDB• Provide the Memcached API but map to NDB API calls

• Writes-in-place, so no need to invalidate cacheSi lifi hit t hi & d t b• Simplifies architecture as caching & database integrated into 1 tier

• Access data from existing relational tables

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201222

Page 23: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Traditional Memcached ArchitectureT l l f h hiTwo levels of hashing

httpd memcached

Memcache

memcachedPHP/Perl hash key to find data

Memcachememcached

memcache keyfriends:12389

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201223

Page 24: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Memcache Protocol Elements

• Key Up to 250 characters• Expire Time A number in seconds up to 30 days• Expire Time A number in seconds, up to 30 days• Flags 32-bit number for application use

CAS ID 64 bit i ti i b l• CAS ID 64-bit incrementing version number on value • Value Value stored for key; traditionally up to 1 MB.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201224

Page 25: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Memcache Protocol Commands (1)

t k Fetch al e for this ke• get key Fetch value for this key• set key value Store this data• add key value Store this data (strict insert)• replace key value Store this data (strict update)• cas key value cas-id Update with version number check

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201225

Page 26: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Memcache Protocol Commands (2)

• append key value Append text to current valueappend key value Append text to current value

• prepend key value Insert text before current value

• incr key amount Add to current stored integer value• incr key amount Add to current stored integer value

• decr key amount Subtract from current stored value

• delete key Delete a key and value

• flush_all Delete all stored values on the server

• stats stat-name Fetch server statistics

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201226

Page 27: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

NDB & Memcache Architecture:M h t l + NDB tMemcache protocol + NDB storage

MySQLy QCluster

Data NodememcachedApplication

MemcacheClient MySQL

ClNDB EngineClient Cluster

Data Node

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201227

Page 28: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Goals

• Access stored data directly from memcache client• Memcached perspective:

• MySQL Cluster is a write-scalable, replicated data store• with reliable in-memory storage,• plus on-disk storage when data is too big for memory.

• MySQL Cluster perspective: • memcache is a high performance API

• providing easy access to in-memory data,• plus an extra layer of caching when data is on disk.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201228

Page 29: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Memcached/MySQL Cluster latency

memcachetest -t 2 -M 7000 -c 25000

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201229

Page 30: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Cluster & Memcached – Schema-Free

<town:maidenhead,SL6>

key value

A li ti i

key value

Application view

SQL view

<town:maidenhead,SL6>

Key Valuetown:maidenhead SL6

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201230

generic table

Page 31: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Cluster & Memcached – Configured Schema

<town:maidenhead,SL6>

key value

A li ti i

prefix key value

Application view

SQL view

<town:maidenhead,SL6>

Prefix Table Key-col Val-col policytown: map.zip town code cluster

C fi t bl

town ... code ...maidenhead ... SL6 ...

i

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201231

Config tables map.zip

Page 32: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Memcached NoSQL Access with InnoDB

• Memcached as a plugin of MySQL Server; same ApplicationMySQL Server; same process space, with very low latency access to data

• Memcapable: supports bothSQL Memcached protocol

mysqldMemcapable: supports both memcached ascii protocol and binary protocol

• Support multiple columns:MySQL Server memcached plugin

Support multiple columns: users can map multiple columns into “value”

• Optional local caching:Handler API InnoDB API

innodb_memcache local cache (optional)

Optional local caching: “innodb-only”, “cache-only”, and “caching”

• Batch operations for

InnoDB Storage Engine

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201232

Batch operations for performance

Page 33: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster 7.3 EA: Node.js NoSQL APIS SQ C Native JavaScript access to MySQL Cluster

– End-to-End JavaScript: browser to the app and databaseClients database

– Storing and retrieving JavaScript objects directly in MySQL Cluster

Clients

y– Eliminate SQL transformation

Implemented as a module for node.jsV8 JavaScript Engine p j– Integrates full Cluster API library within the web

appMySQL Cluster Node.js Module

Couple high performance, distributed apps, with high performance distributed database

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201233

MySQL Cluster Data Nodes

Page 34: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster NoSQL API for Node.jsA li ti C dApplication Code

// Constructor

function Tweet(user, message) {

this.id = UUID.generate();

this.timestamp = Date.now();p

this.user = user;

this message = message;this.message = message;

}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201234

Page 35: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster NoSQL API for Node.js

• Modular connector with various back-end adapters:

• ndb: low-level native access to MySQL Cluster

// Server Startup

access to MySQL Cluster• mysql: access to any

MySQL server (translates

var nosql = require('mysql-js');

y (operations to SQL statements)

var sessionFactory = nosql.connectSync('ndb');

nosql.mapClass(Tweet, 'tweets');

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201235

Page 36: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster NoSQL API for Node.js

// Create a tweet

function newTweet(err, dbSession, httpReq) {

var tweet = new Tweet(

httpReq.user,

httpReq.message);

dbSession.persist(tweet);

}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201236

Page 37: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster NoSQL API for Node.js

function onNewTweetRequest(err, httpReq) {

sessionFactory.openSession(null, newTweet, httpReq);

}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201237

Page 38: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

MySQL Cluster NoSQL API for Node.jsS nc s As nc E ec tion

If you had all synchronous operationsSync vs. Async Execution

y y p– Single execution context blocked for I/O. – Low performancep

If you had all async operationsComplex code– Complex code

– Each individual operation nested within its own callback function.

The right balanceThe right balance– Define a database operation as an immediate call (no I/O)

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201238

– Execute database operations in async calls with callbacks

Page 39: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Next StepsLearn More• www.mysql.com/cluster

A th ti M SQL C i l• Authentic MySQL Curriculum: http://oracle.com/education/mysql

T it O tTry it Out• dev.mysql.com/cluster• labs.mysql.comy

Let us know what you thinkLet us know what you think• clusterdb.com• @clusterdb• forums mysql com/list php?25

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201239

• forums.mysql.com/list.php?25

Page 40: Developing high-throughput services with no sql ap-is to innodb and mysql cluster

Graphic Section Divider

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. September 30th 201240