Radiologists & Gorillas83 Percent of Radiologists Didn’t Spot the GorillaHiding in This CT Scan– Picture of gorilla hidden in last slide of ten lungscans.– They wanted to see if the radiologists, focused onthe telltale nodules, would be blind to the easilydetectable and highly anomalous gorilla– The gorilla was miniscule, but huge compared tothe nodules. It was about the size of a box ofmatches-or 48 times the size of a typical nodule.
Databases Do Not Play WellWith OthersDatabases Systems are the colicky, nastychildren of the software world with bad tempersand leaky noses that stubbornly insist on theirway and will become disruptive at the mostinopportune time, ruining man-years of work inan instant before demanding more--Said by just about every software developer ever
So how do you gethappy MySQL Servers?This session for thosewho are not MySQLDBAs but are tasked totake care of MySQLInstances among othertasks. This will notmake you a DBA anymore than a 1 hoursession onprogramming will makeyou a programmer.
How does a Database server workClientSELECT phoneFROM friendsWHERE name = ‘Joe’;Server
How does a Database server workClientSELECT phoneFROM friendsWHERE name = ‘Joe’;ServerPARSEfind Joe in friendstable in memoryreturn phone
How does a Database server workClientSELECT phoneFROM friendsWHERE name = ‘Joe’;. . .Process phone dataServerPARSEfind Joe in friendstable in memoryreturn phone
How does a Database server workClientSELECT phoneFROM friendsWHERE name = ‘Joe’;. . .Process phone dataServerPARSEfind Joe in friendstable in memoryreturn phoneWhat was that aboutmemory???
Thing to do #1 – Lots of memory•Databases love data in memory
What if it is not in memory?MySQLPlease give me thedata from the citytableOS
What if it is not in memory?MySQLPlease give me thedata from the citytableOSGet inode
What if it is not in memory?MySQLPlease give me thedata from the citytableOSGet inodeAsk disk for data
What if it is not in memory?MySQLPlease give me thedata from the citytableOSGet inodeAsk disk for dataGet data into buffer
What if it is not in memory?MySQLPlease give me thedata from the citytableLoad data into memoryOSGet inodeAsk disk for dataGet data into bufferHand buffer off
What if it is not in memory?MySQLPlease give me thedata from the citytableLoad data into memoryOSGet inodeAsk disk for dataGet data into bufferHand buffer offMuch longer thanjust reading frommemory
Rule #2 – Use Proper HardwareDatabases have to do unpredictable queries,random I/O, and sequential scans so slow I/Okills performance
BuffersWhat happens when you read a file into memoryDISKDiskControllerPageCacheUserBuffer
Disk ReadsA disk read is 100,000 slower than reading memory●For comparison– 100,000 minutes is about 69.5 days– 100,000 feet is about 19 miles– 100,000 kilometers is 15.7 times aroundEarths equator
SSDUse standard RAID controller●SSD as writeback cache●Battery backed●$2.5/GB verses .075/GB●Very fast seek time●Density
Hardware recommendations1. Memory – lots of it, ecc2. DISKs – more spindles, high speed, fast controllers, RAID10, write back cache, and XFS/ZFS/ext4 not ext2/33. Write-through caches with battery backup units fordisks must be monitored, and have life span muchlonger than planned outages. Set learning cycles to offhours4. CPUs, Core less important (spend money on Memoryand IO)
Thing to do #3 –Understand Login/PrivsThe default MySQL Login and Privilege system is alittle … primitive.Be Stingy with privs as they are hard to get backSome tools may not give the privs you want – DROPPRIV is given by default by one popular admin tool
Quick Security Warning!MySQL login security is primitive.●Database mysql has users table●firstname.lastname@example.org or email@example.com.%– Matches host, then user, then password●Be explicit●Proxy and Pluggable logins in MySQL 5.6●firstname.lastname@example.org.% may not be the same email@example.com or firstname.lastname@example.orgMySQL privilege security●GRANT functions or access●Can get Byzantine quickly●Use a GUI
Thing to do #5 – MonitorYou need somethingmonitoring yourinstances as you need aquick way to checkstatus & record events– MySQL EnterpriseMonitor– MySQLWorkbench– Nagios, Cacti,phpMyAdmin, etc
Turn on logging1. Slow query log -- not all long running queriesare bad2. Log queries not using indexes3. READ the logs!!!4. Use monitoring software – MEM, Innotop,Cacti, Munin, Nagios, etc – and pay attentionto it
Just because you can not see all of the problemdoes not mean the problem is not there!
Things to do #6 – BackupsBackups are usually some sort of disk snap shotor serializing data to a fileThe more the better but you need to know stepsto recover dropped table, lost databases, ormangled data.Use data replication to a slave and then backupslave.Be paranoid!!!!!
Thing to do #7 -- ReplicationReplication for MySQL is the binary log for themaster being copied to a slave. The slavethen updates its copy of the dataTwo types:1. Asynchronous – server does not check changes sent toslave before proceeding2. Semi Synchronous – server checks that slave receivedchanges before proceeding
Replication – was messy!MySQL 5.6 is multi threaded and has GTIDs
Replication -- networkNetwork latency will affect MySQL replication. So plannetwork topology to minimize bandwidth competition withother systems/services.Slaves do not need to be as fast as the master but try tokeep things reasonably closeDo not have to replicate all tables/databases to all slaves.Cut down on traffic by replicating what is needed!
Writes & Reads Reads Reads• Write to one master• Read from many slaves, easily add more as needed• Perfect for read/write intensive appsApplicationMySQL ReplicationLoad BalancerMySQL DatabaseReplication Enables Scalability
Indexes are goodWithout IndexDB needs to scanentire table or tablescanWith IndexDB can go right torecord
Indexes, the bad•Overhead -- space, speed, maintenance (youcan have too many)•Not a panacea – does not cure all problems•Will not help if you need to perform a tablescan•Composite indexes can be tricky – YearMonthDayusually better than DayMonthYear
Thing to do #10 – TuningASet innodb_buffer_pool_size to 70-80% of memoryTurn off query cache
Where to get helpLots of Help Available●High Performance MySQL – Schwartz et al●MySQL Administrators Bible – Cabral●Effective MySQL series – Bradford●OurSQL podcast●Forums.MySQL.ComPlanet.MySQL.ComLocal MySQL User Group
MySQL Connect ConferenceMySQL Connect ConferenceSept 21st- 23rdinSan FranciscoThe Call for Proposals (CFP)for MySQL Connect 2013 justclosed. Conferenceattendees will hear the bestideas from MySQL expertsfrom around the globe:developers, visionaries,customers, partners. Bookhotel early do to AmericasCup races in San Francisco.
MySQL Marinate!Virtual self-study of MySQL through theBoston MySQL Users Group (http://www.meetup.com/mysqlbos/)http://www.meetup.com/Virtual-Tech-Self-Study/events/84103332/