(Go: >> BACK << -|- >> HOME <<)

SlideShare a Scribd company logo
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Instrumenting Plugins for
Performance Schema
Mark Leith
Senior Software Development Manager
MySQL Enterprise Tools, Oracle
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
Yea but “Why?”
The Interfaces
An example
Questions
1
2
3
4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Yea but “Why?”
• There’s a bunch of great interfaces in to the MySQL Server now,
from the well known storage engines, through pre/post parser
plugins, auditing, full text search, INFORMATION_SCHEMA tables,
UDFs, replication interfaces, and more..
• We’ve made great strides in instrumenting the core server, but if
you want to use plugins, and don’t also add to the instrumentation
in the new standard ways, this will cause new black holes in your
available performance data
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Performance Schema
Event Horizon
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Interfaces
• The main interface is within ./include/mysql/psi/
• The ABI is maintained via ./include/mysql/psi/psi.h
• Great Doxygen based docs here:
• https://dev.mysql.com/doc/dev/mysql-server/8.0.0/PAGE_PFS_PSI.html
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
The Interfaces
• The API is broken down by the type of instrumentation
• Threads, sync points (mutexes, rwlocks, conditions etc.) in
include/mysql/psi/mysql_thread.h
• File IO in include/mysql/psi/mysql_file.h
• Memory in include/mysql/psi/mysql_memory.h
• Network IO in include/mysql/psi/mysql_socket.h
• These all use the underlying versioned performance schema
interfaces via the psi.h ABI
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
An Example
• Let us dream of an audit plugin
• It will:
• Log statements that cause errors to a file
• Track some error stats with some global status variables
• That requires:
• Some file operations
• A mutex to protect concurrent access to the variables and file
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
pthread_mutex_t LOCK_client_error;
static int client_error_plugin_init(…)
{
pthread_mutex_init(&LOCK_client_error, NULL);
…
}
8
An Example - Mutex init
mysql_mutex_t LOCK_client_error;
PSI_mutex_key key_LOCK_client_error;
static PSI_mutex_info client_error_mutexes[]=
{
{ &key_LOCK_client_error,
"LOCK_client_error", PSI_FLAG_GLOBAL }
};
static int client_error_plugin_init(…)
{
const char* category= "client_error";
int count;
count= array_elements(client_error_mutexes);
mysql_mutex_register(category,
client_error_mutexes, count);
mysql_mutex_init(key_LOCK_client_error,
&LOCK_client_error, MY_MUTEX_INIT_FAST);
…
}
P_S
Instrument Info
Register
within P_S
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
FILE *fp;
static int client_error_plugin_init(…)
{
if(!(fp = fopen(“client_errors.log”, “a+”)))
return true;
…
}
9
An Example - File init
PSI_file_key key_file_client_error_log;
static PSI_file_info client_error_files[]=
{
{ &key_file_client_error_log,
"client_error_log", 0}
};
static int client_error_plugin_init(…)
{
…
count= array_elements(client_error_files);
mysql_file_register(category, client_error_files, count);
…
if (!(client_error_log=
mysql_file_create(key_file_client_error_log,
“client_errors.log”, 0,
O_WRONLY | O_APPEND,
MYF(MY_WME))))
}
See
my_sys.h,
in this case, write
message on
error
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
static int client_error_notify(…)
{
…
if (error_event->event_subclass ==
MYSQL_AUDIT_GENERAL_ERROR)
{
pthread_mutex_lock(&LOCK_client_error);
…
/* Increment some counters */
/* Create some log line buffer in buff */
…
write(fp, (uchar*) buff, len);
pthread_mutex_unlock(&LOCK_client_error);
}
}
10
An Example - Writing to the file
static int client_error_notify(…)
{
…
if (error_event->event_subclass ==
MYSQL_AUDIT_GENERAL_ERROR)
{
mysql_mutex_lock(&LOCK_client_error);
…
/* Increment some counters */
/* Create some log line buffer in buff */
…
mysql_file_write(client_error_log,
(uchar*) buff, len, MYF_RW);
mysql_mutex_unlock(&LOCK_client_error);
}
}
Write message on
error, or if not all
bytes are
processed
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
An Example - Adding Stages
• Now you know where you may be waiting for thread synchronisation
or file IO (or network IO, I won’t talk about that here, look at the
API if you’re doing some Daemon plugin)
• You can track more major sections of code with Stages - the thread
states that exposed via process lists and profiling interfaces
• API is within include/mysql/psi/mysql_stage.h
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
PSI_stage_info opening_client_error_log_file=
{ 0, "Opening client error log file", 0 };
PSI_stage_info recording_error_statistics=
{ 0, "Recording error statistics", 0 };
PSI_stage_info *client_error_stages[]=
{
&opening_client_error_log_file,
&recording_error_statistics
};
12
An Example - Stages
static int client_error_log_open()
{
mysql_set_stage(opening_client_error_log_file.m_key);
mysql_mutex_lock(&LOCK_client_error_log);
/* Open the file, maybe write some header */
return 0;
}
static int client_error_notify(…)
{
…
if (error_event->event_subclass ==
MYSQL_AUDIT_GENERAL_ERROR)
{
mysql_set_stage(recording_error_statistics.m_key);
/* Update stats, write log file etc. */
}
return 0;
}
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
An Example - Adding Stages
• Note that when adding stages, you are hijacking the current stage
• Think about where in the flow your stage can be added
• Consider adding a “continuation” stage
• This can show code executed after your plugin (or face the blame
game)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
An Example - Stage Progress
• You can also track progress of stages within 5.7+
• Call mysql_set_stage(…)
• Then mysql_stage_set_work_estimated(<stage>, <estimate count>)
• Then while doing the estimated work, at the right interval:
• mysql_stage_set_work_completed(<stage>, <completed count>);
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
An Example - Performance Schema Output
15
( SELECT thread_id, nesting_event_id, event_id, event_name, sys.format_time(timer_wait) AS time
FROM performance_schema.events_stages_history_long ORDER BY event_id )
UNION ALL
( SELECT thread_id, nesting_event_id, event_id, concat('-> ', event_name), sys.format_time(timer_wait) AS time
FROM performance_schema.events_waits_history_long WHERE event_name != 'idle' ORDER BY event_id )
ORDER BY thread_id, event_id;
+-----------+------------------+----------+--------------------------------------------------------+-----------+
| thread_id | nesting_event_id | event_id | event_name | time |
+-----------+------------------+----------+--------------------------------------------------------+-----------+
| 24 | 427 | 428 | stage/sql/starting | 120.46 us |
…
| 24 | 428 | 437 | -> wait/synch/rwlock/sql/LOCK_grant | 437.32 ns |
| 24 | 427 | 438 | stage/sql/Opening tables | 28.21 us |
| 24 | 427 | 440 | stage/client_error/Recording error statistics | 23.14 us |
| 24 | 440 | 441 | -> wait/synch/mutex/client_error/LOCK_client_error_log | 203.58 ns |
| 24 | 440 | 442 | -> wait/io/file/client_error/client_error_log | 11.25 us |
| 24 | 427 | 443 | stage/sql/query end | 3.52 us |
| 24 | 443 | 444 | -> wait/synch/mutex/sql/THD::LOCK_query_plan | 158.34 ns |
| 24 | 427 | 445 | stage/sql/closing tables | 1.68 us |
| 24 | 427 | 446 | stage/sql/freeing items | 50.63 us |
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Question and feedback time!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The preceding is intended to outline our general product direction. It is
intended for information purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any material, code, or functionality,
and should not be relied upon in making purchasing decisions. The development,
release, and timing of any features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
Instrumenting plugins for Performance Schema

More Related Content

What's hot

Developing Information Schema Plugins
Developing Information Schema PluginsDeveloping Information Schema Plugins
Developing Information Schema Plugins
Mark Leith
 
Introduction to MySQL Enterprise Monitor
Introduction to MySQL Enterprise MonitorIntroduction to MySQL Enterprise Monitor
Introduction to MySQL Enterprise Monitor
Mark Leith
 
MySQL Monitoring Mechanisms
MySQL Monitoring MechanismsMySQL Monitoring Mechanisms
MySQL Monitoring Mechanisms
Mark Leith
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
Mark Leith
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS Schema
Mark Leith
 
MySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench IntegrationMySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench Integration
Mario Beck
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
Mark Leith
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
Mark Leith
 
What's next after Upgrade to 12c
What's next after Upgrade to 12cWhat's next after Upgrade to 12c
What's next after Upgrade to 12c
Guatemala User Group
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasia
Mayank Prasad
 
MySQL Monitoring 101
MySQL Monitoring 101MySQL Monitoring 101
MySQL Monitoring 101
Ronald Bradford
 
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
Oracle Database 12c  New Features for Developers and DBAs - OTN TOUR LA 2015Oracle Database 12c  New Features for Developers and DBAs - OTN TOUR LA 2015
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
Alex Zaballa
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAs
Sveta Smirnova
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise Monitor
Mario Beck
 
Double the Performance of Oracle SOA Suite 11g? Absolutely!
Double the Performance of Oracle SOA Suite 11g? Absolutely!Double the Performance of Oracle SOA Suite 11g? Absolutely!
Double the Performance of Oracle SOA Suite 11g? Absolutely!
Revelation Technologies
 
Enterprise manager 13c
Enterprise manager 13cEnterprise manager 13c
Enterprise manager 13c
MarketingArrowECS_CZ
 
My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3
Oleksii(Alexey) Porytskyi
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAs
Gokhan Atil
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source Code
Georgi Kodinov
 
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Southeast Linuxfest -- MySQL User Admin Tips & TricksSoutheast Linuxfest -- MySQL User Admin Tips & Tricks
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Dave Stokes
 

What's hot (20)

Developing Information Schema Plugins
Developing Information Schema PluginsDeveloping Information Schema Plugins
Developing Information Schema Plugins
 
Introduction to MySQL Enterprise Monitor
Introduction to MySQL Enterprise MonitorIntroduction to MySQL Enterprise Monitor
Introduction to MySQL Enterprise Monitor
 
MySQL Monitoring Mechanisms
MySQL Monitoring MechanismsMySQL Monitoring Mechanisms
MySQL Monitoring Mechanisms
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS Schema
 
MySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench IntegrationMySQL's Performance Schema, SYS Schema and Workbench Integration
MySQL's Performance Schema, SYS Schema and Workbench Integration
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
What's next after Upgrade to 12c
What's next after Upgrade to 12cWhat's next after Upgrade to 12c
What's next after Upgrade to 12c
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasia
 
MySQL Monitoring 101
MySQL Monitoring 101MySQL Monitoring 101
MySQL Monitoring 101
 
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
Oracle Database 12c  New Features for Developers and DBAs - OTN TOUR LA 2015Oracle Database 12c  New Features for Developers and DBAs - OTN TOUR LA 2015
Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAs
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise Monitor
 
Double the Performance of Oracle SOA Suite 11g? Absolutely!
Double the Performance of Oracle SOA Suite 11g? Absolutely!Double the Performance of Oracle SOA Suite 11g? Absolutely!
Double the Performance of Oracle SOA Suite 11g? Absolutely!
 
Enterprise manager 13c
Enterprise manager 13cEnterprise manager 13c
Enterprise manager 13c
 
My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAs
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source Code
 
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
Southeast Linuxfest -- MySQL User Admin Tips & TricksSoutheast Linuxfest -- MySQL User Admin Tips & Tricks
Southeast Linuxfest -- MySQL User Admin Tips & Tricks
 

Similar to Instrumenting plugins for Performance Schema

Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
Morgan Tocker
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
Mark Leith
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
Mark Swarbrick
 
Developing Drizzle Replication Plugins
Developing Drizzle Replication PluginsDeveloping Drizzle Replication Plugins
Developing Drizzle Replication Plugins
Padraig O'Sullivan
 
2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server
Georgi Kodinov
 
OUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQLOUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQL
Georgi Kodinov
 
Peteris Arajs - Where is my data
Peteris Arajs - Where is my dataPeteris Arajs - Where is my data
Peteris Arajs - Where is my data
Andrejs Vorobjovs
 
MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
Morgan Tocker
 
Upgrading to my sql 8.0
Upgrading to my sql 8.0Upgrading to my sql 8.0
Upgrading to my sql 8.0
Ståle Deraas
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
Ted Wennmark
 
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
Mayank Prasad
 
InterConnect2016: WebApp Architectures with Java and Node.js
InterConnect2016: WebApp Architectures with Java and Node.jsInterConnect2016: WebApp Architectures with Java and Node.js
InterConnect2016: WebApp Architectures with Java and Node.js
Chris Bailey
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
Valeriy Kravchuk
 
Fosdem17 honeypot your database server
Fosdem17 honeypot your database serverFosdem17 honeypot your database server
Fosdem17 honeypot your database server
Georgi Kodinov
 
Advance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAdvance Sql Server Store procedure Presentation
Advance Sql Server Store procedure Presentation
Amin Uddin
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016
Mayank Prasad
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
Olivier DASINI
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
ftz 420
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
Miguel Araújo
 

Similar to Instrumenting plugins for Performance Schema (20)

Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 
Developing Drizzle Replication Plugins
Developing Drizzle Replication PluginsDeveloping Drizzle Replication Plugins
Developing Drizzle Replication Plugins
 
2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server
 
OUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQLOUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQL
 
Peteris Arajs - Where is my data
Peteris Arajs - Where is my dataPeteris Arajs - Where is my data
Peteris Arajs - Where is my data
 
MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
 
Upgrading to my sql 8.0
Upgrading to my sql 8.0Upgrading to my sql 8.0
Upgrading to my sql 8.0
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
 
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRsMySQL-Performance Schema- What's new in MySQL-5.7 DMRs
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
 
InterConnect2016: WebApp Architectures with Java and Node.js
InterConnect2016: WebApp Architectures with Java and Node.jsInterConnect2016: WebApp Architectures with Java and Node.js
InterConnect2016: WebApp Architectures with Java and Node.js
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
 
Fosdem17 honeypot your database server
Fosdem17 honeypot your database serverFosdem17 honeypot your database server
Fosdem17 honeypot your database server
 
Advance Sql Server Store procedure Presentation
Advance Sql Server Store procedure PresentationAdvance Sql Server Store procedure Presentation
Advance Sql Server Store procedure Presentation
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
MySQL Day Paris 2018 - Upgrade from MySQL 5.7 to MySQL 8.0
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 

Recently uploaded

MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
Linda Zhang
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
apoorva2579
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
Matthew Sinclair
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
Emerging Tech
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
UiPathCommunity
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
crioux1
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
Performance Budgets for the Real World by Tammy Everts
Performance Budgets for the Real World by Tammy EvertsPerformance Budgets for the Real World by Tammy Everts
Performance Budgets for the Real World by Tammy Everts
ScyllaDB
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
Safe Software
 
What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)
Margaret Fero
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
ScyllaDB
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
ScyllaDB
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
SATYENDRA100
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
How Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global ScaleHow Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global Scale
ScyllaDB
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
shanthidl1
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions
 
AI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AIAI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AI
Raphaël Semeteys
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
uuuot
 

Recently uploaded (20)

MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & SolutionsMYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
MYIR Product Brochure - A Global Provider of Embedded SOMs & Solutions
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
 
20240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 202420240702 QFM021 Machine Intelligence Reading List June 2024
20240702 QFM021 Machine Intelligence Reading List June 2024
 
Implementations of Fused Deposition Modeling in real world
Implementations of Fused Deposition Modeling  in real worldImplementations of Fused Deposition Modeling  in real world
Implementations of Fused Deposition Modeling in real world
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
 
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
Performance Budgets for the Real World by Tammy Everts
Performance Budgets for the Real World by Tammy EvertsPerformance Budgets for the Real World by Tammy Everts
Performance Budgets for the Real World by Tammy Everts
 
Coordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar SlidesCoordinate Systems in FME 101 - Webinar Slides
Coordinate Systems in FME 101 - Webinar Slides
 
What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)What Not to Document and Why_ (North Bay Python 2024)
What Not to Document and Why_ (North Bay Python 2024)
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
 
How to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory ModelHow to Avoid Learning the Linux-Kernel Memory Model
How to Avoid Learning the Linux-Kernel Memory Model
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
How Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global ScaleHow Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global Scale
 
Cookies program to display the information though cookie creation
Cookies program to display the information though cookie creationCookies program to display the information though cookie creation
Cookies program to display the information though cookie creation
 
Pigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdfPigging Solutions Sustainability brochure.pdf
Pigging Solutions Sustainability brochure.pdf
 
AI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AIAI_dev Europe 2024 - From OpenAI to Opensource AI
AI_dev Europe 2024 - From OpenAI to Opensource AI
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
 

Instrumenting plugins for Performance Schema

  • 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Instrumenting Plugins for Performance Schema Mark Leith Senior Software Development Manager MySQL Enterprise Tools, Oracle Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Program Agenda Yea but “Why?” The Interfaces An example Questions 1 2 3 4
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Yea but “Why?” • There’s a bunch of great interfaces in to the MySQL Server now, from the well known storage engines, through pre/post parser plugins, auditing, full text search, INFORMATION_SCHEMA tables, UDFs, replication interfaces, and more.. • We’ve made great strides in instrumenting the core server, but if you want to use plugins, and don’t also add to the instrumentation in the new standard ways, this will cause new black holes in your available performance data
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Performance Schema Event Horizon
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Interfaces • The main interface is within ./include/mysql/psi/ • The ABI is maintained via ./include/mysql/psi/psi.h • Great Doxygen based docs here: • https://dev.mysql.com/doc/dev/mysql-server/8.0.0/PAGE_PFS_PSI.html
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | The Interfaces • The API is broken down by the type of instrumentation • Threads, sync points (mutexes, rwlocks, conditions etc.) in include/mysql/psi/mysql_thread.h • File IO in include/mysql/psi/mysql_file.h • Memory in include/mysql/psi/mysql_memory.h • Network IO in include/mysql/psi/mysql_socket.h • These all use the underlying versioned performance schema interfaces via the psi.h ABI
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | An Example • Let us dream of an audit plugin • It will: • Log statements that cause errors to a file • Track some error stats with some global status variables • That requires: • Some file operations • A mutex to protect concurrent access to the variables and file
  • 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | pthread_mutex_t LOCK_client_error; static int client_error_plugin_init(…) { pthread_mutex_init(&LOCK_client_error, NULL); … } 8 An Example - Mutex init mysql_mutex_t LOCK_client_error; PSI_mutex_key key_LOCK_client_error; static PSI_mutex_info client_error_mutexes[]= { { &key_LOCK_client_error, "LOCK_client_error", PSI_FLAG_GLOBAL } }; static int client_error_plugin_init(…) { const char* category= "client_error"; int count; count= array_elements(client_error_mutexes); mysql_mutex_register(category, client_error_mutexes, count); mysql_mutex_init(key_LOCK_client_error, &LOCK_client_error, MY_MUTEX_INIT_FAST); … } P_S Instrument Info Register within P_S
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | FILE *fp; static int client_error_plugin_init(…) { if(!(fp = fopen(“client_errors.log”, “a+”))) return true; … } 9 An Example - File init PSI_file_key key_file_client_error_log; static PSI_file_info client_error_files[]= { { &key_file_client_error_log, "client_error_log", 0} }; static int client_error_plugin_init(…) { … count= array_elements(client_error_files); mysql_file_register(category, client_error_files, count); … if (!(client_error_log= mysql_file_create(key_file_client_error_log, “client_errors.log”, 0, O_WRONLY | O_APPEND, MYF(MY_WME)))) } See my_sys.h, in this case, write message on error
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | static int client_error_notify(…) { … if (error_event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR) { pthread_mutex_lock(&LOCK_client_error); … /* Increment some counters */ /* Create some log line buffer in buff */ … write(fp, (uchar*) buff, len); pthread_mutex_unlock(&LOCK_client_error); } } 10 An Example - Writing to the file static int client_error_notify(…) { … if (error_event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR) { mysql_mutex_lock(&LOCK_client_error); … /* Increment some counters */ /* Create some log line buffer in buff */ … mysql_file_write(client_error_log, (uchar*) buff, len, MYF_RW); mysql_mutex_unlock(&LOCK_client_error); } } Write message on error, or if not all bytes are processed
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | An Example - Adding Stages • Now you know where you may be waiting for thread synchronisation or file IO (or network IO, I won’t talk about that here, look at the API if you’re doing some Daemon plugin) • You can track more major sections of code with Stages - the thread states that exposed via process lists and profiling interfaces • API is within include/mysql/psi/mysql_stage.h
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | PSI_stage_info opening_client_error_log_file= { 0, "Opening client error log file", 0 }; PSI_stage_info recording_error_statistics= { 0, "Recording error statistics", 0 }; PSI_stage_info *client_error_stages[]= { &opening_client_error_log_file, &recording_error_statistics }; 12 An Example - Stages static int client_error_log_open() { mysql_set_stage(opening_client_error_log_file.m_key); mysql_mutex_lock(&LOCK_client_error_log); /* Open the file, maybe write some header */ return 0; } static int client_error_notify(…) { … if (error_event->event_subclass == MYSQL_AUDIT_GENERAL_ERROR) { mysql_set_stage(recording_error_statistics.m_key); /* Update stats, write log file etc. */ } return 0; }
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | An Example - Adding Stages • Note that when adding stages, you are hijacking the current stage • Think about where in the flow your stage can be added • Consider adding a “continuation” stage • This can show code executed after your plugin (or face the blame game)
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | An Example - Stage Progress • You can also track progress of stages within 5.7+ • Call mysql_set_stage(…) • Then mysql_stage_set_work_estimated(<stage>, <estimate count>) • Then while doing the estimated work, at the right interval: • mysql_stage_set_work_completed(<stage>, <completed count>);
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | An Example - Performance Schema Output 15 ( SELECT thread_id, nesting_event_id, event_id, event_name, sys.format_time(timer_wait) AS time FROM performance_schema.events_stages_history_long ORDER BY event_id ) UNION ALL ( SELECT thread_id, nesting_event_id, event_id, concat('-> ', event_name), sys.format_time(timer_wait) AS time FROM performance_schema.events_waits_history_long WHERE event_name != 'idle' ORDER BY event_id ) ORDER BY thread_id, event_id; +-----------+------------------+----------+--------------------------------------------------------+-----------+ | thread_id | nesting_event_id | event_id | event_name | time | +-----------+------------------+----------+--------------------------------------------------------+-----------+ | 24 | 427 | 428 | stage/sql/starting | 120.46 us | … | 24 | 428 | 437 | -> wait/synch/rwlock/sql/LOCK_grant | 437.32 ns | | 24 | 427 | 438 | stage/sql/Opening tables | 28.21 us | | 24 | 427 | 440 | stage/client_error/Recording error statistics | 23.14 us | | 24 | 440 | 441 | -> wait/synch/mutex/client_error/LOCK_client_error_log | 203.58 ns | | 24 | 440 | 442 | -> wait/io/file/client_error/client_error_log | 11.25 us | | 24 | 427 | 443 | stage/sql/query end | 3.52 us | | 24 | 443 | 444 | -> wait/synch/mutex/sql/THD::LOCK_query_plan | 158.34 ns | | 24 | 427 | 445 | stage/sql/closing tables | 1.68 us | | 24 | 427 | 446 | stage/sql/freeing items | 50.63 us |
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Question and feedback time!
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.