SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Maximizing
Performance via
Tuning and
Optimization
Getting the most from MariaDB
Server
Jon Day
Solution Architect
Agenda • General Best Practices
• Server, Storage, Network and O/S
• Connections & Pooling
• MariaDB Config Settings
• Query Tuning
• Q&A
General Best Practices
Maybe obvious, but worth repeating
• Service Level Agreements (SLAs)
– Individual Biz/App Transactions
– Throughput
– Latency (at percentile)
– Peaks of peaks or favorable scheduling?
• Translate to Database Transactions
Define Target
Capture Metrics
• Biz/App Transactions
– Code Instrumentation
– Synthetic Transactions
– Compare to defined SLAs
• Database Transactions
• Sub-system level
– Servers (Web, App, DB, etc…)
– Storage
– Network
– Database
Tuning Routine - When to Tune
• Tune from Start of the Application Lifecycle
– Start Early to Ensure Schema is Well Constructed
– Test Queries on Real Data — Watch for Bottlenecks
– Over Tuning without Production Data or Traffic isn’t productive
• Conduct Periodic Reviews of Production Systems
– Watch for Schema, Query and Significant Changes
– Check Carefully New Application Features
– Monitor System Resources — Disk, Memory, Network, CPU
Tuning Routine - When Not to Tune
• Identify Objectives in Advance
– Adhere to Objectives
• Be Aware of Data Integrity
– Where is Speed Most Important?
– Where is Integrity Most Important?
– Adhere to these Boundaries
History
Alerts
Leverage your Metrics
Avoiding Cliffs • Understand expected business volumes
• Watch system-level stats for saturation
• Stress testing
– Sysbench
– HammerDB
– TPC
– Many others….
– Custom
Server, Storage, Network and O/S
Core Infrastructure
• Dedicated Server
• Memory
– More usually helps (up to ~dataset size)
– Important with read-heavy + slow disk
• More CPUs
– Highly concurrent use cases
– Usually favored over faster CPUs
• Faster CPUs
– Less concurrent use cases
– Dataset fits in memory
Database Server
• Local or SAN over NAS
– Performance
• SSD over HHD
– Performance and MTBF
– SSD wear not usually a factor
• SSDs
– Consumer
– Prosumer
– PCIe
– NVMe
Storage
• Can be Bandwidth Hungry
– Regular client traffic
– Replication Traffic
– Rebuilding replicas from snapshots
• Stability matters for Replication
• Sometimes overlooked as potential
bottleneck
• Efficient DNS setup*
Network
OS Settings
Linux Settings
•Swappiness
○ Value for propensity of the OS to swap
to disk
○ Defaults are usually 60
○ Commonly set low to 10 or so (not 0)
•Noatime
○ Mount disks with this option
○ Turns off writing of access time to disk
with every file access
○ Without this option every read becomes
an additional write
Connections & Pooling
Applying Back Pressure
Back Pressure in the Full Stack
Firewall/LB Web Servers App Servers MaxScale MariaDB
Server(s)
MariaDB Connection Controls
App Servers MaxScale MariaDB
Server(s)
max_connections
wait_timeout
thread_handling
thread_pool_max_threads
thread_pool_min_threads
thread_pool_idle_timeout
...
MariaDBDataSource
MariaDBPoolDataSource
maxPoolSize
minPoolSize
...
Outbound
persistpoolmax
persistmaxtime
Inbound
max_connections
connection_timeout
Further Reading
• Java Connector Pooling
mariadb.com/kb/en/library/pool-datasource-implementation/
• MaxScale
mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22/maxscale-
configuration-usage-scenarios/#server
mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22/maxscale-
configuration-usage-scenarios/#server
• Server Thread Pools
mariadb.com/kb/en/library/thread-pool-in-mariadb/
mariadb.com/kb/en/library/thread-pool-system-and-status-variables/
Configuration Settings
Common Settings with Performance Impact
• Runtime changes via SET GLOBAL
• Make permanent with changes to my.cnf
– Make sure you have right my.cnf
– Verify with SHOW GLOBAL
• One change at a time
• Production changes
– tested, reviewed, version controlled
Changing Config
Settings
Configuration Settings
innodb_buffer_pool_size
•The first setting to update
•The buffer pool is where data and indexes
are cached
• Utilize memory for read operations rather
than disk
•80% RAM rule of thumb
•Typical values are
✓ 5-6GB (8GB RAM)
✓ 20-25GB (32GB RAM)
✓ 100-120GB (128GB RAM)
Configuration Settings
query_cache_size
● Query cache is a well known bottleneck
● Consider setting query_cache_size = 0
● Use other ways to speed up read
queries:
○ Good indexing
○ Adding replicas to spread the read
load
Configuration Settings
innodb_log_file_size
● Size of the redo logs - 25 to 50% of
innodb_buffer_pool usually
recommended
● Redo logs are used to make sure writes
are fast and durable and also during
crash recovery
● Larger log files can lead to slower
recovery in the event of a server crash
● But! Larger log files also reduce the
number of checkpoints needed and
reduce disk I/O
Configuration Settings
innodb_file_per_table
● Each .ibd file represents a tablespace of its
own.
● Database operations such as “TRUNCATE”
can be completed faster and you may also
reclaim unused space when dropping or
truncating a database table.
● Allows some of the database tables to be
kept in separate storage device. This can
greatly improve the I/O load on your disks.
Configuration Settings
Disable MySQL Reverse
DNS Lookups
● MariaDB performs a DNS lookup of the
user’s IP address and Hostname with
connection
● The IP address is checked by resolving it to a
host name. The hostname is then resolved to
an IP to verify
● This allows DNS issues to cause delays
● You can disable and use IP addresses only
○ skip-name-resolve under [mysqld] in
my.cnf
Storage Engines
● XtraDB is the best choice in the majority of cases. It is a performance-enhanced fork of InnoDB and is the
MariaDB default engine until MariaDB 10.1.
● InnoDB is a good general transactional storage engine. It is the default MySQL storage engine, and default
MariaDB 10.2 storage engine, but in earlier releases XtraDB is a performance enhanced fork of InnoDB, and is
usually preferred.
● Aria, MariaDB's more modern improvement on MyISAM, has a small footprint and allows for easy copying
between systems.
● MyISAM has a small footprint and allows for easy copying between systems. MyISAM is MySQL's oldest storage
engine. There is usually little reason to use it except for legacy purposes. Aria is MariaDB's more modern
improvement.
● Spider uses partitioning to provide data sharding through multiple servers.
● ColumnStore utilizes a massively parallel distributed data architecture and is designed for big data scaling to
process petabytes of
● MyRocks enables greater compression than InnoDB, as well as less write amplification giving better endurance of
flash storage and improving overall throughput. (Currently Alpha in MariaDB 10.2)
Query Tuning
There are always more queries to tune
Finding Slow
Queries slow_query_log = 1
slow_query_log-file = /var/lib/mysql/myslow.log
long_query_time = 10
Pay attention to similar queries and the
query count
Analyzing Slow
Queries
EXPLAIN
SELECT *
FROM employees
WHERE MONTH(birth_date) = 8 G
id: 1
select_type: SIMPLE
table: employees
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 299587
Extra: Using where
• Poor Indexing #1 Reason for poor
performance
• Basics of B-Tree Indexing same across
relational systems
• Space/Performance Tradeoff
• Write/Read Tradeoff
Indexing
• PRIMARY KEY = Clustered Index
• Secondary Indexes reference hold
primary key
– keep PRIMARY KEY small
• InnoDB Table Stats
• Optimizer Hints
– https://mariadb.com/kb/en/library/optimizer-hints/
InnoDB
Indexing Tips
Query Tuning
SHOW STATUS
Global or Session
● Returns List of Internal Counters
● GLOBAL for System-Wide Status — Since Start-
Up
● SESSION for Local to Client Connection
● FLUSH STATUS Resets Local Counters
● Monitor Changes to Counters to Identify Hot
Spots
● Collect Periodically Status Snapshots to Profile
Traffic
Query Tuning
PERFORMANCE_SCHEMA
● Similar to INFORMATION_SCHEMA , but
Performance Tuning
● Monitors MariaDB Server Events
● Function Calls, Operating System Waits, Internal
Mutexes, I/O Calls
● Detailed Query Execution Stages (Parsing,
Statistics, Sorting)
● Some Features Storage Engine Specific
● Monitoring Lightweight and Requires No
Dedicated Thread
● Designed to be Used Iteratively with Successive
Refinement
Database Design
Choosing Data Types
● Use Appropriate Data Type (INT for
Numbers, VARCHAR)
● Use Smallest Useful Type
● Variable Length Fields are often Padded
● Use NOT NULL, where Practical
○ A NULL field uses slightly More
Disk and Memory (Depends on
Storage Engine)
● Use PROCEDURE ANALYSE( )
Monitoring and Query Tuning
Monitoring Tools
Monyog - Agentless and Cost-effective MariaDB monitoring tool
Box Anemometer - a MariaDB Slow Query Monitor. This tool is used to analyze slow query logs
collected from MariaDB instances to identify problematic queries
Q&A
Thank you
james.mclaurin@mariadb.com.
Appendix
Backup Slides and More
Configuration Settings
max_connections •‘Too many connections’ error?
•Using a connection pool at the application
level or a thread pool at the MariaDB level
can help
Configuration Settings
Check for MySQL idle
Connections
● Idle connections consume resources and
should be interrupted or refreshed when
possible.
● Idle connections are in “sleep” state and
usually stay that way for long period of time.
● To look for idled connections:
● # mysqladmin processlist -u root -p | grep
“Sleep”
● You can check the code for the cause if
many idled
● You can also change the wait_timeout value
Configuration Settings
thread_cache_size
● The thread_cache_size directive sets the amount of
threads that your server should cache.
● To find the thread cache hit rate, you can use the
following technique:
○ show status like 'Threads_created';
○ show status like 'Connections';
● calculate the thread cache hit rate percentage:
○ 100 - ((Threads_created / Connections) * 100)
● Dynamically set to a new value:
○ set global thread_cache_size = 16;
Configuration Settings
memory parameters
● MariaDB uses temporary tables when
processing complex queries involving joins
and sorting
● The default size of a temporary table is very
small
○ The size is configured in your my.cnf:
tmp-table-size = 1G
max-heap-table-size = 1G
● Both should have the same size and will
help prevent disk writes
● A rule of thumb is giving 64Mb for every
GB of RAM on the server
Configuration Settings
Buffer Sizes
● join buffer size
○ used to process joins – but only full
joins on which no keys are possible
● sort buffer size
○ Sort buffer size is used to sort data.
○ The system status variable
sort_merge_passes will indicates need
to increase
○ This variable should be as low as
possible.
● These buffers are allocated per connection
and play a significant role in the
performance of the system.
Configuration Settings
max_allowed_packet
● MariaDB splits data into packets. Usually a
single packet is considered a row that is sent
to a client.
● The max_allowed_packet directive defines
the maximum size of packet that can be
sent.
● Setting this value too low can cause a query
to stall and you will receive an error in your
error log.
● It is recommended to set the value to the
size of your largest packet.
○ Some suggest 11 times the largest BLOB

Weitere ähnliche Inhalte

Was ist angesagt?

Aceleracion de aplicacione 2
Aceleracion de aplicacione 2Aceleracion de aplicacione 2
Aceleracion de aplicacione 2
jfth
 
Netezza Deep Dives
Netezza Deep DivesNetezza Deep Dives
Netezza Deep Dives
Rush Shah
 

Was ist angesagt? (20)

Remote DBA Experts 11g Features
Remote DBA Experts 11g FeaturesRemote DBA Experts 11g Features
Remote DBA Experts 11g Features
 
PostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter TuningPostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter Tuning
 
Cassandra TK 2014 - Large Nodes
Cassandra TK 2014 - Large NodesCassandra TK 2014 - Large Nodes
Cassandra TK 2014 - Large Nodes
 
Aceleracion de aplicacione 2
Aceleracion de aplicacione 2Aceleracion de aplicacione 2
Aceleracion de aplicacione 2
 
5 Postgres DBA Tips
5 Postgres DBA Tips5 Postgres DBA Tips
5 Postgres DBA Tips
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
 
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
Webinar: Dyn + DataStax - helping companies deliver exceptional end-user expe...
 
Hardware planning & sizing for sql server
Hardware planning & sizing for sql serverHardware planning & sizing for sql server
Hardware planning & sizing for sql server
 
How to make data available for analytics ASAP
How to make data available for analytics ASAPHow to make data available for analytics ASAP
How to make data available for analytics ASAP
 
Configuring workload-based storage and topologies
Configuring workload-based storage and topologiesConfiguring workload-based storage and topologies
Configuring workload-based storage and topologies
 
Technical white paper--Optimizing Quality of Service with SAP HANAon Power Ra...
Technical white paper--Optimizing Quality of Service with SAP HANAon Power Ra...Technical white paper--Optimizing Quality of Service with SAP HANAon Power Ra...
Technical white paper--Optimizing Quality of Service with SAP HANAon Power Ra...
 
Pow03190 usen
Pow03190 usenPow03190 usen
Pow03190 usen
 
North Bay Ruby Meetup 101911
North Bay Ruby Meetup 101911North Bay Ruby Meetup 101911
North Bay Ruby Meetup 101911
 
How to size up an Apache Cassandra cluster (Training)
How to size up an Apache Cassandra cluster (Training)How to size up an Apache Cassandra cluster (Training)
How to size up an Apache Cassandra cluster (Training)
 
Right-Sizing your SQL Server Virtual Machine
Right-Sizing your SQL Server Virtual MachineRight-Sizing your SQL Server Virtual Machine
Right-Sizing your SQL Server Virtual Machine
 
Cassandra Summit 2014: Apache Cassandra Best Practices at Ebay
Cassandra Summit 2014: Apache Cassandra Best Practices at EbayCassandra Summit 2014: Apache Cassandra Best Practices at Ebay
Cassandra Summit 2014: Apache Cassandra Best Practices at Ebay
 
M|18 Analyzing Data with the MariaDB AX Platform
M|18 Analyzing Data with the MariaDB AX PlatformM|18 Analyzing Data with the MariaDB AX Platform
M|18 Analyzing Data with the MariaDB AX Platform
 
Netezza Deep Dives
Netezza Deep DivesNetezza Deep Dives
Netezza Deep Dives
 
Hbase: an introduction
Hbase: an introductionHbase: an introduction
Hbase: an introduction
 
Implementing Parallelism in PostgreSQL - PGCon 2014
Implementing Parallelism in PostgreSQL - PGCon 2014Implementing Parallelism in PostgreSQL - PGCon 2014
Implementing Parallelism in PostgreSQL - PGCon 2014
 

Ähnlich wie Maximizing performance via tuning and optimization

Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
Liran Zelkha
 

Ähnlich wie Maximizing performance via tuning and optimization (20)

Deep Dive on MySQL Databases on AWS - AWS Online Tech Talks
Deep Dive on MySQL Databases on AWS - AWS Online Tech TalksDeep Dive on MySQL Databases on AWS - AWS Online Tech Talks
Deep Dive on MySQL Databases on AWS - AWS Online Tech Talks
 
Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
 
Höchste Datenbankleistung durch Anpassung und Optimierung
Höchste Datenbankleistung durch Anpassung und OptimierungHöchste Datenbankleistung durch Anpassung und Optimierung
Höchste Datenbankleistung durch Anpassung und Optimierung
 
Getting Started with Managed Database Services on AWS - September 2016 Webina...
Getting Started with Managed Database Services on AWS - September 2016 Webina...Getting Started with Managed Database Services on AWS - September 2016 Webina...
Getting Started with Managed Database Services on AWS - September 2016 Webina...
 
Selecting the Right AWS Database Solution - AWS 2017 Online Tech Talks
Selecting the Right AWS Database Solution - AWS 2017 Online Tech TalksSelecting the Right AWS Database Solution - AWS 2017 Online Tech Talks
Selecting the Right AWS Database Solution - AWS 2017 Online Tech Talks
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
 
Maximizing performance via tuning and optimization
Maximizing performance via tuning and optimizationMaximizing performance via tuning and optimization
Maximizing performance via tuning and optimization
 
Capacity Planning
Capacity PlanningCapacity Planning
Capacity Planning
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
 
MySQL and MariaDB
MySQL and MariaDBMySQL and MariaDB
MySQL and MariaDB
 
How to Set Up ApsaraDB for RDS on Alibaba Cloud
How to Set Up ApsaraDB for RDS on Alibaba CloudHow to Set Up ApsaraDB for RDS on Alibaba Cloud
How to Set Up ApsaraDB for RDS on Alibaba Cloud
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen
 
Running MySQL in AWS
Running MySQL in AWSRunning MySQL in AWS
Running MySQL in AWS
 
Azure data platform overview
Azure data platform overviewAzure data platform overview
Azure data platform overview
 
AWS March 2016 Webinar Series - Managed Database Services on Amazon Web Services
AWS March 2016 Webinar Series - Managed Database Services on Amazon Web ServicesAWS March 2016 Webinar Series - Managed Database Services on Amazon Web Services
AWS March 2016 Webinar Series - Managed Database Services on Amazon Web Services
 
MySQL and MariaDB
MySQL and MariaDBMySQL and MariaDB
MySQL and MariaDB
 
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
 

Mehr von MariaDB plc

Mehr von MariaDB plc (20)

MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - Newpharma
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - Cloud
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB Enterprise
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentation
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentation
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023
 
Hochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBHochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDB
 
Die Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerDie Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise Server
 
Introducing workload analysis
Introducing workload analysisIntroducing workload analysis
Introducing workload analysis
 
Under the hood: SkySQL monitoring
Under the hood: SkySQL monitoringUnder the hood: SkySQL monitoring
Under the hood: SkySQL monitoring
 
Introducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorIntroducing the R2DBC async Java connector
Introducing the R2DBC async Java connector
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introduction
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDB
 
The architecture of SkySQL
The architecture of SkySQLThe architecture of SkySQL
The architecture of SkySQL
 
What to expect from MariaDB Platform X5, part 1
What to expect from MariaDB Platform X5, part 1What to expect from MariaDB Platform X5, part 1
What to expect from MariaDB Platform X5, part 1
 

Kürzlich hochgeladen

Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
JohnnyPlasten
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
shivangimorya083
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
shambhavirathore45
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
shivangimorya083
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 

Kürzlich hochgeladen (20)

Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 

Maximizing performance via tuning and optimization

  • 1. Maximizing Performance via Tuning and Optimization Getting the most from MariaDB Server Jon Day Solution Architect
  • 2. Agenda • General Best Practices • Server, Storage, Network and O/S • Connections & Pooling • MariaDB Config Settings • Query Tuning • Q&A
  • 3. General Best Practices Maybe obvious, but worth repeating
  • 4. • Service Level Agreements (SLAs) – Individual Biz/App Transactions – Throughput – Latency (at percentile) – Peaks of peaks or favorable scheduling? • Translate to Database Transactions Define Target
  • 5. Capture Metrics • Biz/App Transactions – Code Instrumentation – Synthetic Transactions – Compare to defined SLAs • Database Transactions • Sub-system level – Servers (Web, App, DB, etc…) – Storage – Network – Database
  • 6. Tuning Routine - When to Tune • Tune from Start of the Application Lifecycle – Start Early to Ensure Schema is Well Constructed – Test Queries on Real Data — Watch for Bottlenecks – Over Tuning without Production Data or Traffic isn’t productive • Conduct Periodic Reviews of Production Systems – Watch for Schema, Query and Significant Changes – Check Carefully New Application Features – Monitor System Resources — Disk, Memory, Network, CPU
  • 7. Tuning Routine - When Not to Tune • Identify Objectives in Advance – Adhere to Objectives • Be Aware of Data Integrity – Where is Speed Most Important? – Where is Integrity Most Important? – Adhere to these Boundaries
  • 9. Avoiding Cliffs • Understand expected business volumes • Watch system-level stats for saturation • Stress testing – Sysbench – HammerDB – TPC – Many others…. – Custom
  • 10. Server, Storage, Network and O/S Core Infrastructure
  • 11. • Dedicated Server • Memory – More usually helps (up to ~dataset size) – Important with read-heavy + slow disk • More CPUs – Highly concurrent use cases – Usually favored over faster CPUs • Faster CPUs – Less concurrent use cases – Dataset fits in memory Database Server
  • 12. • Local or SAN over NAS – Performance • SSD over HHD – Performance and MTBF – SSD wear not usually a factor • SSDs – Consumer – Prosumer – PCIe – NVMe Storage
  • 13. • Can be Bandwidth Hungry – Regular client traffic – Replication Traffic – Rebuilding replicas from snapshots • Stability matters for Replication • Sometimes overlooked as potential bottleneck • Efficient DNS setup* Network
  • 14. OS Settings Linux Settings •Swappiness ○ Value for propensity of the OS to swap to disk ○ Defaults are usually 60 ○ Commonly set low to 10 or so (not 0) •Noatime ○ Mount disks with this option ○ Turns off writing of access time to disk with every file access ○ Without this option every read becomes an additional write
  • 16. Back Pressure in the Full Stack Firewall/LB Web Servers App Servers MaxScale MariaDB Server(s)
  • 17. MariaDB Connection Controls App Servers MaxScale MariaDB Server(s) max_connections wait_timeout thread_handling thread_pool_max_threads thread_pool_min_threads thread_pool_idle_timeout ... MariaDBDataSource MariaDBPoolDataSource maxPoolSize minPoolSize ... Outbound persistpoolmax persistmaxtime Inbound max_connections connection_timeout
  • 18. Further Reading • Java Connector Pooling mariadb.com/kb/en/library/pool-datasource-implementation/ • MaxScale mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22/maxscale- configuration-usage-scenarios/#server mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-22/maxscale- configuration-usage-scenarios/#server • Server Thread Pools mariadb.com/kb/en/library/thread-pool-in-mariadb/ mariadb.com/kb/en/library/thread-pool-system-and-status-variables/
  • 19. Configuration Settings Common Settings with Performance Impact
  • 20. • Runtime changes via SET GLOBAL • Make permanent with changes to my.cnf – Make sure you have right my.cnf – Verify with SHOW GLOBAL • One change at a time • Production changes – tested, reviewed, version controlled Changing Config Settings
  • 21. Configuration Settings innodb_buffer_pool_size •The first setting to update •The buffer pool is where data and indexes are cached • Utilize memory for read operations rather than disk •80% RAM rule of thumb •Typical values are ✓ 5-6GB (8GB RAM) ✓ 20-25GB (32GB RAM) ✓ 100-120GB (128GB RAM)
  • 22. Configuration Settings query_cache_size ● Query cache is a well known bottleneck ● Consider setting query_cache_size = 0 ● Use other ways to speed up read queries: ○ Good indexing ○ Adding replicas to spread the read load
  • 23. Configuration Settings innodb_log_file_size ● Size of the redo logs - 25 to 50% of innodb_buffer_pool usually recommended ● Redo logs are used to make sure writes are fast and durable and also during crash recovery ● Larger log files can lead to slower recovery in the event of a server crash ● But! Larger log files also reduce the number of checkpoints needed and reduce disk I/O
  • 24. Configuration Settings innodb_file_per_table ● Each .ibd file represents a tablespace of its own. ● Database operations such as “TRUNCATE” can be completed faster and you may also reclaim unused space when dropping or truncating a database table. ● Allows some of the database tables to be kept in separate storage device. This can greatly improve the I/O load on your disks.
  • 25. Configuration Settings Disable MySQL Reverse DNS Lookups ● MariaDB performs a DNS lookup of the user’s IP address and Hostname with connection ● The IP address is checked by resolving it to a host name. The hostname is then resolved to an IP to verify ● This allows DNS issues to cause delays ● You can disable and use IP addresses only ○ skip-name-resolve under [mysqld] in my.cnf
  • 26. Storage Engines ● XtraDB is the best choice in the majority of cases. It is a performance-enhanced fork of InnoDB and is the MariaDB default engine until MariaDB 10.1. ● InnoDB is a good general transactional storage engine. It is the default MySQL storage engine, and default MariaDB 10.2 storage engine, but in earlier releases XtraDB is a performance enhanced fork of InnoDB, and is usually preferred. ● Aria, MariaDB's more modern improvement on MyISAM, has a small footprint and allows for easy copying between systems. ● MyISAM has a small footprint and allows for easy copying between systems. MyISAM is MySQL's oldest storage engine. There is usually little reason to use it except for legacy purposes. Aria is MariaDB's more modern improvement. ● Spider uses partitioning to provide data sharding through multiple servers. ● ColumnStore utilizes a massively parallel distributed data architecture and is designed for big data scaling to process petabytes of ● MyRocks enables greater compression than InnoDB, as well as less write amplification giving better endurance of flash storage and improving overall throughput. (Currently Alpha in MariaDB 10.2)
  • 27. Query Tuning There are always more queries to tune
  • 28. Finding Slow Queries slow_query_log = 1 slow_query_log-file = /var/lib/mysql/myslow.log long_query_time = 10 Pay attention to similar queries and the query count
  • 29. Analyzing Slow Queries EXPLAIN SELECT * FROM employees WHERE MONTH(birth_date) = 8 G id: 1 select_type: SIMPLE table: employees type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 299587 Extra: Using where
  • 30. • Poor Indexing #1 Reason for poor performance • Basics of B-Tree Indexing same across relational systems • Space/Performance Tradeoff • Write/Read Tradeoff Indexing
  • 31. • PRIMARY KEY = Clustered Index • Secondary Indexes reference hold primary key – keep PRIMARY KEY small • InnoDB Table Stats • Optimizer Hints – https://mariadb.com/kb/en/library/optimizer-hints/ InnoDB Indexing Tips
  • 32. Query Tuning SHOW STATUS Global or Session ● Returns List of Internal Counters ● GLOBAL for System-Wide Status — Since Start- Up ● SESSION for Local to Client Connection ● FLUSH STATUS Resets Local Counters ● Monitor Changes to Counters to Identify Hot Spots ● Collect Periodically Status Snapshots to Profile Traffic
  • 33. Query Tuning PERFORMANCE_SCHEMA ● Similar to INFORMATION_SCHEMA , but Performance Tuning ● Monitors MariaDB Server Events ● Function Calls, Operating System Waits, Internal Mutexes, I/O Calls ● Detailed Query Execution Stages (Parsing, Statistics, Sorting) ● Some Features Storage Engine Specific ● Monitoring Lightweight and Requires No Dedicated Thread ● Designed to be Used Iteratively with Successive Refinement
  • 34. Database Design Choosing Data Types ● Use Appropriate Data Type (INT for Numbers, VARCHAR) ● Use Smallest Useful Type ● Variable Length Fields are often Padded ● Use NOT NULL, where Practical ○ A NULL field uses slightly More Disk and Memory (Depends on Storage Engine) ● Use PROCEDURE ANALYSE( )
  • 35. Monitoring and Query Tuning Monitoring Tools Monyog - Agentless and Cost-effective MariaDB monitoring tool Box Anemometer - a MariaDB Slow Query Monitor. This tool is used to analyze slow query logs collected from MariaDB instances to identify problematic queries
  • 36. Q&A
  • 39. Configuration Settings max_connections •‘Too many connections’ error? •Using a connection pool at the application level or a thread pool at the MariaDB level can help
  • 40. Configuration Settings Check for MySQL idle Connections ● Idle connections consume resources and should be interrupted or refreshed when possible. ● Idle connections are in “sleep” state and usually stay that way for long period of time. ● To look for idled connections: ● # mysqladmin processlist -u root -p | grep “Sleep” ● You can check the code for the cause if many idled ● You can also change the wait_timeout value
  • 41. Configuration Settings thread_cache_size ● The thread_cache_size directive sets the amount of threads that your server should cache. ● To find the thread cache hit rate, you can use the following technique: ○ show status like 'Threads_created'; ○ show status like 'Connections'; ● calculate the thread cache hit rate percentage: ○ 100 - ((Threads_created / Connections) * 100) ● Dynamically set to a new value: ○ set global thread_cache_size = 16;
  • 42. Configuration Settings memory parameters ● MariaDB uses temporary tables when processing complex queries involving joins and sorting ● The default size of a temporary table is very small ○ The size is configured in your my.cnf: tmp-table-size = 1G max-heap-table-size = 1G ● Both should have the same size and will help prevent disk writes ● A rule of thumb is giving 64Mb for every GB of RAM on the server
  • 43. Configuration Settings Buffer Sizes ● join buffer size ○ used to process joins – but only full joins on which no keys are possible ● sort buffer size ○ Sort buffer size is used to sort data. ○ The system status variable sort_merge_passes will indicates need to increase ○ This variable should be as low as possible. ● These buffers are allocated per connection and play a significant role in the performance of the system.
  • 44. Configuration Settings max_allowed_packet ● MariaDB splits data into packets. Usually a single packet is considered a row that is sent to a client. ● The max_allowed_packet directive defines the maximum size of packet that can be sent. ● Setting this value too low can cause a query to stall and you will receive an error in your error log. ● It is recommended to set the value to the size of your largest packet. ○ Some suggest 11 times the largest BLOB