3. Radiologists & Gorillas
83 Percent of Radiologists Didn’t Spot the Gorilla
Hiding in This CT Scan
– Picture of gorilla hidden in last slide of ten lung
scans.
– They wanted to see if the radiologists, focused on
the telltale nodules, would be blind to the easily
detectable and highly anomalous gorilla
– The gorilla was miniscule, but huge compared to
the nodules. It was about the size of a box of
matches-or 48 times the size of a typical nodule.
5. Databases Do Not Play Well
With Others
Databases Systems are the colicky, nasty
children of the software world with bad tempers
and leaky noses that stubbornly insist on their
way and will become disruptive at the most
inopportune time, ruining man-years of work in
an instant before demanding more
--Said by just about every software developer ever
6. So how do you get
happy MySQL Servers?
This session for those
who are not MySQL
DBAs but are tasked to
take care of MySQL
Instances among other
tasks. This will not
make you a DBA any
more than a 1 hour
session on
programming will make
you a programmer.
7. How does a Database server work
Client
SELECT phone
FROM friends
WHERE name = ‘Joe’;
Server
8. How does a Database server work
Client
SELECT phone
FROM friends
WHERE name = ‘Joe’;
Server
PARSE
find Joe in friends
table in memory
return phone
9. How does a Database server work
Client
SELECT phone
FROM friends
WHERE name = ‘Joe’;
. . .
Process phone data
Server
PARSE
find Joe in friends
table in memory
return phone
10. How does a Database server work
Client
SELECT phone
FROM friends
WHERE name = ‘Joe’;
. . .
Process phone data
Server
PARSE
find Joe in friends
table in memory
return phone
What was that about
memory???
11. Thing to do #1 – Lots of memory
•
Databases love data in memory
12. What if it is not in memory?
MySQL
Please give me the
data from the city
table
OS
13. What if it is not in memory?
MySQL
Please give me the
data from the city
table
OS
Get inode
14. What if it is not in memory?
MySQL
Please give me the
data from the city
table
OS
Get inode
Ask disk for data
15. What if it is not in memory?
MySQL
Please give me the
data from the city
table
OS
Get inode
Ask disk for data
Get data into buffer
16. What if it is not in memory?
MySQL
Please give me the
data from the city
table
Load data into memory
OS
Get inode
Ask disk for data
Get data into buffer
Hand buffer off
17. What if it is not in memory?
MySQL
Please give me the
data from the city
table
Load data into memory
OS
Get inode
Ask disk for data
Get data into buffer
Hand buffer off
Much longer than
just reading from
memory
18. Rule #2 – Use Proper Hardware
Databases have to do unpredictable queries,
random I/O, and sequential scans so slow I/O
kills performance
20. Buffers
Memory Lookup – 100 nanoseconds, 12GB/sec
DISK
Disk
Controller
Page
Cache
User
Buffer
21. Buffers
Memory Lookup – 100 nanoseconds, 12GB/sec
DISK seek – 10 milliseconds, 760MB/sec
DISK
Disk
Controller
Page
Cache
User
Buffer
22. Disk Reads
A 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 around
Earth's equator
23. SSD
Use standard RAID controller
●
SSD as writeback cache
●
Battery backed
●
$2.5/GB verses .075/GB
●
Very fast seek time
●
Density
24. Hardware recommendations
1. Memory – lots of it, ecc
2. DISKs – more spindles, high speed, fast controllers, RAID
10, write back cache, and XFS/ZFS/ext4 not ext2/3
3. Write-through caches with battery backup units for
disks must be monitored, and have life span much
longer than planned outages. Set 'learning cycles' to off
hours
4. CPUs, Core less important (spend money on Memory
and IO)
25. Thing to do #3 –
Understand Login/Privs
The default MySQL Login and Privilege system is a
little … primitive.
Be Stingy with privs as they are hard to get back
Some tools may not give the privs you want – DROP
PRIV is given by default by one popular admin tool
26. Quick Security Warning!
MySQL login security is primitive.
●
Database mysql has users table
●
'jsmith'@'co.com' or 'fred'@'10.10.%'
– Matches host, then user, then password
●
Be explicit
●
Proxy and Pluggable logins in MySQL 5.6
●
'joe'@'10.10.%' may not be the same as
'joe'@'yourco.com' or 'joe'@'home.net'
MySQL privilege security
●
GRANT functions or access
●
Can get Byzantine quickly
●
Use a GUI
28. Thing to do #4 – Use Current Release
Speed
– MySQL 5.5 is 20% faster than 5.1
– MySQL 5.6 is ~15% faster than 5.5
Features
– Better optimizer
– Sub-queries
– NoSQL/memcached
– Online DDL
30. Thing to do #5 – Monitor
You need 'something'
monitoring your
instances as you need a
quick way to check
status & record events
– MySQL Enterprise
Monitor
– MySQL
Workbench
– Nagios, Cacti,
phpMyAdmin, etc
31. Turn on logging
1. Slow query log -- not all long running queries
are bad
2. Log queries not using indexes
3. READ the logs!!!
4. Use monitoring software – MEM, Innotop,
Cacti, Munin, Nagios, etc – and pay attention
to it
32. Just because you can not see all of the problem
does not mean the problem is not there!
33. Things to do #6 – Backups
Backups are usually some sort of disk snap shot
or serializing data to a file
The more the better but you need to know steps
to recover dropped table, lost databases, or
mangled data.
Use data replication to a slave and then backup
slave.
Be paranoid!!!!!
34. Thing to do #7 -- Replication
Replication for MySQL is the binary log for the
master being copied to a slave. The slave
then updates its copy of the data
Two types:
1. Asynchronous – server does not check changes sent to
slave before proceeding
2. Semi Synchronous – server checks that slave received
changes before proceeding
37. Replication -- network
Network latency will affect MySQL replication. So plan
network topology to minimize bandwidth competition with
other systems/services.
Slaves do not need to be as fast as the master but try to
keep things reasonably close
Do not have to replicate all tables/databases to all slaves.
Cut down on traffic by replicating what is needed!
38. Writes & Reads Reads Reads
• Write to one master
• Read from many slaves, easily add more as needed
• Perfect for read/write intensive apps
Application
MySQL Replication
Load Balancer
MySQL Database
Replication Enables Scalability
47. Indexes are good
Without Index
DB needs to scan
entire table or table
scan
With Index
DB can go right to
record
48. Indexes, the bad
•
Overhead -- space, speed, maintenance (you
can have too many)
•
Not a panacea – does not cure all problems
•
Will not help if you need to perform a table
scan
•
Composite indexes can be tricky – YearMonthDay
usually better than DayMonthYear
50. Thing to do #10 – Tuning
ASet innodb_buffer_pool_size to 70-
80% of memory
Turn off query cache
51. Where to get help
Lots of Help Available
●
High Performance MySQL – Schwartz et al
●
MySQL Administrator's Bible – Cabral
●
Effective MySQL series – Bradford
●
OurSQL podcast
●
Forums.MySQL.Com
Planet.MySQL.Com
Local MySQL User Group
53. MySQL Connect ConferenceMySQL Connect Conference
Sept 21st
- 23rd
in
San Francisco
The Call for Proposals (CFP)
for MySQL Connect 2013 just
closed. Conference
attendees will hear the best
ideas from MySQL experts
from around the globe:
developers, visionaries,
customers, partners. Book
hotel early do to Americas
Cup races in San Francisco.
54. MySQL Marinate!
Virtual self-study of MySQL through the
Boston MySQL Users Group (
http://www.meetup.com/mysqlbos/)
http://www.meetup.com/Virtual-
Tech-Self-Study/events/84103332/