SlideShare ist ein Scribd-Unternehmen logo
1 von 123
Big Data For OLTP
Handling Massive Writes
 Liran Zelkha, Tona Consulting
    Liran.zelkha@gmail.com
Intro
• Israel’s Big Data Meetup
• By Developers, For Developers

• We talk code, architecture, solutions
  – No products
  – No sales pitches
• Suggest ideas for next meetups
• Suggest yourselves as speakers for next meetups
About Me
• Liran Zelkha, from Tona Consulting
• Formerly co-founder at ScaleBase
  – NewSQL solution for scaling RDBMS
• Works (allot) with applications that need to
  scale, both reads and writes
Agenda
• Terminology
• Massive Reads vs. Massive Writes
• Solutions
  – RDBMS
  – NoSQL
  – Code
TERMINOLOGY
Terminology
• OLTP
  – a class of systems that facilitate and manage
    transaction-oriented applications, typically for data
    entry and retrieval transaction processing. The term is
    somewhat ambiguous; some understand a
    "transaction" in the context of computer or database
    transactions, while others (such as the Transaction
    Processing Performance Council) define it in terms of
    business or commercial transactions. OLTP has also
    been used to refer to processing in which the system
    responds immediately to user requests. An automatic
    teller machine (ATM) for a bank is an example of a
    commercial transaction processing application.

         http://en.wikipedia.org/wiki/Online_transaction_processing
Terminology
• OLAP
  – s an approach to swiftly answer multi-dimensional
    analytical (MDA) queries. OLAP is part of the broader
    category of business intelligence, which also
    encompasses relational reporting and data mining.
    Typical applications of OLAP include business
    reporting for sales, marketing, management
    reporting, business process management (BPM),
    budgeting and forecasting, financial reporting and
    similar areas, with new applications coming up, such
    as agriculture. The term OLAP was created as a slight
    modification of the traditional database term OLTP
    (Online Transaction Processing).
         http://en.wikipedia.org/wiki/Online_analytical_processing
MASSIVE READS VS. MASSIVE
WRITES
Reads vs. Writes
Reads                        Writes
• Caching helps              • Caching sucks
• No need for availability   • Availability is a must (?)
• No transactions            • Transactions are a must (?)
• No locking                 • Locking is a must (?)
Massive Reads Solutions
• Memory, Memory, Memory
  – For Caching, Caching, Caching
• Column stores (?)
Caching
• Tons of solutions.
• To name a few:
  – java.util.Map
  – Hazelcast
  – Infinispan
  – Coherence
When Caching Consider
•   Time To Live
•   Memory Leaks
•   Updates (?)
•   What is cached and where
Column Store Databases
• Store data in columns vs. rows
• Faster reads, slower writes
• Compression helps store more data in less disk
  space
Massive Write Solutions
• Memory?
  – Only with fast networks
• Fast disks
Memory
• Memory can fail, machines can fail
• Distributed memory
• Size of memory

• See Nati Shalom’s points at
  http://natishalom.typepad.com/nati_shaloms
  _blog/2010/03/memory-is-the-new-disk-for-
  the-enterprise.html
Memory Is The New Disk
Fast Disks
• When massive writes translates to massive
  disk writes
  – Fast disks are a must
• Can offer
  – HA
  – Scalability
  – Low latency
2 Words On Storage Technologies
•   RAID
•   SSD
•   SAN
•   NAS
Example
• NMS System
• Each device interaction is built from 5-10
  request/response pair
• Each request causes up to 3 database insert/updates
   – And multiple reads
• Support up to 5M devices
• Technology stack
   – Jboss 6
   – EJB3, JPA
   – Oracle Database
JDBC Profiling – Standard Disks
JDBC Profiling – Fast SAN
• Spec
  – HP P2000 with 16 drives configured as:
     • 14 300G 10K SAS Drives in RAID 10 (Data)
     • 2 300G 10K SAS Drives in RAID 1 (Redo)
     • Write-back is enabled
  – Sisk enclosure is connected via FC Switch and 8GB
    Qlogic HBA on the server side.
JDBC Profiling – Fast SAN
RDBMS
MySQL Scaling Options
•   Tuning
•   Hardware upscale
•   Partitioning
•   New MySQL distribution
•   Read/Write Split
Database Tuning
• There are many ways to tune your database
• Allot of data online, check out this post
  – http://forge.mysql.com/wiki/Top10SQLPerforman
    ceTips
Database Tuning – Some Examples
• innodb_buffer_pool_size
   –   Holds the data and indexes of tables in memory.
   –   Bigger buffer results in faster row lookups.
   –   The bigger the better.
   –   Default – 8M
• Query Cache
   – Keeps the result of queries in memory until they are invalidated by
     writes.
   – query_cache_size
        • total size of memory available to query caching
   – query_cache_limit
        • the maximum number of kilobytes one query may be in order to be cached.
   – query_cache_size = 128MB
   – query_cache_limit = 4MB
Database Tuning – Pros and Cons


  Pros                          Cons
  May result in major           Doesn’t scale. No matter how well
  performance improvements      the tuning is performed, it will
                                reach a limit defined by machine
                                capabilities.
  Doesn’t require application
  changes
SQL Tuning
• If you write lousy SQL code, you’ll get lousy
  performance
  – Java gurus are not SQL gurus
  – Your ORM code does not know how to write good
    SQL code
• What will happen when executing
  – SELECT * FROM
• Tuning your SQL commands is tedious but very
  rewarding
SQL Tuning – Some Examples
• Here are just some examples:
  – Use EXPLAIN to profile the query execution plan
  – Use DISTINCT – not GROUP BY
  – Don’t use an indexed column with a function
  – Try not to use a non deterministic functions in
    where clause
SQL Tuning – Pros and Cons


  Pros                       Cons
  May result in major        Requires code modifications.
  performance improvements
                             Doesn’t scale. No matter how
                             well the tuning is performed, it
                             will reach a limit defined by
                             machine capabilities.
Scaling Up Hardware
  • Usually DB gets the strongest servers
  • However – there is a limit to how much performance
    gains you can get from increasing hardware
  • Some data:




http://www.mysqlperformanceblog.com/2011/01/26/modeling-innodb-scalability-on-
multi-core-servers/
Scaling Up Hardware – Pros and Cons
Pros                                           Cons
May result in major performance improvements   Scaling is limited
Transparent                                    Might be expensive
Easy
SSD
• Solid State Drive
   – Better latency and access time than regular HDD
   – Cost more per GB (but prices are dropping)
• Vadim Tkachenko from Percona gave a great
  lecture on SSD at MySQL Conf 2011
   – (see slides at
     http://en.oreilly.com/mysql2011/public/schedule/det
     ail/17117)
   – Claims you can expect up to X7 performance from SSD
SSD – Pros and Cons
Pros                                           Cons
May result in major performance improvements   Expensive
Transparent                                    Still limited scalability
Partitioning
• Partitioning was introduced to MySQL at
  version 5.1.
• It is a way to split tables across multiple files, a
  technique that proved very useful for
  improving database performance.
• Benefits:
   – Helps fit indexes in RAM
   – Faster query/insert
   – Instant delete
Partitioning Performance
 • See excellent presentation by Giuseppe Maxia
   from 2010
      – http://www.slideshare.net/datacharmer/partition
        s-performance-with-mysql-51-and-55

Engine                       6 month range query
InnoDB                       4min 30s
MyISAM                       25.03s
InnoDB partitions            13.19s
MyISAM partiotions           4.45s
Partitioning
Pros                                    Cons
May result in major performance         MySQL server itself introduces limits. User
improvements                            concurrency, transaction chains, isolation,
                                        are still bottlenecked by the single MySQL
                                        that owns all partitions
Mostly transparent to the application
New MySQL Distributions
• There are many MySQL drop-in replacements
• Are MySQL, but tuned differently, different
  extensions
• Leading examples
  – PerconaServer
  – MariaDB
New MySQL Distributions – Pros and
             Cons


    Pros                  Cons
    Provide performance   Still limited scalability
    improvements
    Transparent
Other Storage Engines
• InnoDB better than MyISAM
  – Oh really?
  – As always, it depends.
  – InnoDB will cause less corruptions, and is probably
    better for most high traffic applications.
• MEMORY can be great
  – However, no persistency
Read/Write Splitting
• Write to MySQL master, read from 1 (or more)
  slaves
• Excellent read scaling
• Many issues:
  – Since replication is a-synchronous – read might
    not be up to date
  – Transactions create stickiness
  – Code changes
Read/Write Splitting – Pros and Cons
Pros                     Cons
Provides performance     Requires code changes
improvements
Scale out the database   Good for scaling reads, not writes
                         Since replication is asynchronous, some reads
                         might get data that is not up to date.
Sharding


                 DB1


App



                 DB2
MySQL + NoSQL - HandlerSocket
• Fascinating post -
  http://yoshinorimatsunobu.blogspot.com/2010/1
  0/using-mysql-as-nosql-story-for.html
• MySQL spends huge amount of time on SQL
  statement parsing
• Using InnoDB API directly

• MySQL Plugin
• Comes builtin with Percona Server 5.5
HandlerSocket - Architecture
Code Sample

#!/usr/bin/perl

use strict;
use warnings;
use Net::HandlerSocket;

#1. establishing a connection
my $args = { host => 'ip_to_remote_host', port => 9998 };
my $hs = new Net::HandlerSocket($args);

#2. initializing an index so that we can use in main logics.
# MySQL tables will be opened here (if not opened)
my $res = $hs->open_index(0, 'test', 'user', 'PRIMARY',
  'user_name,user_email,created');
die $hs->get_error() if $res != 0;
Code Sample – Cont’

#3. main logic
 #fetching rows by id
 #execute_single (index id, cond, cond value, max rows, offset)
$res = $hs->execute_single(0, '=', [ '101' ], 1, 0);
die $hs->get_error() if $res->[0] != 0;
shift(@$res);
for (my $row = 0; $row < 1; ++$row) {
  my $user_name= $res->[$row + 0];
  my $user_email= $res->[$row + 1];
  my $created= $res->[$row + 2];
  print "$user_namet$user_emailt$createdn";
}

#4. closing the connection
$hs->close();
Bashing Some NewSQL Solutions
• Xeround
   – Limited Database size
   – Only on the cloud
• VoltDB
   – Rewrite your entire app to use stored procedures
• NimbusDB
   – Still in Beta
• Clustrix
   – Insanely expensive
   – NoSQL that looks like MySQL
• Schooner
   – Fast MySQL on SSD
• And no word on ScaleBase
NOSQL
NoSQL Is Here To Stay
NoSQL
• A term used to designate databases which
  differ from classic relational databases in
  some way. These data stores may not require
  fixed table schemas, and usually
  avoid join operations and typically scale
  horizontally. Academics and papers typically
  refer to these databases as structured storage,
  a term which would include classic relational
  databases as a subset.
                             http://en.wikipedia.org/wiki/NoSQL
NoSQL Types
• Key/Value
   – A big hash table
   – Examples: Voldemort, Amazon Dynamo
• Big Table
   – Big table, column families
   – Examples: Hbase, Cassandra
• Document based
   – Collections of collections
   – Examples: CouchDB, MongoDB
• Graph databases
   – Based on graph theory
   – Examples: Neo4J
• Each solves a different problem
NO-SQL




  http://browsertoolkit.com/fault-tolerance.png
MongoDB
• I use the slides of Roger Bodamer from 10gen
• Find them here:
  – http://assets.en.oreilly.com/1/event/61/Building%
    20Web%20Applications%20with%20MongoDB%2
    0Presentation.ppt
• In my book – Mongo doesn’t fit the massive
  write story.
MongoDB
• Document Oriented Database
   – Data is stored in documents, not tables / relations

• MongoDB is Implemented in C++ for best performance
• Platforms 32/64 bit Windows Linux, Mac OS-X, FreeBSD, Solaris

• Language drivers for:
   –   Ruby / Ruby-on-Rails
   –   Java
   –   C#
   –   JavaScript
   –   C / C++
   –   Erlang Python, Perl others..... and much more ! ..
Design
• Want to build an app where users can check in
  to a location

• Leave notes or comments about that location

• Iterative Approach:
  – Decide requirements
  – Design documents
  – Rinse, repeat :-)
Requirements
• Locations
  – Need to store locations (Offices, Restaurants etc)
     • Want to be able to store name, address and tags
     • Maybe User Generated Content, i.e. tips / small notes ?


  – Want to be able to find other locations nearby
Requirements
• Locations
  – Need to store locations (Offices, Restaurants etc)
     • Want to be able to store name, address and tags
     • Maybe User Generated Content, i.e. tips / small notes ?

  – Want to be able to find other locations nearby

• Checkins
  – User should be able to ‘check in’ to a location
  – Want to be able to generate statistics
Terminology
RDBMS                 Mongo
Table, View           Collection
Row(s)                JSON Document
Index                 Index
Join                  Embedded Document

Partition             Shard
Partition Key         Shard Key
Collections




loc1, loc2, loc3                 User1, User2


      Location
                                      Users
          s
JSON Sample Doc

 { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
   author : "roger",
   date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)",
   text : ”MongoSF",
   tags : [ ”San Francisco", ”MongoDB" ] }

Notes:
 - _id is unique, but can be anything you’d like
BSON

• JSON has powerful, but limited set of datatypes
  – Mongo extends datypes with Date, Int types, Id, …

• MongoDB stores data in BSON

• BSON is a binary representation of JSON
  – Optimized for performance and navigational abilities
  – Also compression
  – See bsonspec.org
Locations v1

location1= {
      name: "10gen East Coast”,
      address: ”134 5th Avenue 3rd Floor”,
      city: "New York”,
      zip: "10011”
}
Places v1
location1= {
        name: "10gen East Coast”,
        address: ”134 5th Avenue 3rd Floor”,
        city: "New York”,
        zip: "10011”
}


db.locations.find({zip:”10011”}).limit(10)
Places v2
location1 = {
      name: "10gen East Coast”,
      address: "17 West 18th Street 8th Floor”,
      city: "New York”,
      zip: "10011”,

      tags: [“business”, “mongodb”]
}
Places v2
location1 = {
        name: "10gen East Coast”,
        address: "17 West 18th Street 8th Floor”,
        city: "New York”,
        zip: "10011”,

        tags: [“business”, “mongodb”]
}

db.locations.find({zip:”10011”, tags:”business”})
Places v3
location1 = {
      name: "10gen East Coast”,
      address: "17 West 18th Street 8th Floor”,
      city: "New York”,
      zip: "10011”,

      tags: [“business”, “mongodb”],

      latlong: [40.0,72.0]
}
Places v3
location1 = {
      name: "10gen East Coast”,
      address: "17 West 18th Street 8th Floor”,
      city: "New York”,
      zip: "10011”,

      tags: [“business”, “cool place”],

      latlong: [40.0,72.0]
}

db.locations.ensureIndex({latlong:”2d”})
Places v3
location1 = {
      name: "10gen HQ”,
      address: "17 West 18th Street 8th Floor”,
      city: "New York”,
      zip: "10011”,

      tags: [“business”, “cool place”],

      latlong: [40.0,72.0]
}

db.locations.ensureIndex({latlong:”2d”})
db.locations.find({latlong:{$near:[40,70]}})
Places v4
location1 = {
        name: "10gen HQ”,
        address: "17 West 18th Street 8th Floor”,
        city: "New York”,
        zip: "10011”,
        latlong: [40.0,72.0],

        tags: [“business”, “cool place”],

        tips: [
                    {user:"nosh", time:6/26/2010, tip:"stop by   for
office hours on Wednesdays from 4-6pm"},
           {.....},
                    ]
}
Querying your Places
Creating your indexes
db.locations.ensureIndex({tags:1})
db.locations.ensureIndex({name:1})
db.locations.ensureIndex({latlong:”2d”})

Finding places:
db.locations.find({latlong:{$near:[40,70]}})

With regular expressions:
db.locations.find({name: /^typeaheadstring/)

By tag:
db.locations.find({tags: “business”})
Inserting and updating locations
Initial data load:
db.locations.insert(place1)


Using update to Add tips:
db.locations.update({name:"10gen HQ"},
      {$push :{tips:
                      {user:"nosh", time:6/26/2010,
        tip:"stop by for office hours on
Wednesdays from 4-6"}}}}
Requirements
• Locations
  – Need to store locations (Offices, Restaurants etc)
     • Want to be able to store name, address and tags
     • Maybe User Generated Content, i.e. tips / small notes ?

  – Want to be able to find other locations nearby

• Checkins
  – User should be able to ‘check in’ to a location
  – Want to be able to generate statistics
Users
user1 = {
      name: “nosh”
      email: “nosh@10gen.com”,
      .
      .
      .
      checkins: [{ location: “10gen HQ”,
          ts: 9/20/2010 10:12:00,
          …},
          …
        ]
}
Simple Stats
db.users.find({„checkins.location‟: “10gen HQ”)


db.checkins.find({„checkins.location‟: “10gen HQ”})
                                 .sort({ts:-1}).limit(10)


db.checkins.find({„checkins.location‟: “10gen HQ”,
                                 ts: {$gt: midnight}}).count()
Alternative
user1 = {
      name: “nosh”
      email: “nosh@10gen.com”,
      .
      .
      .
      checkins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab]
}



checkins [] = ObjectId reference to locations collection
User Check in


Check-in = 2 ops
        read location to obtain location id
        Update ($push) location id to user object

Queries: find all locations where a user checked in:
  checkin_array = db.users.find({..},
                  {checkins:true}).checkins

  db.location.find({_id:{$in: checkin_array}})
Unsharded Deployment

                •Configure as a replica set for
Primary
                automated failover
                •Async replication between nodes

Secondary       •Add more secondaries to scale reads


Secondary
Sharded Deployment
                             MongoS




                                                                confi
                                                                g
    Primary




   Secondary


•Autosharding distributes data among two or more replica sets
•Mongo Config Server(s) handles distribution & balancing
•Transparent to applications
Cassandra
• Slides used from eben hewitt
• See original slides here:
  – http://assets.en.oreilly.com/1/event/51/Scaling%2
    0Web%20Applications%20with%20Cassandra%20
    Presentation.ppt
cassandra properties
•   tuneably consistent
•   very fast writes
•   highly available
•   fault tolerant
•   linear, elastic scalability
•   decentralized/symmetric
•   ~12 client languages
    – Thrift RPC API
• ~automatic provisioning of new nodes
• 0(1) dht
• big data
write op
Staged Event-Driven Architecture
• A general-purpose framework for high
  concurrency & load conditioning
• Decomposes applications into stages
  separated by queues
• Adopt a structured approach to event-driven
  concurrency
instrumentation
data replication
• configurable replication factor
• replica placement strategy
   rack unaware  Simple Strategy
  rack aware  Old Network Topology Strategy
  data center shard  Network Topology Strategy
partitioner smack-down
Random Preserving                Order Preserving
• system will use MD5(key) to    • key distribution determined
  distribute data across nodes     by token
• even distribution of keys      • lexicographical ordering
  from one CF across             • required for range queries
  ranges/nodes                      – scan over rows like cursor in
                                      index
                                 • can specify the token for
                                   this node to use
                                 • ‘scrabble’ distribution
agenda
•   context
•   features
•   data model
•   api
structure

keyspace

               column family
 settings
    (eg,
partitioner)   settings (eg,
                                column
               comparator,
                type [Std])       name     value   clock
keyspace
• ~= database
• typically one per application
• some settings are configurable only per
  keyspace
column family
• group records of similar kind
• not same kind, because CFs are sparse tables
• ex:
  – User
  – Address
  – Tweet
  – PointOfInterest
  – HotelRoom
think of cassandra as

 row-oriented
• each row is uniquely identifiable by key
• rows group columns and super columns
column family

key                 nickname=
      user=eben         The
123                  Situation

key                    icon=     n=
      user=alison
456                              42
json-like notation
User {
  123 : { email: alison@foo.com,
          icon:          },

    456 : { email: eben@bar.com,
            location: The Danger Zone}
}
example
$cassandra –f
$bin/cassandra-cli
cassandra> connect localhost/9160


cassandra> set
  Keyspace1.Standard1[‘eben’][‘age’]=‘29’
cassandra> set
  Keyspace1.Standard1[‘eben’][‘email’]=‘e@e.com’
cassandra> get Keyspace1.Standard1[‘eben'][‘age']
=> (column=6e616d65, value=39,
  timestamp=1282170655390000)
a column has 3 parts
1. name
  –   byte[]
  –   determines sort order
  –   used in queries
  –   indexed
2. value
  –   byte[]
  –   you don’t query on column values
3. timestamp
  – long (clock)
  – last write wins conflict resolution
column comparators
•   byte
•   utf8
•   long
•   timeuuid
•   lexicaluuid
•   <pluggable>
    – ex: lat/long
super column



super columns group columns under a common name
super column family
             <<SCF>>PointOfInterest

           <<SC>>Central          <<SC>>
               Park           Empire State Bldg
10017       desc=Fun to                 desc=Great
                           phone=212.
              walk in.                   view from
                            555.11212
                                        102nd floor!



            <<SC>>
85255       Phoenix
              Zoo
super column family
                     super column family

PointOfInterest {
  key: 85255 {                                            column
      Phoenix Zoo { phone: 480-555-5555, desc: They have animals here. },
      Spring Training { phone: 623-333-3333, desc: Fun for baseball fans. },
  }, //end phx
                   key
                         super column
    key: 10019 {                                               flexible schema
        Central Park { desc: Walk around. It's pretty.} ,
                                                     s
        Empire State Building { phone: 212-777-7777,
                                 desc: Great view from 102nd floor. }
    } //end nyc
}
about super column families
• sub-column names in a SCF are not indexed
  – top level columns (SCF Name) are always indexed
• often used for denormalizing data from
  standard CFs
slice predicate
• data structure describing columns to return
  – SliceRange
     •   start column name
     •   finish column name (can be empty to stop on count)
     •   reverse
     •   count (like LIMIT)
• get() : Column
    – get the Col or SC at given ColPath
                                                                read api
      COSC cosc = client.get(key, path, CL);

• get_slice() : List<ColumnOrSuperColumn>
    – get Cols in one row, specified by SlicePredicate:
      List<ColumnOrSuperColumn> results =
        client.get_slice(key, parent, predicate, CL);

• multiget_slice() : Map<key, List<CoSC>>
    – get slices for list of keys, based on SlicePredicate
     Map<byte[],List<ColumnOrSuperColumn>> results =
       client.multiget_slice(rowKeys, parent, predicate, CL);

• get_range_slices() : List<KeySlice>
    – returns multiple Cols according to a range
    – range is startkey, endkey, starttoken, endtoken:
      List<KeySlice> slices = client.get_range_slices(
         parent, predicate, keyRange, CL);
client.insert(userKeyBytes, parent,      write       api
    new Column(“band".getBytes(UTF8),
    “Funkadelic".getBytes(), clock), CL);

batch_mutate
  – void batch_mutate(
    map<byte[], map<String, List<Mutation>>> , CL)
remove
  – void remove(byte[],
    ColumnPath column_path, Clock, CL)
//create param
                                                            batch_mutate
Map<byte[], Map<String, List<Mutation>>> mutationMap =
   new HashMap<byte[], Map<String, List<Mutation>>>();

//create Cols for Muts
Column nameCol = new Column("name".getBytes(UTF8),
“Funkadelic”.getBytes("UTF-8"), new Clock(System.nanoTime()););
Mutation nameMut = new Mutation();
nameMut.column_or_supercolumn = nameCosc; //also phone, etc

Map<String, List<Mutation>> muts = new HashMap<String, List<Mutation>>();
List<Mutation> cols = new ArrayList<Mutation>();
cols.add(nameMut);
cols.add(phoneMut);
muts.put(CF, cols);
//outer map key is a row key; inner map key is the CF name
mutationMap.put(rowKey.getBytes(), muts);
//send to server
client.batch_mutate(mutationMap, CL);
what about…

SELECT WHERE
    ORDER BY
      JOIN ON
       GROUP
rdbms: domain-based model
             what answers do I have?



cassandra: query-based model
             what questions do I have?
SELECT WHERE
               cassandra is an index factory
<<cf>>USER
Key: UserID
Cols: username, email, birth date, city, state

How to support this query?

SELECT * FROM User WHERE city = ‘Scottsdale’

Create a new CF called UserCity:

<<cf>>USERCITY
Key: city
Cols: IDs of the users in that city.
Also uses the Valueless Column pattern
SELECT WHERE pt 2
• Use an aggregate key
  state:city: { user1, user2}

• Get rows between AZ: & AZ;
  for all Arizona users

• Get rows between AZ:Scottsdale &
  AZ:Scottsdale1
  for all Scottsdale users
ORDER BY

Columns                   Rows
are sorted according to   are placed according to their Partitioner:
CompareWith or
CompareSubcolumnsWith
                          •Random: MD5 of key
                          •Order-Preserving: actual key


                          are sorted by key, regardless of partitioner
rdbms
cassandra
When To Use NoSQL
• No schema – No SQL
   – Don’t do this KV DB design
      • Terrible performance, impossible to maintain
• No persistency – No SQL
   – Heck – use a distributed cache for that
• Low write latency
   – And fast storage is not an option
• Simple queries
   – You can always ETL to a DB later
• Cool factor
   – Good luck with that
Real Life NoSQL Usages
• MongoDB is great for CMS
  – Try MTV…
• Cassandra is great for low latency writes

• Use the right tool for the job – or you’ll get
  worse performance than a DB
• Expect a very high learning curve to
  implement
SpringData
• In your face – there are frameworks that use
  NoSQL
And To Finish
• A long time ago people told me Java doesn’t
  perform nor scale…
CODE
ORM
• Check the queries created
  – For instance, in Hibernate
     • setLast,setFirst – kill your performance
     • Lazy fetching
     • N+1
• Use batch updates
Hibernate With Batch Updates
session.doWork(new Work() {
  public void execute(Connection connection) throws SQLException {
    PreparedStatement stmt = connection.prepareStatement(“insert into test
values(?,?)");
    stmt.setLong(1, id);
    stmt.setLong(2, transId);
    call.execute();
 }
});
JDBC Code
• Always use prepared statements
• Use your Database performance extensions
  – For instance, massive inserts for Column Store DBs
Transactions
• One transaction per hit. At most.
• Reads can hurt your writes
Database Tuning
• We talked about it, but:
  – Indexes – good for read, bad for write
  – Multi column indexes – good only if query reads using
    the same order of columns
  – Indexes and views
  – EXPLAIN is your friend
• Keep your DB small
  – BI against read-replica
  – Delete history
  – Ensure you only save what you actually need
Final Note
• NoSQL, SQL – it doesn’t matter if your code
  sucks!
2 Words On Cloud
• Storage sucks
• Network sucks

• So
  – Cache locally
  – Write a-sync
  – Write to files, not DB
  – Don’t use RDS
  – Check Cloud providers that offer SSD

Weitere ähnliche Inhalte

Was ist angesagt?

MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017Ivan Zoratti
 
Bridging the Developer and the Datacenter
Bridging the Developer and the DatacenterBridging the Developer and the Datacenter
Bridging the Developer and the Datacenterlurs83
 
Infinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQLInfinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQLManik Surtani
 
Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...
Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...
Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...Andrew Miller
 
X-DB Replication Server and MMR
X-DB Replication Server and MMRX-DB Replication Server and MMR
X-DB Replication Server and MMRAshnikbiz
 
From distributed caches to in-memory data grids
From distributed caches to in-memory data gridsFrom distributed caches to in-memory data grids
From distributed caches to in-memory data gridsMax Alexejev
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
The SQL Stack Design And Configurations
The SQL Stack Design And ConfigurationsThe SQL Stack Design And Configurations
The SQL Stack Design And ConfigurationsStephan Lawson
 
5 Ways to Avoid Server and Application Downtime
5 Ways to Avoid Server and Application Downtime5 Ways to Avoid Server and Application Downtime
5 Ways to Avoid Server and Application DowntimeNeverfail Group
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)Aurimas Mikalauskas
 
Sql Server High Availability & DR Technologies
Sql Server High Availability & DR TechnologiesSql Server High Availability & DR Technologies
Sql Server High Availability & DR TechnologiesRockSolid SQL
 
SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBUniFabric
 
NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5UniFabric
 
PostgreSQL Scaling And Failover
PostgreSQL Scaling And FailoverPostgreSQL Scaling And Failover
PostgreSQL Scaling And FailoverJohn Paulett
 
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...NetApp
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014marvin herrera
 
Moving On Up - smaller servers and bigger performance
Moving On Up - smaller servers and bigger performanceMoving On Up - smaller servers and bigger performance
Moving On Up - smaller servers and bigger performanceDoug Lucy
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQLPostgreSQL-Consulting
 
Varrow madness 2013 virtualizing sql presentation
Varrow madness 2013 virtualizing sql presentationVarrow madness 2013 virtualizing sql presentation
Varrow madness 2013 virtualizing sql presentationpittmantony
 

Was ist angesagt? (20)

MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017MySQL Performance Tuning London Meetup June 2017
MySQL Performance Tuning London Meetup June 2017
 
Bridging the Developer and the Datacenter
Bridging the Developer and the DatacenterBridging the Developer and the Datacenter
Bridging the Developer and the Datacenter
 
Infinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQLInfinspan: In-memory data grid meets NoSQL
Infinspan: In-memory data grid meets NoSQL
 
Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...
Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...
Varrow Q4 Lunch & Learn Presentation - Virtualizing Business Critical Applica...
 
X-DB Replication Server and MMR
X-DB Replication Server and MMRX-DB Replication Server and MMR
X-DB Replication Server and MMR
 
From distributed caches to in-memory data grids
From distributed caches to in-memory data gridsFrom distributed caches to in-memory data grids
From distributed caches to in-memory data grids
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
The SQL Stack Design And Configurations
The SQL Stack Design And ConfigurationsThe SQL Stack Design And Configurations
The SQL Stack Design And Configurations
 
5 Ways to Avoid Server and Application Downtime
5 Ways to Avoid Server and Application Downtime5 Ways to Avoid Server and Application Downtime
5 Ways to Avoid Server and Application Downtime
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
Sql Server High Availability & DR Technologies
Sql Server High Availability & DR TechnologiesSql Server High Availability & DR Technologies
Sql Server High Availability & DR Technologies
 
SOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DBSOUG_Deployment__Automation_DB
SOUG_Deployment__Automation_DB
 
NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5NGENSTOR_ODA_P2V_V5
NGENSTOR_ODA_P2V_V5
 
PostgreSQL Scaling And Failover
PostgreSQL Scaling And FailoverPostgreSQL Scaling And Failover
PostgreSQL Scaling And Failover
 
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...
TechTarget Event - Storage Architectures for the Modern Data Center - Howard ...
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
 
Scalability Design Principles - Internal Session
Scalability Design Principles - Internal SessionScalability Design Principles - Internal Session
Scalability Design Principles - Internal Session
 
Moving On Up - smaller servers and bigger performance
Moving On Up - smaller servers and bigger performanceMoving On Up - smaller servers and bigger performance
Moving On Up - smaller servers and bigger performance
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
 
Varrow madness 2013 virtualizing sql presentation
Varrow madness 2013 virtualizing sql presentationVarrow madness 2013 virtualizing sql presentation
Varrow madness 2013 virtualizing sql presentation
 

Andere mochten auch

애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)
애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)
애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)윤성 이
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningFromDual GmbH
 
Go 1.설치와 세팅
Go 1.설치와 세팅Go 1.설치와 세팅
Go 1.설치와 세팅재봉 이
 
당신의 디버깅에 니코니코니
당신의 디버깅에 니코니코니당신의 디버깅에 니코니코니
당신의 디버깅에 니코니코니Lusain Kim
 
OSS개발자 포럼 캠프
OSS개발자 포럼 캠프OSS개발자 포럼 캠프
OSS개발자 포럼 캠프Hakbeom Hwang
 
커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco
커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco
커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, pecoDaegwon Kim
 
넘쳐나는 정보 소화 노하우
넘쳐나는 정보 소화 노하우넘쳐나는 정보 소화 노하우
넘쳐나는 정보 소화 노하우종빈 오
 
Redis trouble shooting
Redis trouble shootingRedis trouble shooting
Redis trouble shootingDaeMyung Kang
 
The Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptThe Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptNorman Richards
 
어서 와! 번역은 처음이지?
어서 와! 번역은 처음이지?어서 와! 번역은 처음이지?
어서 와! 번역은 처음이지?복연 이
 
개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]
개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]
개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]Yurim Jin
 
Share some development
Share some developmentShare some development
Share some developmentJi Heon Kim
 
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
스프링 시큐리티로 시작하는 웹 어플리케이션 보안스프링 시큐리티로 시작하는 웹 어플리케이션 보안
스프링 시큐리티로 시작하는 웹 어플리케이션 보안HyungTae Lim
 
Programming skills 1부
Programming skills 1부Programming skills 1부
Programming skills 1부JiHyung Lee
 
나에 첫번째 자바8 람다식 지앤선
나에 첫번째 자바8 람다식   지앤선나에 첫번째 자바8 람다식   지앤선
나에 첫번째 자바8 람다식 지앤선daewon jeong
 
GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사
GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사
GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사Chang W. Doh
 
프로그래머를 꿈꾸는 학부 후배들에게
프로그래머를 꿈꾸는 학부 후배들에게프로그래머를 꿈꾸는 학부 후배들에게
프로그래머를 꿈꾸는 학부 후배들에게Matthew (정재화)
 
[NHN NEXT] Java 강의 - Week4
[NHN NEXT] Java 강의 - Week4[NHN NEXT] Java 강의 - Week4
[NHN NEXT] Java 강의 - Week4Young-Ho Cho
 

Andere mochten auch (20)

Amazed by AWS Series #4
Amazed by AWS Series #4Amazed by AWS Series #4
Amazed by AWS Series #4
 
Java the good parts
Java the good partsJava the good parts
Java the good parts
 
애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)
애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)
애자일, 소프트웨어와 인간을 말하다(eXtreme Programming, XP)
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
 
Go 1.설치와 세팅
Go 1.설치와 세팅Go 1.설치와 세팅
Go 1.설치와 세팅
 
당신의 디버깅에 니코니코니
당신의 디버깅에 니코니코니당신의 디버깅에 니코니코니
당신의 디버깅에 니코니코니
 
OSS개발자 포럼 캠프
OSS개발자 포럼 캠프OSS개발자 포럼 캠프
OSS개발자 포럼 캠프
 
커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco
커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco
커맨드 라인 도구 활용하기 - zsh + oh-my-zsh, tmux, peco
 
넘쳐나는 정보 소화 노하우
넘쳐나는 정보 소화 노하우넘쳐나는 정보 소화 노하우
넘쳐나는 정보 소화 노하우
 
Redis trouble shooting
Redis trouble shootingRedis trouble shooting
Redis trouble shooting
 
The Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScriptThe Lambda Calculus and The JavaScript
The Lambda Calculus and The JavaScript
 
어서 와! 번역은 처음이지?
어서 와! 번역은 처음이지?어서 와! 번역은 처음이지?
어서 와! 번역은 처음이지?
 
개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]
개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]
개발과 디자인은 재미있어 [141025 한국우분투커뮤니티 발표]
 
Share some development
Share some developmentShare some development
Share some development
 
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
스프링 시큐리티로 시작하는 웹 어플리케이션 보안스프링 시큐리티로 시작하는 웹 어플리케이션 보안
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
 
Programming skills 1부
Programming skills 1부Programming skills 1부
Programming skills 1부
 
나에 첫번째 자바8 람다식 지앤선
나에 첫번째 자바8 람다식   지앤선나에 첫번째 자바8 람다식   지앤선
나에 첫번째 자바8 람다식 지앤선
 
GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사
GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사
GDG DevFest 2014 - 코드 없이 오픈소스 기여하기: HTML5Rocks/KO 번역 야사
 
프로그래머를 꿈꾸는 학부 후배들에게
프로그래머를 꿈꾸는 학부 후배들에게프로그래머를 꿈꾸는 학부 후배들에게
프로그래머를 꿈꾸는 학부 후배들에게
 
[NHN NEXT] Java 강의 - Week4
[NHN NEXT] Java 강의 - Week4[NHN NEXT] Java 강의 - Week4
[NHN NEXT] Java 강의 - Week4
 

Ähnlich wie Handling Massive Writes

Kb 40 kevin_klineukug_reading20070717[1]
Kb 40 kevin_klineukug_reading20070717[1]Kb 40 kevin_klineukug_reading20070717[1]
Kb 40 kevin_klineukug_reading20070717[1]shuwutong
 
Ceph Community Talk on High-Performance Solid Sate Ceph
Ceph Community Talk on High-Performance Solid Sate Ceph Ceph Community Talk on High-Performance Solid Sate Ceph
Ceph Community Talk on High-Performance Solid Sate Ceph Ceph Community
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014Ryusuke Kajiyama
 
Scaling apps for the big time
Scaling apps for the big timeScaling apps for the big time
Scaling apps for the big timeproitconsult
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systemselliando dias
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMariaDB plc
 
Deep Dive on MySQL Databases on AWS - AWS Online Tech Talks
Deep Dive on MySQL Databases on AWS - AWS Online Tech TalksDeep Dive on MySQL Databases on AWS - AWS Online Tech Talks
Deep Dive on MySQL Databases on AWS - AWS Online Tech TalksAmazon Web Services
 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16Sanjay Manwani
 
VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right VMworld
 
NoSQLDatabases
NoSQLDatabasesNoSQLDatabases
NoSQLDatabasesAdi Challa
 
Building a High Performance Analytics Platform
Building a High Performance Analytics PlatformBuilding a High Performance Analytics Platform
Building a High Performance Analytics PlatformSantanu Dey
 
Database as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance PlatformDatabase as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance PlatformMaris Elsins
 
2013 CPM Conference, Nov 6th, NoSQL Capacity Planning
2013 CPM Conference, Nov 6th, NoSQL Capacity Planning2013 CPM Conference, Nov 6th, NoSQL Capacity Planning
2013 CPM Conference, Nov 6th, NoSQL Capacity Planningasya999
 
Designing, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons LearnedDesigning, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons LearnedDenny Lee
 
My sql competitive update
My sql competitive updateMy sql competitive update
My sql competitive updatexKinAnx
 
Chapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choicesChapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choicesMaynooth University
 
Severalnines Training: MySQL® Cluster - Part IX
Severalnines Training: MySQL® Cluster - Part IXSeveralnines Training: MySQL® Cluster - Part IX
Severalnines Training: MySQL® Cluster - Part IXSeveralnines
 

Ähnlich wie Handling Massive Writes (20)

Kb 40 kevin_klineukug_reading20070717[1]
Kb 40 kevin_klineukug_reading20070717[1]Kb 40 kevin_klineukug_reading20070717[1]
Kb 40 kevin_klineukug_reading20070717[1]
 
Ceph Community Talk on High-Performance Solid Sate Ceph
Ceph Community Talk on High-Performance Solid Sate Ceph Ceph Community Talk on High-Performance Solid Sate Ceph
Ceph Community Talk on High-Performance Solid Sate Ceph
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
 
Scaling apps for the big time
Scaling apps for the big timeScaling apps for the big time
Scaling apps for the big time
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systems
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
Deep Dive on MySQL Databases on AWS - AWS Online Tech Talks
Deep Dive on MySQL Databases on AWS - AWS Online Tech TalksDeep Dive on MySQL Databases on AWS - AWS Online Tech Talks
Deep Dive on MySQL Databases on AWS - AWS Online Tech Talks
 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16
 
VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right VMworld 2013: Virtualizing Databases: Doing IT Right
VMworld 2013: Virtualizing Databases: Doing IT Right
 
NoSQLDatabases
NoSQLDatabasesNoSQLDatabases
NoSQLDatabases
 
Building a High Performance Analytics Platform
Building a High Performance Analytics PlatformBuilding a High Performance Analytics Platform
Building a High Performance Analytics Platform
 
Database as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance PlatformDatabase as a Service on the Oracle Database Appliance Platform
Database as a Service on the Oracle Database Appliance Platform
 
IaaS for DBAs in Azure
IaaS for DBAs in AzureIaaS for DBAs in Azure
IaaS for DBAs in Azure
 
2013 CPM Conference, Nov 6th, NoSQL Capacity Planning
2013 CPM Conference, Nov 6th, NoSQL Capacity Planning2013 CPM Conference, Nov 6th, NoSQL Capacity Planning
2013 CPM Conference, Nov 6th, NoSQL Capacity Planning
 
Designing, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons LearnedDesigning, Building, and Maintaining Large Cubes using Lessons Learned
Designing, Building, and Maintaining Large Cubes using Lessons Learned
 
Running MySQL in AWS
Running MySQL in AWSRunning MySQL in AWS
Running MySQL in AWS
 
My sql competitive update
My sql competitive updateMy sql competitive update
My sql competitive update
 
Chapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choicesChapter1: NoSQL: It’s about making intelligent choices
Chapter1: NoSQL: It’s about making intelligent choices
 
Severalnines Training: MySQL® Cluster - Part IX
Severalnines Training: MySQL® Cluster - Part IXSeveralnines Training: MySQL® Cluster - Part IX
Severalnines Training: MySQL® Cluster - Part IX
 

Kürzlich hochgeladen

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Kürzlich hochgeladen (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

Handling Massive Writes

  • 1. Big Data For OLTP Handling Massive Writes Liran Zelkha, Tona Consulting Liran.zelkha@gmail.com
  • 2. Intro • Israel’s Big Data Meetup • By Developers, For Developers • We talk code, architecture, solutions – No products – No sales pitches • Suggest ideas for next meetups • Suggest yourselves as speakers for next meetups
  • 3. About Me • Liran Zelkha, from Tona Consulting • Formerly co-founder at ScaleBase – NewSQL solution for scaling RDBMS • Works (allot) with applications that need to scale, both reads and writes
  • 4. Agenda • Terminology • Massive Reads vs. Massive Writes • Solutions – RDBMS – NoSQL – Code
  • 6. Terminology • OLTP – a class of systems that facilitate and manage transaction-oriented applications, typically for data entry and retrieval transaction processing. The term is somewhat ambiguous; some understand a "transaction" in the context of computer or database transactions, while others (such as the Transaction Processing Performance Council) define it in terms of business or commercial transactions. OLTP has also been used to refer to processing in which the system responds immediately to user requests. An automatic teller machine (ATM) for a bank is an example of a commercial transaction processing application. http://en.wikipedia.org/wiki/Online_transaction_processing
  • 7. Terminology • OLAP – s an approach to swiftly answer multi-dimensional analytical (MDA) queries. OLAP is part of the broader category of business intelligence, which also encompasses relational reporting and data mining. Typical applications of OLAP include business reporting for sales, marketing, management reporting, business process management (BPM), budgeting and forecasting, financial reporting and similar areas, with new applications coming up, such as agriculture. The term OLAP was created as a slight modification of the traditional database term OLTP (Online Transaction Processing). http://en.wikipedia.org/wiki/Online_analytical_processing
  • 8. MASSIVE READS VS. MASSIVE WRITES
  • 9. Reads vs. Writes Reads Writes • Caching helps • Caching sucks • No need for availability • Availability is a must (?) • No transactions • Transactions are a must (?) • No locking • Locking is a must (?)
  • 10. Massive Reads Solutions • Memory, Memory, Memory – For Caching, Caching, Caching • Column stores (?)
  • 11. Caching • Tons of solutions. • To name a few: – java.util.Map – Hazelcast – Infinispan – Coherence
  • 12. When Caching Consider • Time To Live • Memory Leaks • Updates (?) • What is cached and where
  • 13. Column Store Databases • Store data in columns vs. rows • Faster reads, slower writes • Compression helps store more data in less disk space
  • 14. Massive Write Solutions • Memory? – Only with fast networks • Fast disks
  • 15. Memory • Memory can fail, machines can fail • Distributed memory • Size of memory • See Nati Shalom’s points at http://natishalom.typepad.com/nati_shaloms _blog/2010/03/memory-is-the-new-disk-for- the-enterprise.html
  • 16. Memory Is The New Disk
  • 17. Fast Disks • When massive writes translates to massive disk writes – Fast disks are a must • Can offer – HA – Scalability – Low latency
  • 18. 2 Words On Storage Technologies • RAID • SSD • SAN • NAS
  • 19. Example • NMS System • Each device interaction is built from 5-10 request/response pair • Each request causes up to 3 database insert/updates – And multiple reads • Support up to 5M devices • Technology stack – Jboss 6 – EJB3, JPA – Oracle Database
  • 20. JDBC Profiling – Standard Disks
  • 21. JDBC Profiling – Fast SAN • Spec – HP P2000 with 16 drives configured as: • 14 300G 10K SAS Drives in RAID 10 (Data) • 2 300G 10K SAS Drives in RAID 1 (Redo) • Write-back is enabled – Sisk enclosure is connected via FC Switch and 8GB Qlogic HBA on the server side.
  • 22. JDBC Profiling – Fast SAN
  • 23. RDBMS
  • 24. MySQL Scaling Options • Tuning • Hardware upscale • Partitioning • New MySQL distribution • Read/Write Split
  • 25. Database Tuning • There are many ways to tune your database • Allot of data online, check out this post – http://forge.mysql.com/wiki/Top10SQLPerforman ceTips
  • 26. Database Tuning – Some Examples • innodb_buffer_pool_size – Holds the data and indexes of tables in memory. – Bigger buffer results in faster row lookups. – The bigger the better. – Default – 8M • Query Cache – Keeps the result of queries in memory until they are invalidated by writes. – query_cache_size • total size of memory available to query caching – query_cache_limit • the maximum number of kilobytes one query may be in order to be cached. – query_cache_size = 128MB – query_cache_limit = 4MB
  • 27. Database Tuning – Pros and Cons Pros Cons May result in major Doesn’t scale. No matter how well performance improvements the tuning is performed, it will reach a limit defined by machine capabilities. Doesn’t require application changes
  • 28. SQL Tuning • If you write lousy SQL code, you’ll get lousy performance – Java gurus are not SQL gurus – Your ORM code does not know how to write good SQL code • What will happen when executing – SELECT * FROM • Tuning your SQL commands is tedious but very rewarding
  • 29. SQL Tuning – Some Examples • Here are just some examples: – Use EXPLAIN to profile the query execution plan – Use DISTINCT – not GROUP BY – Don’t use an indexed column with a function – Try not to use a non deterministic functions in where clause
  • 30. SQL Tuning – Pros and Cons Pros Cons May result in major Requires code modifications. performance improvements Doesn’t scale. No matter how well the tuning is performed, it will reach a limit defined by machine capabilities.
  • 31. Scaling Up Hardware • Usually DB gets the strongest servers • However – there is a limit to how much performance gains you can get from increasing hardware • Some data: http://www.mysqlperformanceblog.com/2011/01/26/modeling-innodb-scalability-on- multi-core-servers/
  • 32. Scaling Up Hardware – Pros and Cons Pros Cons May result in major performance improvements Scaling is limited Transparent Might be expensive Easy
  • 33. SSD • Solid State Drive – Better latency and access time than regular HDD – Cost more per GB (but prices are dropping) • Vadim Tkachenko from Percona gave a great lecture on SSD at MySQL Conf 2011 – (see slides at http://en.oreilly.com/mysql2011/public/schedule/det ail/17117) – Claims you can expect up to X7 performance from SSD
  • 34. SSD – Pros and Cons Pros Cons May result in major performance improvements Expensive Transparent Still limited scalability
  • 35. Partitioning • Partitioning was introduced to MySQL at version 5.1. • It is a way to split tables across multiple files, a technique that proved very useful for improving database performance. • Benefits: – Helps fit indexes in RAM – Faster query/insert – Instant delete
  • 36. Partitioning Performance • See excellent presentation by Giuseppe Maxia from 2010 – http://www.slideshare.net/datacharmer/partition s-performance-with-mysql-51-and-55 Engine 6 month range query InnoDB 4min 30s MyISAM 25.03s InnoDB partitions 13.19s MyISAM partiotions 4.45s
  • 37. Partitioning Pros Cons May result in major performance MySQL server itself introduces limits. User improvements concurrency, transaction chains, isolation, are still bottlenecked by the single MySQL that owns all partitions Mostly transparent to the application
  • 38. New MySQL Distributions • There are many MySQL drop-in replacements • Are MySQL, but tuned differently, different extensions • Leading examples – PerconaServer – MariaDB
  • 39. New MySQL Distributions – Pros and Cons Pros Cons Provide performance Still limited scalability improvements Transparent
  • 40. Other Storage Engines • InnoDB better than MyISAM – Oh really? – As always, it depends. – InnoDB will cause less corruptions, and is probably better for most high traffic applications. • MEMORY can be great – However, no persistency
  • 41. Read/Write Splitting • Write to MySQL master, read from 1 (or more) slaves • Excellent read scaling • Many issues: – Since replication is a-synchronous – read might not be up to date – Transactions create stickiness – Code changes
  • 42. Read/Write Splitting – Pros and Cons Pros Cons Provides performance Requires code changes improvements Scale out the database Good for scaling reads, not writes Since replication is asynchronous, some reads might get data that is not up to date.
  • 43. Sharding DB1 App DB2
  • 44. MySQL + NoSQL - HandlerSocket • Fascinating post - http://yoshinorimatsunobu.blogspot.com/2010/1 0/using-mysql-as-nosql-story-for.html • MySQL spends huge amount of time on SQL statement parsing • Using InnoDB API directly • MySQL Plugin • Comes builtin with Percona Server 5.5
  • 46. Code Sample #!/usr/bin/perl use strict; use warnings; use Net::HandlerSocket; #1. establishing a connection my $args = { host => 'ip_to_remote_host', port => 9998 }; my $hs = new Net::HandlerSocket($args); #2. initializing an index so that we can use in main logics. # MySQL tables will be opened here (if not opened) my $res = $hs->open_index(0, 'test', 'user', 'PRIMARY', 'user_name,user_email,created'); die $hs->get_error() if $res != 0;
  • 47. Code Sample – Cont’ #3. main logic #fetching rows by id #execute_single (index id, cond, cond value, max rows, offset) $res = $hs->execute_single(0, '=', [ '101' ], 1, 0); die $hs->get_error() if $res->[0] != 0; shift(@$res); for (my $row = 0; $row < 1; ++$row) { my $user_name= $res->[$row + 0]; my $user_email= $res->[$row + 1]; my $created= $res->[$row + 2]; print "$user_namet$user_emailt$createdn"; } #4. closing the connection $hs->close();
  • 48. Bashing Some NewSQL Solutions • Xeround – Limited Database size – Only on the cloud • VoltDB – Rewrite your entire app to use stored procedures • NimbusDB – Still in Beta • Clustrix – Insanely expensive – NoSQL that looks like MySQL • Schooner – Fast MySQL on SSD • And no word on ScaleBase
  • 49. NOSQL
  • 50. NoSQL Is Here To Stay
  • 51. NoSQL • A term used to designate databases which differ from classic relational databases in some way. These data stores may not require fixed table schemas, and usually avoid join operations and typically scale horizontally. Academics and papers typically refer to these databases as structured storage, a term which would include classic relational databases as a subset. http://en.wikipedia.org/wiki/NoSQL
  • 52. NoSQL Types • Key/Value – A big hash table – Examples: Voldemort, Amazon Dynamo • Big Table – Big table, column families – Examples: Hbase, Cassandra • Document based – Collections of collections – Examples: CouchDB, MongoDB • Graph databases – Based on graph theory – Examples: Neo4J • Each solves a different problem
  • 54. MongoDB • I use the slides of Roger Bodamer from 10gen • Find them here: – http://assets.en.oreilly.com/1/event/61/Building% 20Web%20Applications%20with%20MongoDB%2 0Presentation.ppt • In my book – Mongo doesn’t fit the massive write story.
  • 55. MongoDB • Document Oriented Database – Data is stored in documents, not tables / relations • MongoDB is Implemented in C++ for best performance • Platforms 32/64 bit Windows Linux, Mac OS-X, FreeBSD, Solaris • Language drivers for: – Ruby / Ruby-on-Rails – Java – C# – JavaScript – C / C++ – Erlang Python, Perl others..... and much more ! ..
  • 56. Design • Want to build an app where users can check in to a location • Leave notes or comments about that location • Iterative Approach: – Decide requirements – Design documents – Rinse, repeat :-)
  • 57. Requirements • Locations – Need to store locations (Offices, Restaurants etc) • Want to be able to store name, address and tags • Maybe User Generated Content, i.e. tips / small notes ? – Want to be able to find other locations nearby
  • 58. Requirements • Locations – Need to store locations (Offices, Restaurants etc) • Want to be able to store name, address and tags • Maybe User Generated Content, i.e. tips / small notes ? – Want to be able to find other locations nearby • Checkins – User should be able to ‘check in’ to a location – Want to be able to generate statistics
  • 59. Terminology RDBMS Mongo Table, View Collection Row(s) JSON Document Index Index Join Embedded Document Partition Shard Partition Key Shard Key
  • 60. Collections loc1, loc2, loc3 User1, User2 Location Users s
  • 61. JSON Sample Doc { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : ”MongoSF", tags : [ ”San Francisco", ”MongoDB" ] } Notes: - _id is unique, but can be anything you’d like
  • 62. BSON • JSON has powerful, but limited set of datatypes – Mongo extends datypes with Date, Int types, Id, … • MongoDB stores data in BSON • BSON is a binary representation of JSON – Optimized for performance and navigational abilities – Also compression – See bsonspec.org
  • 63. Locations v1 location1= { name: "10gen East Coast”, address: ”134 5th Avenue 3rd Floor”, city: "New York”, zip: "10011” }
  • 64. Places v1 location1= { name: "10gen East Coast”, address: ”134 5th Avenue 3rd Floor”, city: "New York”, zip: "10011” } db.locations.find({zip:”10011”}).limit(10)
  • 65. Places v2 location1 = { name: "10gen East Coast”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “mongodb”] }
  • 66. Places v2 location1 = { name: "10gen East Coast”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “mongodb”] } db.locations.find({zip:”10011”, tags:”business”})
  • 67. Places v3 location1 = { name: "10gen East Coast”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “mongodb”], latlong: [40.0,72.0] }
  • 68. Places v3 location1 = { name: "10gen East Coast”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “cool place”], latlong: [40.0,72.0] } db.locations.ensureIndex({latlong:”2d”})
  • 69. Places v3 location1 = { name: "10gen HQ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, tags: [“business”, “cool place”], latlong: [40.0,72.0] } db.locations.ensureIndex({latlong:”2d”}) db.locations.find({latlong:{$near:[40,70]}})
  • 70. Places v4 location1 = { name: "10gen HQ”, address: "17 West 18th Street 8th Floor”, city: "New York”, zip: "10011”, latlong: [40.0,72.0], tags: [“business”, “cool place”], tips: [ {user:"nosh", time:6/26/2010, tip:"stop by for office hours on Wednesdays from 4-6pm"}, {.....}, ] }
  • 71. Querying your Places Creating your indexes db.locations.ensureIndex({tags:1}) db.locations.ensureIndex({name:1}) db.locations.ensureIndex({latlong:”2d”}) Finding places: db.locations.find({latlong:{$near:[40,70]}}) With regular expressions: db.locations.find({name: /^typeaheadstring/) By tag: db.locations.find({tags: “business”})
  • 72. Inserting and updating locations Initial data load: db.locations.insert(place1) Using update to Add tips: db.locations.update({name:"10gen HQ"}, {$push :{tips: {user:"nosh", time:6/26/2010, tip:"stop by for office hours on Wednesdays from 4-6"}}}}
  • 73. Requirements • Locations – Need to store locations (Offices, Restaurants etc) • Want to be able to store name, address and tags • Maybe User Generated Content, i.e. tips / small notes ? – Want to be able to find other locations nearby • Checkins – User should be able to ‘check in’ to a location – Want to be able to generate statistics
  • 74. Users user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [{ location: “10gen HQ”, ts: 9/20/2010 10:12:00, …}, … ] }
  • 75. Simple Stats db.users.find({„checkins.location‟: “10gen HQ”) db.checkins.find({„checkins.location‟: “10gen HQ”}) .sort({ts:-1}).limit(10) db.checkins.find({„checkins.location‟: “10gen HQ”, ts: {$gt: midnight}}).count()
  • 76. Alternative user1 = { name: “nosh” email: “nosh@10gen.com”, . . . checkins: [4b97e62bf1d8c7152c9ccb74, 5a20e62bf1d8c736ab] } checkins [] = ObjectId reference to locations collection
  • 77. User Check in Check-in = 2 ops read location to obtain location id Update ($push) location id to user object Queries: find all locations where a user checked in: checkin_array = db.users.find({..}, {checkins:true}).checkins db.location.find({_id:{$in: checkin_array}})
  • 78. Unsharded Deployment •Configure as a replica set for Primary automated failover •Async replication between nodes Secondary •Add more secondaries to scale reads Secondary
  • 79. Sharded Deployment MongoS confi g Primary Secondary •Autosharding distributes data among two or more replica sets •Mongo Config Server(s) handles distribution & balancing •Transparent to applications
  • 80. Cassandra • Slides used from eben hewitt • See original slides here: – http://assets.en.oreilly.com/1/event/51/Scaling%2 0Web%20Applications%20with%20Cassandra%20 Presentation.ppt
  • 81. cassandra properties • tuneably consistent • very fast writes • highly available • fault tolerant • linear, elastic scalability • decentralized/symmetric • ~12 client languages – Thrift RPC API • ~automatic provisioning of new nodes • 0(1) dht • big data
  • 83. Staged Event-Driven Architecture • A general-purpose framework for high concurrency & load conditioning • Decomposes applications into stages separated by queues • Adopt a structured approach to event-driven concurrency
  • 85. data replication • configurable replication factor • replica placement strategy rack unaware  Simple Strategy rack aware  Old Network Topology Strategy data center shard  Network Topology Strategy
  • 86. partitioner smack-down Random Preserving Order Preserving • system will use MD5(key) to • key distribution determined distribute data across nodes by token • even distribution of keys • lexicographical ordering from one CF across • required for range queries ranges/nodes – scan over rows like cursor in index • can specify the token for this node to use • ‘scrabble’ distribution
  • 87. agenda • context • features • data model • api
  • 88. structure keyspace column family settings (eg, partitioner) settings (eg, column comparator, type [Std]) name value clock
  • 89. keyspace • ~= database • typically one per application • some settings are configurable only per keyspace
  • 90. column family • group records of similar kind • not same kind, because CFs are sparse tables • ex: – User – Address – Tweet – PointOfInterest – HotelRoom
  • 91. think of cassandra as row-oriented • each row is uniquely identifiable by key • rows group columns and super columns
  • 92. column family key nickname= user=eben The 123 Situation key icon= n= user=alison 456 42
  • 93. json-like notation User { 123 : { email: alison@foo.com, icon: }, 456 : { email: eben@bar.com, location: The Danger Zone} }
  • 94. example $cassandra –f $bin/cassandra-cli cassandra> connect localhost/9160 cassandra> set Keyspace1.Standard1[‘eben’][‘age’]=‘29’ cassandra> set Keyspace1.Standard1[‘eben’][‘email’]=‘e@e.com’ cassandra> get Keyspace1.Standard1[‘eben'][‘age'] => (column=6e616d65, value=39, timestamp=1282170655390000)
  • 95. a column has 3 parts 1. name – byte[] – determines sort order – used in queries – indexed 2. value – byte[] – you don’t query on column values 3. timestamp – long (clock) – last write wins conflict resolution
  • 96. column comparators • byte • utf8 • long • timeuuid • lexicaluuid • <pluggable> – ex: lat/long
  • 97. super column super columns group columns under a common name
  • 98. super column family <<SCF>>PointOfInterest <<SC>>Central <<SC>> Park Empire State Bldg 10017 desc=Fun to desc=Great phone=212. walk in. view from 555.11212 102nd floor! <<SC>> 85255 Phoenix Zoo
  • 99. super column family super column family PointOfInterest { key: 85255 { column Phoenix Zoo { phone: 480-555-5555, desc: They have animals here. }, Spring Training { phone: 623-333-3333, desc: Fun for baseball fans. }, }, //end phx key super column key: 10019 { flexible schema Central Park { desc: Walk around. It's pretty.} , s Empire State Building { phone: 212-777-7777, desc: Great view from 102nd floor. } } //end nyc }
  • 100. about super column families • sub-column names in a SCF are not indexed – top level columns (SCF Name) are always indexed • often used for denormalizing data from standard CFs
  • 101. slice predicate • data structure describing columns to return – SliceRange • start column name • finish column name (can be empty to stop on count) • reverse • count (like LIMIT)
  • 102. • get() : Column – get the Col or SC at given ColPath read api COSC cosc = client.get(key, path, CL); • get_slice() : List<ColumnOrSuperColumn> – get Cols in one row, specified by SlicePredicate: List<ColumnOrSuperColumn> results = client.get_slice(key, parent, predicate, CL); • multiget_slice() : Map<key, List<CoSC>> – get slices for list of keys, based on SlicePredicate Map<byte[],List<ColumnOrSuperColumn>> results = client.multiget_slice(rowKeys, parent, predicate, CL); • get_range_slices() : List<KeySlice> – returns multiple Cols according to a range – range is startkey, endkey, starttoken, endtoken: List<KeySlice> slices = client.get_range_slices( parent, predicate, keyRange, CL);
  • 103. client.insert(userKeyBytes, parent, write api new Column(“band".getBytes(UTF8), “Funkadelic".getBytes(), clock), CL); batch_mutate – void batch_mutate( map<byte[], map<String, List<Mutation>>> , CL) remove – void remove(byte[], ColumnPath column_path, Clock, CL)
  • 104. //create param batch_mutate Map<byte[], Map<String, List<Mutation>>> mutationMap = new HashMap<byte[], Map<String, List<Mutation>>>(); //create Cols for Muts Column nameCol = new Column("name".getBytes(UTF8), “Funkadelic”.getBytes("UTF-8"), new Clock(System.nanoTime());); Mutation nameMut = new Mutation(); nameMut.column_or_supercolumn = nameCosc; //also phone, etc Map<String, List<Mutation>> muts = new HashMap<String, List<Mutation>>(); List<Mutation> cols = new ArrayList<Mutation>(); cols.add(nameMut); cols.add(phoneMut); muts.put(CF, cols); //outer map key is a row key; inner map key is the CF name mutationMap.put(rowKey.getBytes(), muts); //send to server client.batch_mutate(mutationMap, CL);
  • 105. what about… SELECT WHERE ORDER BY JOIN ON GROUP
  • 106. rdbms: domain-based model what answers do I have? cassandra: query-based model what questions do I have?
  • 107. SELECT WHERE cassandra is an index factory <<cf>>USER Key: UserID Cols: username, email, birth date, city, state How to support this query? SELECT * FROM User WHERE city = ‘Scottsdale’ Create a new CF called UserCity: <<cf>>USERCITY Key: city Cols: IDs of the users in that city. Also uses the Valueless Column pattern
  • 108. SELECT WHERE pt 2 • Use an aggregate key state:city: { user1, user2} • Get rows between AZ: & AZ; for all Arizona users • Get rows between AZ:Scottsdale & AZ:Scottsdale1 for all Scottsdale users
  • 109. ORDER BY Columns Rows are sorted according to are placed according to their Partitioner: CompareWith or CompareSubcolumnsWith •Random: MD5 of key •Order-Preserving: actual key are sorted by key, regardless of partitioner
  • 110. rdbms
  • 112. When To Use NoSQL • No schema – No SQL – Don’t do this KV DB design • Terrible performance, impossible to maintain • No persistency – No SQL – Heck – use a distributed cache for that • Low write latency – And fast storage is not an option • Simple queries – You can always ETL to a DB later • Cool factor – Good luck with that
  • 113. Real Life NoSQL Usages • MongoDB is great for CMS – Try MTV… • Cassandra is great for low latency writes • Use the right tool for the job – or you’ll get worse performance than a DB • Expect a very high learning curve to implement
  • 114. SpringData • In your face – there are frameworks that use NoSQL
  • 115. And To Finish • A long time ago people told me Java doesn’t perform nor scale…
  • 116. CODE
  • 117. ORM • Check the queries created – For instance, in Hibernate • setLast,setFirst – kill your performance • Lazy fetching • N+1 • Use batch updates
  • 118. Hibernate With Batch Updates session.doWork(new Work() { public void execute(Connection connection) throws SQLException { PreparedStatement stmt = connection.prepareStatement(“insert into test values(?,?)"); stmt.setLong(1, id); stmt.setLong(2, transId); call.execute(); } });
  • 119. JDBC Code • Always use prepared statements • Use your Database performance extensions – For instance, massive inserts for Column Store DBs
  • 120. Transactions • One transaction per hit. At most. • Reads can hurt your writes
  • 121. Database Tuning • We talked about it, but: – Indexes – good for read, bad for write – Multi column indexes – good only if query reads using the same order of columns – Indexes and views – EXPLAIN is your friend • Keep your DB small – BI against read-replica – Delete history – Ensure you only save what you actually need
  • 122. Final Note • NoSQL, SQL – it doesn’t matter if your code sucks!
  • 123. 2 Words On Cloud • Storage sucks • Network sucks • So – Cache locally – Write a-sync – Write to files, not DB – Don’t use RDS – Check Cloud providers that offer SSD

Hinweis der Redaktion

  1. There are many ways to scale MySQL, but we’ll try to follow some guidelines – Plain vanilla MySQL – we’re not going to go into the different Storage Engine stories. They require a lengthy data migration process, and as such are outside the scope of this webinar.MySQL – we’re not comparing MySQL to Postgress or any other database – open sourced or notAfter laying down these guidelines we’re left with the following options:Tuning – be it SQL tuning or MySQL tuningScaling up the hardware used to run MySQL – more memory, CPU or even SSDUse partioning – a cool scaling feature introduced by MySQL 5.1Use another distribution of MySQL, which uses the same storage engines – but has some improvements in the MySQL core which can cause performance improvementsRead/Write splitting – a technique to send reads and writes to different servers, in order to decrease the load on a specific server.Sharding – the most popular technique to scale-out MySQL – however, this technique comes at a price – which we’ll discuss.And I promise – no sales pitch. I will only mention the ScaleBase solution at the very end of the webinar, and I promise to be quick about it.
  2. The first step of any serious tuning process starts with tuning the MySQL database. This can be divided to two types of tuning:Operating system tuning – like setting socket timeout, freeing up memory, using dedicated cores, etc. This is specific to each operating system you run MySQL on – and most likely you can Google some good data on how to tune your operating system for MySQL.MySQL process tuning – which is usually not dependent on your operating system – but rather on your hardware and application usage. So let’s dive in and see what kind of options MySQL exposes for tuning.
  3. Now, for the sake of this webinar, we’ll dive into 2 important and very popular parameters. Both can be set in the my.cnf file.The first,  innodb_buffer_pool_size, holds the data and indexes of tables in memory. Database uses indexes to find data more quickly. Usually, you add indexes to columns used in the where clause of your SQL statement. If the index is in RAM – the search will perform much faster. If the data is in RAM – the fetching of data will be faster. The bigger this value is the better, but of course, it can’t exceed system memory, and you must take into account other applications running on the database server. Note that this parameter only holds for InnoDB, which is the default storage engine nowadays anyway.The second, QueryCache, is a cache of query results, stored until an update invalidates the query result. The bigger this value is – the more query results it can store, and make big queries on data that is not updated often, perform much faster. By default, MySQL stores only big queries in its cache, which is what query cache limit is used for.
  4. The Pros of database tuning are pretty obvious – it will probably result in major performance improvement, and is transparent to the application.The downside is that once completing the initial tuning process, additional tuning will deliver very little if any performance improvement.
  5. The next must have scaling strategy is tuning your SQL commands. It sounds pretty minor – how much damage can an SQL command do? You’ll be surprised. The following command actually performs a FULL TABLE SCAN – meaning that the database will have to run through the entire table – without the use of indexes. This is almost never a desired behavior as it results in lousy performance. Tuning such a query is simple – just write the name of the columns you wish to query – even if it’s a list of all the columns in the table. You’ll see substantial performance improvements, and the bigger the table – the bigger the improvement. This might seem negligible, but if the database is under heavy load, long running queries will actually take even longer to execute. The reason is transaction isolation, a topic we’ll not discuss in this webinar – but you can find more info about it in the ScaleBase blog section. So always make sure you fine tune your SQL commands. Note that this task should be done by experts, as it’s not a skill developers usually have.
  6. Here are some very general tips on SQL command tuning. MySQL offers an EXPLAIN command, which shows how MySQL executes a query – which tables are accessed first, indexes, etc. Always use EXPLAIN when tuning your SQL commands.DISTINCT in MySQL is faster than Group By. The reason is that while MySQL executes both commands the same way (which means a temporary table is created for the results) – MySQL sorts the results when performing a Group By – thus taking an additional step when executing the query.If you use an indexed column as a function parameter in a where clause – the index will not be used – and a full table scan might be performedUsing non deterministic functions in the where clause, like CURRENT_DATE(), will eliminate the query results from the query cache – a major performance hit.
  7. So the pros of SQL tuning are clear – it will probably result in major performance improvements. The down side is that it requires code modifications, can take a long time, and at then end of the day – is still limited, since under heavy load even the best queries will perform poorly.A point to remember when talking about code modifications – when using ORM tools, changing queries can be really difficult – as not all ORM tools give the option of tuning the SQL query.
  8. Scaling up the hardware is the oldest trick in the book. Buy a new machine, and Moore’s law will make sure it’s much stronger than the one you already have. If that was the case – none of us would have been here. Scaling up MySQL is limited. And those graphs, built by Baron Schwartz of Percona fame show just that. Performance improves as hardware becomes more powerful – but at some point, performance starts to degrade. MySQL has a sweet spot – meaning an optimal hardware configuration. Anything more powerful than this configuration will not improve performance, but in fact might even degrade it.
  9. I think the pros and cons of scaling up are pretty clear – the easiest way to go – but it’s limited and might be very expensive, for high end hardware.
  10. SSD is another form of scaling up. SSD stands for Solid State Drives, and they’re basically the new generation of hard-disks – they work much faster than regular hard drives. Without going into the technicalities involved, SSD use microchips to store data, so unlike hard-drives, no moving parts are involved, and access time is much faster.However – they are more expensive. And while improving performance – SSD doesn’t scale indefinitely. As VadimTkachenko of Percona showed in his MySQL Conference presentation – you can expect a times seven performance improvement by moving to SSD, but that’s that.
  11. The pros and cons for the SSD solution are similar to those of scaling up hardware.
  12. Partitioning is a great feature introduced to MySQL 5.1. To understand it, we need to understand how MySQL stores data in tables. Each table is mapped to a file on the file system. Partitioning lets you store the table in multiple files. The result is improved performance – queries and inserts run much faster, since indexes are smaller and can fit in RAM.
  13. The table in this slide can show just how well database partitioning can perform. Those results are based on specific use cases, and incorrect partitioning configuration can hurt performance – but if you know what you’re doing, partitioning is a great solution.
  14. While partitioning is not completely transparent to the application (as some SQL limitations apply), it’s a great solution for performance improvements. However – it’s not perfect. And the reason is that although it improves I/O, CPU bound actions, like user concurrency or transactions isolations are still bottle necks that hurt performance under heavy load.
  15. Many companies rose up to release new MySQL distributions. We mention them here since they usually show major performance improvements, while still being a 100% drop-in replacement for MySQL, and can use the same storage engine MySQL uses. Percona Server and MariaDB are the leading examples, but you can find other distributions as well.
  16. And again – while performance improvements might be gained with new MySQL distributions – scalability is still limited at the machine level.
  17. We now reach the first solution that can truly scale out MySQL. With Read/Write splitting, the application directs all writes to a single, master, server. That server is replicating all its data to any number of slaves. Read operations from the application can be executed against any one of the slaves.This solution requires code modifications in the application, but also poses some data consistency situations – since replication in MySQL is a-synchronous, it is possible that the application will read data from a slave that is not up to date. This is an acceptable situation for many applications, since the data is not lost, and will appear in the next query. However, for some applications this is unacceptable.Another point to remember is that if the application started a transaction, database stickiness must be implemented. And that if the transaction executes a write operation, then even read operations in that transaction must be executed on the master server, so the code implementation is quite complex.
  18. Read/Write splitting greatly improves database performance, and is unlimited in its scaling capabilities, since it allows you to scale out the database. However, it requires code changes, and might create consistency problems in the application. But the biggest con of read/write splitting is that write operations are still executed on one server. Since many applications use caching layers – many databases see allot of write traffic – and read/write splitting doesn’t help these applications one bit.
  19. Memory mapped files, BSON, indexes, multiple data types, binary files, etc@ main datasets: places and checkins use cases: given current loc find places nearby; add notes to locations Record checkinsGenerate stats about checkins
  20. Memory mapped files, BSON, indexes, multiple data types, binary files, etc@ main datasets: places and checkins use cases: given current loc find places nearby; add notes to locations Record checkinsGenerate stats about checkins
  21. Documents go into collectionsTodays app: users , places, checkins
  22. Latlong are actually real lat / long points$near gives you the closest 100
  23. Latlong are actually real lat / long points$near gives you the closest 100
  24. Latlong are actually real lat / long points$near gives you the closest 100
  25. Memory mapped files, BSON, indexes, multiple data types, binary files, etc@ main datasets: places and checkins use cases: given current loc find places nearby; add notes to locations Record checkinsGenerate stats about checkins