SlideShare a Scribd company logo
1 of 18
Download to read offline
www.fromdual.com
1 / 18
MySQL Performance Tuning
für Entwickler
Cebit 2015, Hannover
Oli Sennhauser
Senior MySQL Consultant, FromDual GmbH
oli.sennhauser@fromdual.com
www.fromdual.com
2 / 18
FromDual GmbH
Support
remote-DBA
Schulung
Beratung
www.fromdual.com
3 / 18
Datenbank Performance
Über was reden wir eigentlich genau?
● Durchsatz (throughput)
● z. B. Business-Transaktionen pro Minute
● Antwortzeit (Latenz, response time)
● z.B. Business-Transaktion dauert 7.2 Sekunden im Schnitt
Über was redet Marketing?
● Durchsatz, Skalierbarkeit von DB-Queries
Gap!
● 95% der Nutzer haben ein Latenz-Problem
● 5% ein Durchsatz/Skalierungs-Problem
www.fromdual.com
4 / 18
Durchsatz nimmt zu
www.fromdual.com
5 / 18
Antwortzeit nimmt zu!
www.fromdual.com
6 / 18
Wo ist meine Zeit geblieben?
● Antwortzeit meiner Business-Transaktion
● d. h. Zeit messen!!!
● Applikation mit „Probes“ versehen
● Profiler (PHP (XDebug), Java (Jprofiler), ...)
● Profil erstellen:
function x() {
  start = current_time();
  count[x]++;
  …
  end = current_time();
  duration[x] += (end ­ start);
}
function   count   time
x            123     156.25     0.8%
y             19     827.30     4.1%
z              2   19280.00    95.1%
Total        144   20263.55   100.0%
time
a
b
c
d
e
f
g h j
i
www.fromdual.com
7 / 18
End-to-End Profile
● Idealfall: End-to-End Profile:
● Round-Trip pro Business-Transaktion
Web-Client
Network
Web-Server
Application
DB
Network
Fat-Client
Connector
…%
…%
…%
…%
…%
…%
Menge der Daten?
Anzahl Round-Trips?
Queries pro B-trx?
NW-Latenz?
www.fromdual.com
8 / 18
General Query Log
● Alle Queries werden gelogged:
● Gut bei:
● Frameworks
● Fremdapplikationen
● Beispiel:
● CMS: 1 Änderung (30 s)
● → 30'000 Queries in der DB (ca. 1 ms/Query)
+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­+
| Variable_name    | Value       |
+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­+
| general_log      | OFF         |
| general_log_file | general.log |
+­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­+
www.fromdual.com
9 / 18
Ist die Datenbank schuld?
● Angenommen die Business-Trx verbringt viel
Zeit in der DB:
● Dann ist NICHT zwingend die DB schuld!
● SISO Prinzip?
● 1 Connection = 1 Query = 1 Thread = 1 Core
● Heute: Viel Memory, SSD
→ Oft ist/wird wieder die CPU der Flaschenhals
● Wie gucken?
vmstat, top, iostat
www.fromdual.com
10 / 18
Performance-Waage
● Wo ansetzen?
● HW, OS, DB Konfiguration, Applikation
Architektur und Design
● Typischerweise NICHT DB-Konfiguration
● (Defaults sind besser geworden!)
● DB Konfiguration: 9 Variablen, dann ist gut!
www.fromdual.com
11 / 18
Des Admins Bazooka
● Wenig Reaktionszeit:
● SHOW [FULL] PROCESSLIST;
● System entspannen:
● KILL [CONNECTION | QUERY] id;
mysql> SHOW PROCESSLIST;
+­­­­­+­­­­­­­+­­­­­­+­­­­­­­­­+­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| Id  | User  | db   | Command | Time | State        | Info                                            |
+­­­­­+­­­­­­­+­­­­­­+­­­­­­­­­+­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
| 146 | live  | live | Query   |  710 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... |
| 240 | live  | live | Query   |  467 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... |
| 272 | live  | live | Query   |  275 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... |
| 323 | live  | live | Query   |   79 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... |
| 374 | admin | NULL | Query   |    0 | NULL         | SHOW PROCESSLIST                                |
+­­­­­+­­­­­­­+­­­­­­+­­­­­­­­­+­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+
mysql> KILL CONNECTION 146
www.fromdual.com
12 / 18
Slow Query Log
● Etwas systematischer:
● Slow Query Log
● Auswerten:
● mysqldumpslow ­s t slow.log > profile
+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+
| Variable_name                          | Value    |
+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+
| log_queries_not_using_indexes          | ON       |
| long_query_time                        | 0.500000 |
| slow_query_log                         | OFF      |
| slow_query_log_file                    | slow.log |
| min_examined_row_limit                 | 100      |
+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+
www.fromdual.com
13 / 18
Graphisch: Query Analyzer
www.fromdual.com
14 / 18
Harte Arbeit
● Sammeln und Schauen (Slow Query Log)
● Verstehen (Query Execution Plan (QEP))
● EXPLAIN SELECT COUNT(*) FROM ...
● Denken
● Wo lege ich den Index an...
● Tipp 5.7: EXPLAIN anderer Connection:
EXPLAIN FOR CONNECTION connection_id;
www.fromdual.com
15 / 18
Query Execution Plan (QEP)
EXPLAIN
SELECT domain
  FROM newsite_domain AS nd
  JOIN newsite_main AS nm ON nd.id = nm.id 
 WHERE nm.gbot_indexer = '62'
   AND (nm.state=2 OR nm.state=3 OR nm.state=9)
;
+­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­+
| table | type   | possible_keys      | key        | ref          | rows   | Extra       |
+­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­+
| nm    | range  | PRIMARY,site_state | site_state | NULL         | 150298 | Using where |
| nd    | eq_ref | PRIMARY            | PRIMARY    | jobads.nm.id |      1 |             |
+­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­+
CREATE TABLE `newsite_main` (
  ...
  PRIMARY KEY  (`id`),
  KEY `site_state` (`state`)
);
 
www.fromdual.com
16 / 18
Indexieren
● Der Schlüssel zur besseren Query Performance
sind Indices
● Wo setzen wir Indices:
● Jede Tabelle hat einen Primary Key!
● Dort wo gejoined wird
● Wo gute Filter vorhanden sind (WHERE a = ...)
● Spezialfälle
● Covering Index
● Index zu ORDER BY Optimierung
● PK zur Verbesserung der Lokalität der Daten
www.fromdual.com
17 / 18
Wir suchen noch:
MySQL Datenbank Enthusiast/in für
Support / remote-DBA / Beratung
www.fromdual.com
18 / 18
Q & A
Fragen ?
Diskussion?
Wir haben Zeit für ein persönliches Gespräch...
● FromDual bietet neutral und unabhängig:
● Beratung
● Remote-DBA
● Support für MySQL, Galera, Percona Server und MariaDB
● Schulung
www.fromdual.com/presentations

More Related Content

What's hot

DOAG 2011: MySQL Replication
DOAG 2011: MySQL ReplicationDOAG 2011: MySQL Replication
DOAG 2011: MySQL Replication
FromDual GmbH
 
DOAG 2011: MySQL Performance Tuning
DOAG 2011: MySQL Performance TuningDOAG 2011: MySQL Performance Tuning
DOAG 2011: MySQL Performance Tuning
FromDual GmbH
 
MySQL Replication for Beginners
MySQL Replication for BeginnersMySQL Replication for Beginners
MySQL Replication for Beginners
FromDual GmbH
 
Internet Briefing 2011: NoSQL with MySQL
Internet Briefing 2011: NoSQL with MySQLInternet Briefing 2011: NoSQL with MySQL
Internet Briefing 2011: NoSQL with MySQL
FromDual GmbH
 
FROSCON 2011: MySQL Performance Tuning
FROSCON 2011: MySQL Performance TuningFROSCON 2011: MySQL Performance Tuning
FROSCON 2011: MySQL Performance Tuning
FromDual GmbH
 
FROSCON 2011: MySQL Replication
FROSCON 2011: MySQL ReplicationFROSCON 2011: MySQL Replication
FROSCON 2011: MySQL Replication
FromDual GmbH
 
DOAG 2010: MySQL Architekturen für Oracle DBA's
DOAG 2010: MySQL Architekturen für Oracle DBA'sDOAG 2010: MySQL Architekturen für Oracle DBA's
DOAG 2010: MySQL Architekturen für Oracle DBA's
FromDual GmbH
 
DAOG SIG: HA Architekturen mit MySQL
DAOG SIG: HA Architekturen mit MySQLDAOG SIG: HA Architekturen mit MySQL
DAOG SIG: HA Architekturen mit MySQL
FromDual GmbH
 
DOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, Backup
DOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, BackupDOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, Backup
DOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, Backup
FromDual GmbH
 

What's hot (20)

Der Datenbank-Backup ist gemacht - was nun?
Der Datenbank-Backup ist gemacht - was nun?Der Datenbank-Backup ist gemacht - was nun?
Der Datenbank-Backup ist gemacht - was nun?
 
MySQL Cluster with Galera Cluster for MySQL
MySQL Cluster with Galera Cluster for MySQLMySQL Cluster with Galera Cluster for MySQL
MySQL Cluster with Galera Cluster for MySQL
 
MySQL-Server im Teamwork - Replikation und Cluster
MySQL-Server im Teamwork - Replikation und ClusterMySQL-Server im Teamwork - Replikation und Cluster
MySQL-Server im Teamwork - Replikation und Cluster
 
DOAG 2011: MySQL Replication
DOAG 2011: MySQL ReplicationDOAG 2011: MySQL Replication
DOAG 2011: MySQL Replication
 
DOAG 2011: MySQL Performance Tuning
DOAG 2011: MySQL Performance TuningDOAG 2011: MySQL Performance Tuning
DOAG 2011: MySQL Performance Tuning
 
MySQL Replication for Beginners
MySQL Replication for BeginnersMySQL Replication for Beginners
MySQL Replication for Beginners
 
Internet Briefing 2011: NoSQL with MySQL
Internet Briefing 2011: NoSQL with MySQLInternet Briefing 2011: NoSQL with MySQL
Internet Briefing 2011: NoSQL with MySQL
 
FROSCON 2011: MySQL Performance Tuning
FROSCON 2011: MySQL Performance TuningFROSCON 2011: MySQL Performance Tuning
FROSCON 2011: MySQL Performance Tuning
 
FROSCON 2011: MySQL Replication
FROSCON 2011: MySQL ReplicationFROSCON 2011: MySQL Replication
FROSCON 2011: MySQL Replication
 
DOAG 2010: MySQL Architekturen für Oracle DBA's
DOAG 2010: MySQL Architekturen für Oracle DBA'sDOAG 2010: MySQL Architekturen für Oracle DBA's
DOAG 2010: MySQL Architekturen für Oracle DBA's
 
DAOG SIG: HA Architekturen mit MySQL
DAOG SIG: HA Architekturen mit MySQLDAOG SIG: HA Architekturen mit MySQL
DAOG SIG: HA Architekturen mit MySQL
 
MySQL HA and Security
MySQL HA and SecurityMySQL HA and Security
MySQL HA and Security
 
DOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, Backup
DOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, BackupDOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, Backup
DOAG SIG: MySQL Replikation, Scale-Out, Master- Master Replikation, Backup
 
MySQL Hochverfügbarkeitslösungen
MySQL HochverfügbarkeitslösungenMySQL Hochverfügbarkeitslösungen
MySQL Hochverfügbarkeitslösungen
 
Ausgewählte Performance Technologien
Ausgewählte Performance TechnologienAusgewählte Performance Technologien
Ausgewählte Performance Technologien
 
Ausgewählte PL/SQL Packages (1)
Ausgewählte PL/SQL Packages (1)Ausgewählte PL/SQL Packages (1)
Ausgewählte PL/SQL Packages (1)
 
Exadata with VM as Consolidation Plattform
Exadata with VM as Consolidation PlattformExadata with VM as Consolidation Plattform
Exadata with VM as Consolidation Plattform
 
LinuxTag 2008 - Virtuelle Cold-Standby Server mit Linux
LinuxTag 2008 - Virtuelle Cold-Standby Server mit LinuxLinuxTag 2008 - Virtuelle Cold-Standby Server mit Linux
LinuxTag 2008 - Virtuelle Cold-Standby Server mit Linux
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
Komprimierung in der Oracle Datenbank (Stand 11gR2, 12c)
 

Viewers also liked

MySQL Server Settings Tuning
MySQL Server Settings TuningMySQL Server Settings Tuning
MySQL Server Settings Tuning
guest5ca94b
 
MySQL Performance Tuning
MySQL Performance TuningMySQL Performance Tuning
MySQL Performance Tuning
FromDual GmbH
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
webhostingguy
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
MYXPLAIN
 

Viewers also liked (19)

MySQL Server Settings Tuning
MySQL Server Settings TuningMySQL Server Settings Tuning
MySQL Server Settings Tuning
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
MySQL Performance Tuning Variables
MySQL Performance Tuning VariablesMySQL Performance Tuning Variables
MySQL Performance Tuning Variables
 
MySQL Performance Tuning
MySQL Performance TuningMySQL Performance Tuning
MySQL Performance Tuning
 
Performance Tuning Best Practices
Performance Tuning Best PracticesPerformance Tuning Best Practices
Performance Tuning Best Practices
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQL
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
 
MySQL查询优化浅析
MySQL查询优化浅析MySQL查询优化浅析
MySQL查询优化浅析
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuning
 

Similar to MySQL Performance Tuning für Entwickler

AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?
AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?
AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?
panagenda
 
Best Practices SharePoint and SQL Installation
Best Practices SharePoint and SQL InstallationBest Practices SharePoint and SQL Installation
Best Practices SharePoint and SQL Installation
Samuel Zürcher
 
Forms and Reports 12c - Processes and Automation in Development and Operations
Forms and Reports 12c - Processes and Automation in Development and OperationsForms and Reports 12c - Processes and Automation in Development and Operations
Forms and Reports 12c - Processes and Automation in Development and Operations
Torsten Kleiber
 

Similar to MySQL Performance Tuning für Entwickler (20)

Optimizing SQL Server 2012 Deep dive for SharePoint 2013 Lars Platzdasch SQL ...
Optimizing SQL Server 2012 Deep dive for SharePoint 2013 Lars Platzdasch SQL ...Optimizing SQL Server 2012 Deep dive for SharePoint 2013 Lars Platzdasch SQL ...
Optimizing SQL Server 2012 Deep dive for SharePoint 2013 Lars Platzdasch SQL ...
 
Kritische app performance erfolgreich optimieren mit Bison
Kritische app performance erfolgreich optimieren mit BisonKritische app performance erfolgreich optimieren mit Bison
Kritische app performance erfolgreich optimieren mit Bison
 
AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?
AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?
AdminCamp 2014: Quo Vadis – Wohin mit IBM Notes/Domino?
 
Presentation bp7 - citrix xen desktop
Presentation   bp7 - citrix xen desktopPresentation   bp7 - citrix xen desktop
Presentation bp7 - citrix xen desktop
 
AdminCamp 2011 Performance
AdminCamp 2011 PerformanceAdminCamp 2011 Performance
AdminCamp 2011 Performance
 
Best Practices SharePoint and SQL Installation
Best Practices SharePoint and SQL InstallationBest Practices SharePoint and SQL Installation
Best Practices SharePoint and SQL Installation
 
Überblick: 18c und Autonomous Data Warehouse Cloud (ADWC)
Überblick: 18c und Autonomous Data Warehouse Cloud (ADWC)Überblick: 18c und Autonomous Data Warehouse Cloud (ADWC)
Überblick: 18c und Autonomous Data Warehouse Cloud (ADWC)
 
Sql Server GrundlagenfüR Share Point Admins
Sql Server GrundlagenfüR Share Point AdminsSql Server GrundlagenfüR Share Point Admins
Sql Server GrundlagenfüR Share Point Admins
 
Sql Server Grundlagen für Sharepoint Administratoren
Sql Server Grundlagen für Sharepoint AdministratorenSql Server Grundlagen für Sharepoint Administratoren
Sql Server Grundlagen für Sharepoint Administratoren
 
Warum Monitoring und warum Icinga 2 (Webinar vom 04.12.2013)
Warum Monitoring und warum Icinga 2 (Webinar vom 04.12.2013)Warum Monitoring und warum Icinga 2 (Webinar vom 04.12.2013)
Warum Monitoring und warum Icinga 2 (Webinar vom 04.12.2013)
 
Zurück in die Zukunft - DNUG 2014 - Track 5.2
Zurück in die Zukunft - DNUG 2014 - Track 5.2Zurück in die Zukunft - DNUG 2014 - Track 5.2
Zurück in die Zukunft - DNUG 2014 - Track 5.2
 
Schlanke Maschinendatenerfassung für produzierende Unternehmen
Schlanke Maschinendatenerfassung für produzierende UnternehmenSchlanke Maschinendatenerfassung für produzierende Unternehmen
Schlanke Maschinendatenerfassung für produzierende Unternehmen
 
Forms and Reports 12c - Processes and Automation in Development and Operations
Forms and Reports 12c - Processes and Automation in Development and OperationsForms and Reports 12c - Processes and Automation in Development and Operations
Forms and Reports 12c - Processes and Automation in Development and Operations
 
Meet Magento - High performance magento
Meet Magento - High performance magentoMeet Magento - High performance magento
Meet Magento - High performance magento
 
Datenbank-Hausputz für Einsteiger
Datenbank-Hausputz für EinsteigerDatenbank-Hausputz für Einsteiger
Datenbank-Hausputz für Einsteiger
 
SQL Server 2016 and SharePoint 2016 - Lars PLatzdasch - SQL Konferenz 2016
SQL Server 2016 and SharePoint 2016  - Lars PLatzdasch - SQL Konferenz 2016SQL Server 2016 and SharePoint 2016  - Lars PLatzdasch - SQL Konferenz 2016
SQL Server 2016 and SharePoint 2016 - Lars PLatzdasch - SQL Konferenz 2016
 
Webinar - SAP Gateway
Webinar  - SAP GatewayWebinar  - SAP Gateway
Webinar - SAP Gateway
 
bccon-2014 adm01 tipps-und-skripts-aus-dem-leben-eines-ibm-connections-admins
bccon-2014 adm01 tipps-und-skripts-aus-dem-leben-eines-ibm-connections-adminsbccon-2014 adm01 tipps-und-skripts-aus-dem-leben-eines-ibm-connections-admins
bccon-2014 adm01 tipps-und-skripts-aus-dem-leben-eines-ibm-connections-admins
 
Tipps und Skripts aus dem Leben eines Connections Admins
Tipps und Skripts aus dem Leben eines Connections AdminsTipps und Skripts aus dem Leben eines Connections Admins
Tipps und Skripts aus dem Leben eines Connections Admins
 
Oracle12c threaded execution - Ressourcen sparen zum Nulltarif?!?
Oracle12c threaded execution - Ressourcen sparen zum Nulltarif?!?Oracle12c threaded execution - Ressourcen sparen zum Nulltarif?!?
Oracle12c threaded execution - Ressourcen sparen zum Nulltarif?!?
 

More from FromDual GmbH

More from FromDual GmbH (18)

MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...
 
MariaDB / MySQL tripping hazard and how to get out again?
MariaDB / MySQL tripping hazard and how to get out again?MariaDB / MySQL tripping hazard and how to get out again?
MariaDB / MySQL tripping hazard and how to get out again?
 
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration WorkshopPXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
 
IT Tage 2019 MariaDB 10.4 New Features
IT Tage 2019 MariaDB 10.4 New FeaturesIT Tage 2019 MariaDB 10.4 New Features
IT Tage 2019 MariaDB 10.4 New Features
 
MariaDB 10.4 New Features
MariaDB 10.4 New FeaturesMariaDB 10.4 New Features
MariaDB 10.4 New Features
 
MariaDB 10.2 New Features
MariaDB 10.2 New FeaturesMariaDB 10.2 New Features
MariaDB 10.2 New Features
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
 
MySQL Security SLAC 2015
MySQL Security SLAC 2015MySQL Security SLAC 2015
MySQL Security SLAC 2015
 
MySQL Replikation - Die Eier legende Wollmilchsau?
MySQL Replikation - Die Eier legende Wollmilchsau?MySQL Replikation - Die Eier legende Wollmilchsau?
MySQL Replikation - Die Eier legende Wollmilchsau?
 
Reading MySQL fingerprints
Reading MySQL fingerprintsReading MySQL fingerprints
Reading MySQL fingerprints
 
High-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLHigh-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQL
 
MySQL always-up with Galera Cluster
MySQL always-up with Galera ClusterMySQL always-up with Galera Cluster
MySQL always-up with Galera Cluster
 
HA with Galera
HA with GaleraHA with Galera
HA with Galera
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
 
Need for Speed: Mysql indexing
Need for Speed: Mysql indexingNeed for Speed: Mysql indexing
Need for Speed: Mysql indexing
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
MySQL High Availability Solutions
MySQL High Availability SolutionsMySQL High Availability Solutions
MySQL High Availability Solutions
 
MySQL Security
MySQL SecurityMySQL Security
MySQL Security
 

MySQL Performance Tuning für Entwickler

  • 1. www.fromdual.com 1 / 18 MySQL Performance Tuning für Entwickler Cebit 2015, Hannover Oli Sennhauser Senior MySQL Consultant, FromDual GmbH oli.sennhauser@fromdual.com
  • 2. www.fromdual.com 2 / 18 FromDual GmbH Support remote-DBA Schulung Beratung
  • 3. www.fromdual.com 3 / 18 Datenbank Performance Über was reden wir eigentlich genau? ● Durchsatz (throughput) ● z. B. Business-Transaktionen pro Minute ● Antwortzeit (Latenz, response time) ● z.B. Business-Transaktion dauert 7.2 Sekunden im Schnitt Über was redet Marketing? ● Durchsatz, Skalierbarkeit von DB-Queries Gap! ● 95% der Nutzer haben ein Latenz-Problem ● 5% ein Durchsatz/Skalierungs-Problem
  • 6. www.fromdual.com 6 / 18 Wo ist meine Zeit geblieben? ● Antwortzeit meiner Business-Transaktion ● d. h. Zeit messen!!! ● Applikation mit „Probes“ versehen ● Profiler (PHP (XDebug), Java (Jprofiler), ...) ● Profil erstellen: function x() {   start = current_time();   count[x]++;   …   end = current_time();   duration[x] += (end ­ start); } function   count   time x            123     156.25     0.8% y             19     827.30     4.1% z              2   19280.00    95.1% Total        144   20263.55   100.0% time a b c d e f g h j i
  • 7. www.fromdual.com 7 / 18 End-to-End Profile ● Idealfall: End-to-End Profile: ● Round-Trip pro Business-Transaktion Web-Client Network Web-Server Application DB Network Fat-Client Connector …% …% …% …% …% …% Menge der Daten? Anzahl Round-Trips? Queries pro B-trx? NW-Latenz?
  • 8. www.fromdual.com 8 / 18 General Query Log ● Alle Queries werden gelogged: ● Gut bei: ● Frameworks ● Fremdapplikationen ● Beispiel: ● CMS: 1 Änderung (30 s) ● → 30'000 Queries in der DB (ca. 1 ms/Query) +­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­+ | Variable_name    | Value       | +­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­+ | general_log      | OFF         | | general_log_file | general.log | +­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­­+
  • 9. www.fromdual.com 9 / 18 Ist die Datenbank schuld? ● Angenommen die Business-Trx verbringt viel Zeit in der DB: ● Dann ist NICHT zwingend die DB schuld! ● SISO Prinzip? ● 1 Connection = 1 Query = 1 Thread = 1 Core ● Heute: Viel Memory, SSD → Oft ist/wird wieder die CPU der Flaschenhals ● Wie gucken? vmstat, top, iostat
  • 10. www.fromdual.com 10 / 18 Performance-Waage ● Wo ansetzen? ● HW, OS, DB Konfiguration, Applikation Architektur und Design ● Typischerweise NICHT DB-Konfiguration ● (Defaults sind besser geworden!) ● DB Konfiguration: 9 Variablen, dann ist gut!
  • 11. www.fromdual.com 11 / 18 Des Admins Bazooka ● Wenig Reaktionszeit: ● SHOW [FULL] PROCESSLIST; ● System entspannen: ● KILL [CONNECTION | QUERY] id; mysql> SHOW PROCESSLIST; +­­­­­+­­­­­­­+­­­­­­+­­­­­­­­­+­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | Id  | User  | db   | Command | Time | State        | Info                                            | +­­­­­+­­­­­­­+­­­­­­+­­­­­­­­­+­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ | 146 | live  | live | Query   |  710 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... | | 240 | live  | live | Query   |  467 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... | | 272 | live  | live | Query   |  275 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... | | 323 | live  | live | Query   |   79 | Sending data | SELECT COUNT(*) FROM (SELECT DISTINCT(nid), ... | | 374 | admin | NULL | Query   |    0 | NULL         | SHOW PROCESSLIST                                | +­­­­­+­­­­­­­+­­­­­­+­­­­­­­­­+­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+ mysql> KILL CONNECTION 146
  • 12. www.fromdual.com 12 / 18 Slow Query Log ● Etwas systematischer: ● Slow Query Log ● Auswerten: ● mysqldumpslow ­s t slow.log > profile +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+ | Variable_name                          | Value    | +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+ | log_queries_not_using_indexes          | ON       | | long_query_time                        | 0.500000 | | slow_query_log                         | OFF      | | slow_query_log_file                    | slow.log | | min_examined_row_limit                 | 100      | +­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­+
  • 14. www.fromdual.com 14 / 18 Harte Arbeit ● Sammeln und Schauen (Slow Query Log) ● Verstehen (Query Execution Plan (QEP)) ● EXPLAIN SELECT COUNT(*) FROM ... ● Denken ● Wo lege ich den Index an... ● Tipp 5.7: EXPLAIN anderer Connection: EXPLAIN FOR CONNECTION connection_id;
  • 15. www.fromdual.com 15 / 18 Query Execution Plan (QEP) EXPLAIN SELECT domain   FROM newsite_domain AS nd   JOIN newsite_main AS nm ON nd.id = nm.id   WHERE nm.gbot_indexer = '62'    AND (nm.state=2 OR nm.state=3 OR nm.state=9) ; +­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­+ | table | type   | possible_keys      | key        | ref          | rows   | Extra       | +­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­+ | nm    | range  | PRIMARY,site_state | site_state | NULL         | 150298 | Using where | | nd    | eq_ref | PRIMARY            | PRIMARY    | jobads.nm.id |      1 |             | +­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­­­­­­­­+­­­­­­­­­­­­+­­­­­­­­­­­­­­+­­­­­­­­+­­­­­­­­­­­­­+ CREATE TABLE `newsite_main` (   ...   PRIMARY KEY  (`id`),   KEY `site_state` (`state`) );  
  • 16. www.fromdual.com 16 / 18 Indexieren ● Der Schlüssel zur besseren Query Performance sind Indices ● Wo setzen wir Indices: ● Jede Tabelle hat einen Primary Key! ● Dort wo gejoined wird ● Wo gute Filter vorhanden sind (WHERE a = ...) ● Spezialfälle ● Covering Index ● Index zu ORDER BY Optimierung ● PK zur Verbesserung der Lokalität der Daten
  • 17. www.fromdual.com 17 / 18 Wir suchen noch: MySQL Datenbank Enthusiast/in für Support / remote-DBA / Beratung
  • 18. www.fromdual.com 18 / 18 Q & A Fragen ? Diskussion? Wir haben Zeit für ein persönliches Gespräch... ● FromDual bietet neutral und unabhängig: ● Beratung ● Remote-DBA ● Support für MySQL, Galera, Percona Server und MariaDB ● Schulung www.fromdual.com/presentations