Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
©2017Percona1
PeterZaitsev
MySQLvsMongoDBChoosingrighttechnologyforyourapplication
CEO,PerconaAllThingsOpen,Raleigh,NCOctober23rd,2017
©2017Percona2
MySQLvsMongoDB
VS
©2017Percona3
BiggerQuestion
WhatOpenSourceDatabaseTechnologies IshouldbeusingforMy
Application?
©2017Percona4
EvenBiggerQuestion
WhatDatabaseTechnologiesIshouldbeusingforMyApplication
©2017Percona5
OpenSource
IncreasingnumberofOpenSourceFirstCompanies
OnlyuseProprietarySoftwarewhentherearenogoodOpenSourceChoices
Cost,ReducedVendorLock,Choice
Talentaccess– developerspreferOpenSource
©2017Percona6
Modern=OpenSource
©2017Percona7
WhyMySQLandMongoDB?MostPopularOpenSource SQLandNoSQLEngines
©2017Percona8
WhyMySQLandMongoDB?
TwoTechnologiesPerconaProvidesSolutionsFor
©2017Percona9
ItisnotOneOR anotherchoicereally
ManyComplexApplicationsusebothMySQLandMongoDB
PolyglotPersistence
Micro-serviceswithindependentpersistencechoices
Cloud,DBaaSallowstosimplifyDBrollout
©2017Percona10
FullDisclosure
IknowMySQLMuchbetterthanMongoDB…whichwillimpactmy
bias
©2017Percona11
MySQL
RelationalDatabaseFirstandForemost
FullSQLSupport,Transactions,ACID
DesignedforaSingleServerfirst
Scale-OutasAfterthought
©2017Percona12
MongoDB
Designedfor“WebScale”
Scalability,Cloud,MultipleMachines
ReplicationandShardingpartofinitialdesign
Onlyfeatureswhichcanscale
©2017Percona13
Q1:Whatdoyouknowandlove?
BothMySQLandMongoDBarevery
capable.Yourexperienceandpreferencematter
©2017Percona14
Q2:Whichdatamodelfitsbetter?
Relational
•MySQLObviousChoice
DocumentBased
•MongoDBObviouschoice
•MySQLhasDocumentStorestarting5.7
©2017Percona15
Q3:HowDataisUsed
Databelongstosingleapplication
• JSONmodelmoreexpressiveforapplicationdatastructures
• Schemadesignedforspecificaccesspaths
Datasharedbymultipleapplications
• Relationalstructureeasiertoshare
• Canbemoreflexibleinhowdataisaccessed
©2017Percona16
Q4:Transactions
NeedfullTransactions
•MySQLcanbebetterchoice
•OneofthemainbenefitsofMySQLDocumentStore
DonotneedTransactions
•MongoDBcanbegreatchoice
•CandoAtomicDocumentUpdates
©2017Percona17
Q5:JOINs
AdvancedJOINsandotherSQLfeatures
• MySQLmuchmorepowerful
• $lookupand$graphLookupfeaturesinMongoDBaggregationframework
Mainlysimplelookupswithfilters/sorting
• MongoDBandMySQLbothdotheseverywell
©2017Percona18
Q6:Scale
SingleServerisGoodEnough
• MySQLworksgreat• WelloptimizedforManycores;largememory;faststorage
NeedMassiveScaleout
• AutomatedshadinginMongoDBismuchbetter
• ReplicationinMongoDBiseasiertouse
• SolutionslikeVitesstrytomakeitlesspainfulforMySQL
©2017Percona19
Q7:LargeScaleAggregation
MongoDB
• hasbuiltinaggregationframeworkforparallelprocessing
• BIConnectorandToroDBforSQLaccess
• ReplicatetoHadoop
MySQL
• Executeseveryquerysinglethreaded
•MariaDBColumnStore(InfiniDBreborn)
• ClickHouse• ReplicatetoHadoop
©2017Percona20
Q8:AccessLanguage
SQL
•Structured•Query•Language
CRUD
•Create•Read•Update•Delete
©2017Percona21
NotjustDatabasebut…LanguageSupport
MySQL
•DriversareverythinglayertorunSQLQueries
•ManyindependentORMFrameworks
MongoDB
•NativelookandfeelofProgrammingLanguage
©2017Percona22
Learningfromeachother
MySQL
•DocStoreinMySQL5.7
•JSONtoRelationalandBackinMySQL8
MongoDB
•MongoDBBIConnector(Enterprise)torunSQL
•MySQLWireProtocol
©2017Percona23
MySQLandMongoDBcomparedCourtesyofAlexanderRubin
©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"
}
©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/
©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/
©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
©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
©2017Percona29
WhereismyInnoDB?
MySQL MongoDB
MyISAM
InnoDB
TokuDB
MyRocks(RocksDB)*
MMAPv1 memorymappedstoredengine,
WiredTigertransactional,withcompression,btree
PerconaMemoryEngine
MongoRocks (RocksDB)
©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,
...}
©2017Percona31
WherearemyGrants?
mysql> grant all on *.* to user@localhost identified by ‘pass’;
> use productsdb.createUser(
{user: "accountUser",pwd: "password",roles: [ "readWrite",
"dbAdmin" ]}
)
©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"
}]
©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
}
©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,
..
©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
©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
©2017Percona37
100%FreeandOpenSource
InteractiveTroubleshootingandPerformanceOptimization
BuiltonBestinclasssoftware–PrometheusandGrafana
CheckOutOnlineDemohttp://pmmdemo.percona.com
ForMySQLandMongoDBfromPercona
©2017Percona38
FindWhat QueriesareCausingtheLoad
©2017Percona39
FindWhat QueriesareCausingtheLoad
©2017Percona40
Why AretheycausingthisLoad
©2017Percona41
How tofixthem
©2017Percona42
In-DepthDatabase OperationalDetails
©2017Percona43
AswellasSystemLevelOperationalDetails
©2017Percona44
ThinkingaboutusingMongoDB?ConsidertryingoutPerconaServerforMongoDB
©2017Percona45
PerconaServerforMongoDB3.4
100%CompatiblewithMongoDB3.4CommunityEdition
OpenSourcewithAlternativestomanyMongoDBEnterpriseFeatures
MongoRocks(RocksDB)andPerconaMemoryEngine
New:SensitiveDataMasking
New:QuerySampling
New:HotBackupforWiredTiger andMongoRocks
©2017Percona46
PerconaMemoryEngineforMongoDBBenchmarks
©2017Percona47
WiredTiger vsMongoRocks – writeintensive
©2017Percona48
SAVE THE DATE!
CALL FOR PAPERS OPENING SOON!www.perconalive.com
April 23-25, 2018Santa Clara Convention Center
©2017Percona49
AboutPerconaSolutionsforyoursuccesswithMySQL,MariaDB andMongoDB
Support,ManagedServices,Consulting,Training,Software
OurSoftwareis100%FreeandOpenSource
SupportBroadEcosystem– MySQL,MariaDB,AmazonRDS,GoogleCloudSQL
InBusinessfor11years
Morethan3000customers,includingtopInternetcompaniesandenterprises
DATABASE PERFORMANCEMATTERS
DatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMatters