66
© 2017 Percona 1 Peter Zaitsev MySQL vs MongoDB Choosing right technology for your application CEO,Percona SCALE 15x 3 March 2017, Pasadena,CA

MySQL vs MongoDB - Percona · My MySQL vs MongoDB Most Popular Open Source Relational and Non Relational storage Both Technologies started with Focus on Exceptional Ease of Use

  • Upload
    buithuy

  • View
    218

  • Download
    1

Embed Size (px)

Citation preview

©2017Percona1

PeterZaitsev

MySQLvsMongoDBChoosingrighttechnologyforyourapplication

CEO,PerconaSCALE15x3March2017,Pasadena,CA

©2017Percona2

MySQLvsMongoDB

VS

©2017Percona3

BiggerQuestion

WhatOpenSourceDatabaseTechnologies IshouldbeusingforMy

Application?

©2017Percona4

EvenBiggerQuestion

WhatDatabaseTechnologiesIshouldbeusingforMyApplication

©2017Percona5

OpenSource

IncreasingnumberofOpenSourceFirstCompanies

OnlyuseProprietarySoftwarewhentherearenootherchoices

Cost,ReducedVendorLockInarethemainfactors

©2017Percona6

OpenSourcevsProprietarytrends

©2017Percona7

NewGenerationTechnologies– OpenSource

©2017Percona8

PolyglotPersistence

ChooseMultipleDatabasesystems

UseTheirStrongSides

©2017Percona9

ArchitectureExamples

MainOperationStore+AuxiliaryServices

MicroServiceswiththeirownstores

DataBus/DataFlow

©2017Percona10

ForExample

MySQLasmaindatastore

UseMemcacheorRedisforcaching

ElasticSearchforSearch

KafkatotransferdatatoElasticSearch,Hadoop

©2017Percona11

ChoosingtheDataStore

SQL(Relational)

NoSQL(NonRelational)

©2017Percona12

ManyNoSQLDataModels

KeyValue(Memcache)

WideColumn(Cassandra)

Document(MongoDB)

Graph(Neo4J)

©2017Percona13

WhyMySQLvsMongoDB?

©2017Percona14

MyMySQLvsMongoDB

MostPopularOpenSourceRelationalandNonRelationalstorage

BothTechnologiesstartedwithFocusonExceptionalEaseofUse

Theseare2TechnologieswefocusatPercona

©2017Percona15

PerconaSoftwareforMySQLandMongoDB

MySQL

• PerconaServerforMySQL• PerconaXtraDBCluster• PeronaXtrabackup• PerconaToolkit• PerconaMonitoringandManagement

• TokuDBStorageEngine

MongoDB

• PerconaServerforMySQL•MongoRocksDBStorageEngine(RocksDBBased)

• PerconaMemoryEngineforMongoDB

• PerconaToolkit• PerconaMonitoringandManagement

©2017Percona16

FullDisclosure

IPersonallyknowMySQLmuchbetterthan

MongoDB

©2017Percona17

NoSQLonMySQL

StartingMySQL5.7MySQLSupportsNoSQLInterface

MongoDBLikeCRUDaccess

WithTransactionSupport

WithoutGoodShardingSolution

Notyetcommonlyadopted

©2017Percona18

TopThingstoConsider

TeamPreferencesandExperience

DevelopmentProcessandApplicationLifecycle

DataModel TransactionsandConsistency

Performance Scalability Administration Legal

©2017Percona19

TeamPreferencesandExperience

AbsolutelyKeyQuestion!

UnlovedTechnology– RecipeforDisaster

Problemsmayhavemorethanonesolution

ConsiderOriginalDevelopmentandFullLifecycle

©2017Percona20

TeamExperienceMySQLvsMongoDB

MySQL

• VeryMatureTechnology• SQLStandard• Easiertomovetootherrelationaldatabases

• Transactions• AlotofChoices

MongoDB

•ModernandDynamic• DonotneedtolearnnastySQL• DynamicSchema• ComplexQueriesarerecipeforcomplexproblems

• EasierScalability• NativeIntegrationJavascript,JSON

©2017Percona21

DevelopmentProcessandLifeCycle

FasterDevelopmentpaceormorecontrol?

DataAlwaysHaveSchema

IsDataBelongtoApplicationorusedbyMultipleApplications

ApplicationLifeTime

ApplicationActivedevelopmenttime

©2017Percona22

DevelopmentinMySQLandMongoDB

MySQL

• RelationalDatabaserequiresmoreplanningandcontrol

• Easytousedatafrommanyapplications

• Manyapplications15+Years• CanuseSQLandNoSQLInterface

MongoDB

• DevelopmentPace• NoNeedtoSynchronizeSchemabetweenApplicationandDatabase

• ClearPathtoScalability

©2017Percona23

DataModel

OptimalDataModeldependsontheApplicationandTeamExperince

©2017Percona24

DataModelinMySQLvsMongoDB

MySQL

• RelationalDataModel• Easytoreflectrelationshipsbetweenobjects

• Changedatainoneplace• QueryResult- Table

MongoDB

• DocumentOrientedDataModel• Documentscanembedotherdocuments

• EasytorepresentJSONdatacommoninWebApplications

• ComplexJOINscanoftenbeavoided• QueryResult– ListofDocuments(differentstructure)

©2017Percona25

ModelDesignExample

PeopleandtheirPassports

Peoplemayhavemorethanonpassport

NotEveryoneHasaPassport

©2017Percona26

RelationalSchemaDesign

©2017Percona27

EasyToAnswerVariousQuestions• NumberofPeople

• SELECTcount(*)FROMpeople• ValidityDateofPersonspassport

• SELECTvalid_until frompassportsps joinpeoplepl ONps.people_id =pl.idWHEREname='Stephane‘

• WhoDoesnothaveAPassport?• SELECTnameFROMpeoplepl LEFTJOINpassportsps ONps.people_id =

pl.idWHEREps.idISNULL

©2017Percona28

MongoDBDesignExample

©2017Percona29

MongoDBandMySQLTerms

MySQL

• Database/Schema• Table• Row• Column• PrimaryKey• Join

MongoDB

• Database• Collection• Document• Field• PrimaryKey• EmbeddedDocumentorLinking

©2017Percona30

AccessLanguage

SQL

•Structured•Query•Language

CRUD

•Create•Read•Update•Delete

©2017Percona31

SQLvsCRUD- InsertSQL CRUD

©2017Percona32

SQLvsCRUDUpdate

©2017Percona33

SQLvsCRUD- Delete

©2017Percona34

SQLvsCRUD- Search

©2017Percona35

SQLvsCRUD- Count

©2017Percona36

SQLvsCRUD- Aggregation

©2017Percona37

TransactionsandConsistency

• Atomicity• Consistency• Isolation• Durability

©2017Percona38

TransactionsinMySQLvsMongoDB

MySQL

•ACIDTransactionsofarbitrarysize

MongoDB

•ACIDonthedocumentlevel

©2017Percona39

MongoDBReadsareDirtyReads

ReadingaLargeResultwillReturnDocumentsfromdifferentpointintime

SameDocumentCan(rarely)beReturnedMorethanOnce

©2017Percona40

Performance

VeryHardtoCompareDirectly

DependsalotontheApplicationArchitecture

ManyBenchmarkscomparedifferentDurabilityorSettings

MongoDBScalesBettersosinglenodeperformancelessofafocus

©2017Percona41

MySQLvsMongoDBPerformanceTestbyMarkCallaghan:http://bit.ly/2epDJqD

©2017Percona42

Scalablilty

•Scalabilitywithinsinglesystem•Scalabilityformultiplesystems•Scalingreads,writes,datasize

WhatdoIneedtodotoscalemyApplicationfrom100to100.000.000

users?

©2017Percona43

ScalabilityMySQLandMongoDB

MySQL

• Scaleswellwithsinglesystemsize

• CanbescaledtoFacebookScale• Easytoscaleformediumsizeapplications

• ScalingReadswithReplication• ShardingisPainful

MongoDB

• Scalabilitywasfocuseduponfromtheearlyversions

• BuiltinSharding• ShardingforScalability,ReplicationisforHA

©2017Percona44

DatabaseOperationsWhatDevelopersdonotlikethinkingabout

Automation

Backups

VersionUpdates

Monitoring

DisasterRecovery

PerformanceManagement

©2017Percona45

OperationsMySQLandMongoDB

MySQL

• Flexibility• Manywaystosolveproblems• ManyOpenSourceToolsavailable

• OutoftheboxManualFailoverinReplication

MongoDB

• Simplicity• VirtuallyZeroAdministration• FewerOpenSourceOperationTools

• StrongConnectiontoMongoDBOpsManager

©2017Percona46

License

MySQL

•GPLorProprietary

MongoDB

•AGPLorProprietary

©2017Percona47

SolvedMongoDBProblems• PoorconcurrentwriteperformancewithMMAPv1

• FixedbyWiredTiger andMongoRocks• PoordiskspaceusagewithMMAPv1

• FixedbyWiredTiger andMongoRocks• Nowaytovalidatedocuments

• DocumentValidationsinceMongoDB3.2• NoJOIN

• LimitedsupportinaggregationframeworkstartingMongoDB3.2

©2017Percona48

TypicalMySQLExample

• FullFeatureTransactionsareimportant• RelationalModelisagoodfit• Datasizeistypicallynotrequiringsharding• LongTermApplicationdevelopment• Samedatausedbymanyapplicationsdirectly

OnlineEcommerce

©2017Percona49

TypicalMongoDBExample

• Extremescalingmightbeneededifgamebecomespopular

• Dataisusedbyoneapplication• Dataiscomplicatedanddoesnotfitrelationalmodelwell

• Documentlevelconsistencyisoftenenough• Lowpaceofdevelopmentafter“launch”

OnlineGame

Backend

©2017Percona50

ExtraMaterialOtherthingsworthsharing

©2017Percona51

JustReleased!

©2017Percona52

PerconaServerforMongoDB3.4

100%FreeandOpenSource

100%CompatiblewithMongoDB3.4

AdditionalMemoryEngineandMongoRocks

PluggableAuthenticationas

inMongoDBEnterprise

AuditingasinMongoDBEnterprise

AdvancedQueryPerformanceMonitoring

HotBackupsforWiredTiger

©2017Percona53

PerconaMonitoringandManagement

• Comprehensive Database Focused Monitoring

• 100% Open Source Roll-your-own solution

• Easy to install and use

• Supports MySQL and MongoDB

• Version 1.1 focuses on Trending and Query Analyses

• Management Features to Come

©2017Percona54

WhatQueriesarecausingtheload?

©2017Percona55

Whyaretheycausingthisload?

©2017Percona56

Howtofixthem

©2017Percona57

SystemInformation

©2017Percona58

WhathappensonOSandHardwareLevel

©2017Percona59

AswellasDatabaseLevel

©2017Percona60

DetailedMongoDBStorageEngineMonitoring

©2017Percona61

CheckouttheDemohttp://pmmdemo.percona.com

©2017Percona62

©2017Percona63

©2017Percona64

MeetusatBooth#219

©2017Percona65

AboutPerconaSolutionsforyoursuccesswithMySQLandMongoDB

Support,ManagedServices,Software

OurSoftwareis100%OpenSource

SupportBroadEcosystem– MySQL,MariaDB,AmazonRDS

InBusinessformorethan10years

Morethan3000customers,includingtopInternetcompaniesandenterprises

DATABASE PERFORMANCEMATTERS

DatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMattersDatabasePerformanceMatters