50
© 2017 Percona 1 Peter Zaitsev MySQL vs MongoDB Choosing right technology for your application CEO, Percona All Things Open, Raleigh,NC October 23 rd , 2017

Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona1

PeterZaitsev

MySQLvsMongoDBChoosingrighttechnologyforyourapplication

CEO,PerconaAllThingsOpen,Raleigh,NCOctober23rd,2017

Page 2: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona2

MySQLvsMongoDB

VS

Page 3: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona3

BiggerQuestion

WhatOpenSourceDatabaseTechnologies IshouldbeusingforMy

Application?

Page 4: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona4

EvenBiggerQuestion

WhatDatabaseTechnologiesIshouldbeusingforMyApplication

Page 5: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona5

OpenSource

IncreasingnumberofOpenSourceFirstCompanies

OnlyuseProprietarySoftwarewhentherearenogoodOpenSourceChoices

Cost,ReducedVendorLock,Choice

Talentaccess– developerspreferOpenSource

Page 6: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona6

Modern=OpenSource

Page 7: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona7

WhyMySQLandMongoDB?MostPopularOpenSource SQLandNoSQLEngines

Page 8: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona8

WhyMySQLandMongoDB?

TwoTechnologiesPerconaProvidesSolutionsFor

Page 9: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona9

ItisnotOneOR anotherchoicereally

ManyComplexApplicationsusebothMySQLandMongoDB

PolyglotPersistence

Micro-serviceswithindependentpersistencechoices

Cloud,DBaaSallowstosimplifyDBrollout

Page 10: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona10

FullDisclosure

IknowMySQLMuchbetterthanMongoDB…whichwillimpactmy

bias

Page 11: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona11

MySQL

RelationalDatabaseFirstandForemost

FullSQLSupport,Transactions,ACID

DesignedforaSingleServerfirst

Scale-OutasAfterthought

Page 12: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona12

MongoDB

Designedfor“WebScale”

Scalability,Cloud,MultipleMachines

ReplicationandShardingpartofinitialdesign

Onlyfeatureswhichcanscale

Page 13: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona13

Q1:Whatdoyouknowandlove?

BothMySQLandMongoDBarevery

capable.Yourexperienceandpreferencematter

Page 14: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona14

Q2:Whichdatamodelfitsbetter?

Relational

•MySQLObviousChoice

DocumentBased

•MongoDBObviouschoice

•MySQLhasDocumentStorestarting5.7

Page 15: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona15

Q3:HowDataisUsed

Databelongstosingleapplication

• JSONmodelmoreexpressiveforapplicationdatastructures

• Schemadesignedforspecificaccesspaths

Datasharedbymultipleapplications

• Relationalstructureeasiertoshare

• Canbemoreflexibleinhowdataisaccessed

Page 16: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona16

Q4:Transactions

NeedfullTransactions

•MySQLcanbebetterchoice

•OneofthemainbenefitsofMySQLDocumentStore

DonotneedTransactions

•MongoDBcanbegreatchoice

•CandoAtomicDocumentUpdates

Page 17: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona17

Q5:JOINs

AdvancedJOINsandotherSQLfeatures

• MySQLmuchmorepowerful

• $lookupand$graphLookupfeaturesinMongoDBaggregationframework

Mainlysimplelookupswithfilters/sorting

• MongoDBandMySQLbothdotheseverywell

Page 18: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona18

Q6:Scale

SingleServerisGoodEnough

• MySQLworksgreat• WelloptimizedforManycores;largememory;faststorage

NeedMassiveScaleout

• AutomatedshadinginMongoDBismuchbetter

• ReplicationinMongoDBiseasiertouse

• SolutionslikeVitesstrytomakeitlesspainfulforMySQL

Page 19: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona19

Q7:LargeScaleAggregation

MongoDB

• hasbuiltinaggregationframeworkforparallelprocessing

• BIConnectorandToroDBforSQLaccess

• ReplicatetoHadoop

MySQL

• Executeseveryquerysinglethreaded

•MariaDBColumnStore(InfiniDBreborn)

• ClickHouse• ReplicatetoHadoop

Page 20: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona20

Q8:AccessLanguage

SQL

•Structured•Query•Language

CRUD

•Create•Read•Update•Delete

Page 21: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona21

NotjustDatabasebut…LanguageSupport

MySQL

•DriversareverythinglayertorunSQLQueries

•ManyindependentORMFrameworks

MongoDB

•NativelookandfeelofProgrammingLanguage

Page 22: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona22

Learningfromeachother

MySQL

•DocStoreinMySQL5.7

•JSONtoRelationalandBackinMySQL8

MongoDB

•MongoDBBIConnector(Enterprise)torunSQL

•MySQLWireProtocol

Page 23: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona23

MySQLandMongoDBcomparedCourtesyofAlexanderRubin

Page 24: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona24

Fromto

MySQL MongoDB

mysql> select * from zips limit 1\G*************************** 1. row ***************************country_code: USpostal_code: 34050place_name: FPOadmin_name1: admin_code1: AAadmin_name2: Erieadmin_code2: 029admin_name3: admin_code3:

latitude: 41.03750000longitude: -111.67890000accuracy:

1 row in set (0.00 sec)

MongoDB shell version: 3.0.8connecting to: zips> db.zips.find().limit(1).pretty(){

"_id" : "01001","city" : "AGAWAM","loc" : [

-72.622739,42.070206

],"pop" : 15338,"state" : "MA"

}

Page 25: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona25

WhereismySQL?

MySQL MongoDB

CREATE TABLE users (

id MEDIUMINT NOT NULL

AUTO_INCREMENT,

user_id Varchar(30),

age Number,

status char(1),

PRIMARY KEY (id)

)

db.users.insert( {

user_id: "abc123",

age: 55,

status: "A"

} )

(no schema)

SQLtoMongoDBMappingCharthttps://docs.mongodb.org/manual/reference/sql-comparison/

Page 26: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona26

WhereismySQL?

MySQL MongoDB

SELECT *

FROM users

WHERE status = "A"

AND age = 50

db.users.find(

{ status: "A",

age: 50 }

)

SQLtoMongoDBMappingCharthttps://docs.mongodb.org/manual/reference/sql-comparison/

Page 27: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona27

Whereismy/etc/my.cnf?

MySQL MongoDB

/etc/my.cnf /etc/mongod.conf

# Where and how to store data.storage:

dbPath: /datawtjournal:

enabled: trueengine: wiredTiger

...

/usr/bin/mongod -f /etc/mongod.conf

Page 28: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona28

Wherearemydatabases/tables?

MySQL MongoDB

Databasesmysql> show databases;+--------------------+| Database |+--------------------+| information_schema |...

mysql> use zipsDatabase changed

Tablesmysql> show tables;+----------------+| Tables_in_zips |+----------------+| zips |+----------------+

Databases> show dbs;admin 0.000GBlocal 0.000GBosm 13.528GBtest 0.000GBzips 0.002GB

> use zipsswitched to db zips

Collections> show collectionszips> show tables // samezips

Page 29: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona29

WhereismyInnoDB?

MySQL MongoDB

MyISAM

InnoDB

TokuDB

MyRocks(RocksDB)*

MMAPv1 memorymappedstoredengine,

WiredTigertransactional,withcompression,btree

PerconaMemoryEngine

MongoRocks (RocksDB)

Page 30: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona30

WhereismyProcesslist?

mysql> show processlist\G*************************** 1. row ***************************

Id: 137259User: rootHost: localhostdb: geonames

Command: QueryTime: 0State: initInfo: show processlist

Rows_sent: 0Rows_examined: 01 row in set (0.00 sec)

> db.currentOp(){

"inprog" : [{

"desc" : "conn28","threadId" : "0x19b85260","connectionId" : 28,"opid" : 27394208,"active" : true,"secs_running" : 3,"microsecs_running" :

NumberLong(3210539),"op" : "query","ns" : "osm.points3","query" : {

"name" : "Durham"},"planSummary" : "COLLSCAN","client" : "127.0.0.1:58835","numYields" : 24905,"locks" : {

"Global" : "r","Database" : "r","Collection" : "r"

},"waitingForLock" : false,

...}

Page 31: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona31

WherearemyGrants?

mysql> grant all on *.* to user@localhost identified by ‘pass’;

> use productsdb.createUser(

{user: "accountUser",pwd: "password",roles: [ "readWrite",

"dbAdmin" ]}

)

Page 32: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona32

WhereismyIndex?

MySQL MongoDBmysql> show keys from zips\G*************************** 1. row ***************************

Table: zipsNon_unique: 0Key_name: PRIMARY

Seq_in_index: 1Column_name: idCollation: A

Cardinality: 0Sub_part: NULLPacked: NULLNull:

Index_type: BTREEComment:

Index_comment: *************************** 2. row ***************************

Table: zipsNon_unique: 1Key_name: postal_code

Seq_in_index: 1...

> db.zips.getIndexes()[

{"v" : 1,"key" : {

"_id" : 1},"name" : "_id_","ns" : "zips.zips"

}]

Page 33: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona33

Whereismyaddindex?

mysql> alter table zips add key (postal_code);Query OK, 0 rows affected (0.10 sec)Records: 0 Duplicates: 0 Warnings: 0

> db.zips.createIndex({ state : 1 } ){

"createdCollectionAutomatically" : false,

"numIndexesBefore" : 1,"numIndexesAfter" : 2,"ok" : 1

}

// Index can be sorted:

> db.zips.createIndex({ state : -1 } ){

"createdCollectionAutomatically" : false,

"numIndexesBefore" : 2,"numIndexesAfter" : 3,"ok" : 1

}

Page 34: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona34

WhereismySlowQueryLog?

MySQL MongoDB

mysql> set global long_query_time = 0.1;Query OK, 0 rows affected (0.02 sec)

mysql> set global slow_query_log = 1;Query OK, 0 rows affected (0.02 sec)

mysql> show global variables like 'slow_query_log_file';+---------------------+------------------------------+| Variable_name | Value |+---------------------+------------------------------+| slow_query_log_file | /var/lib/mysql/thor-slow.log |+---------------------+------------------------------+1 row in set (0.00 sec)

db.setProfilingLevel(level,slowms)

Level: 0 for no profiling, 1 for only slow operations, or 2 for all

operations.

Slowms = long_query_time but in milliseconds> db.setProfilingLevel(2, 100);{ "was" : 0, "slowms" : 100, "ok" : 1 }

> db.system.profile.find( { millis : { $gt : 100 } } ).pretty(){

"op" : "query","ns" : "zips.zips","query" : {

"city" : "DURHAM"},"ntoreturn" : 0,

..

Page 35: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona35

Export from MySQL 5.7:mysql> SELECT JSON_OBJECT('name', replace(name, '"', ''), 'other_tags', replace(other_tags, '"', ''), 'geometry', st_asgeojson(shape)) as j

FROM `points` INTO OUTFILE '/var/lib/mysql-files/points.json'; Query OK, 13660667 rows affected (4 min 1.35 sec)

Fromto

Page 36: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona36

Load to MongoDB (parallel):mongoimport --db osm --collection points -j 24 --file /var/lib/mysql-files/points.json 2016-04-11T22:38:10.029+0000 connected to: localhost2016-04-11T22:38:13.026+0000 [........................] osm.points 31.8 MB/2.2 GB (1.4%)2016-04-11T22:38:16.026+0000 [........................] osm.points 31.8 MB/2.2 GB (1.4%)2016-04-11T22:38:19.026+0000 [........................] osm.points 31.8 MB/2.2 GB (1.4%)…2016-04-11T23:12:13.447+0000 [########################] osm.points 2.2 GB/2.2 GB (100.0%)2016-04-11T23:12:15.614+0000 imported 13660667 documents

Fromto

Page 37: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona37

100%FreeandOpenSource

InteractiveTroubleshootingandPerformanceOptimization

BuiltonBestinclasssoftware–PrometheusandGrafana

CheckOutOnlineDemohttp://pmmdemo.percona.com

ForMySQLandMongoDBfromPercona

Page 38: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona38

FindWhat QueriesareCausingtheLoad

Page 39: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona39

FindWhat QueriesareCausingtheLoad

Page 40: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona40

Why AretheycausingthisLoad

Page 41: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona41

How tofixthem

Page 42: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona42

In-DepthDatabase OperationalDetails

Page 43: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona43

AswellasSystemLevelOperationalDetails

Page 44: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona44

ThinkingaboutusingMongoDB?ConsidertryingoutPerconaServerforMongoDB

Page 45: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona45

PerconaServerforMongoDB3.4

100%CompatiblewithMongoDB3.4CommunityEdition

OpenSourcewithAlternativestomanyMongoDBEnterpriseFeatures

MongoRocks(RocksDB)andPerconaMemoryEngine

New:SensitiveDataMasking

New:QuerySampling

New:HotBackupforWiredTiger andMongoRocks

Page 46: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona46

PerconaMemoryEngineforMongoDBBenchmarks

Page 47: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona47

WiredTiger vsMongoRocks – writeintensive

Page 48: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona48

SAVE THE DATE!

CALL FOR PAPERS OPENING SOON!www.perconalive.com

April 23-25, 2018Santa Clara Convention Center

Page 49: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

©2017Percona49

AboutPerconaSolutionsforyoursuccesswithMySQL,MariaDB andMongoDB

Support,ManagedServices,Consulting,Training,Software

OurSoftwareis100%FreeandOpenSource

SupportBroadEcosystem– MySQL,MariaDB,AmazonRDS,GoogleCloudSQL

InBusinessfor11years

Morethan3000customers,includingtopInternetcompaniesandenterprises

Page 50: Choosing right technology for your application · Q3: How Data is Used Data belongs to single application •JSON model more expressive for application data structures •Schema designed

DATABASE PERFORMANCEMATTERS

DatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMatters