SlideShare a Scribd company logo
“Understanding MySQL
Locking Issues”
Contents
 Server Variables
 Query Cache
 Locking Issues
 Internal Locking
 External Locking
 Concurrent Inserts
 Connection Pooling
Server Variables
The MySQL server maintains many system variables
that indicate how it is configured.
• Each system variable has its default value.
• We can dynamically change these settings using
SET command.
• SHOW VARIABLES
• Currently there are 291 variables defined in
MySQL 5.1.6
• SHOW VARIABLES LIKE 'have_query_cache';
• SHOW STATUS LIKE 'Table%';
Query Cache
• The have_query_cache server system variable
indicates whether the query cache is available.
• SHOW VARIABLES LIKE 'have_query_cache';
• It totally depends upon query_cache_type and
query_cache_size
• query_cache_type is of 0,1 and 2 (On DEMAND)
• You can set max query_cache_size (1MB) as
well as query_cache_min_res_unit (4KB)
• SHOW STATUS LIKE '%qcache%';
Locking Issues
• SHOW STATUS LIKE 'Table%';
To achieve a very high lock speed, MySQL uses table
locking (instead of page, row, or column locking)
for all storage engines except InnoDB and
NDBCLUSTER.
• Internal Locking
• External Locking
• Concurrent Inserts
Internal Locking
Performed within the MySQL server itself to manage
contention for table contents by multiple sessions.
MySQL grants table write locks as follows:
-If there are no locks on the table, put a write lock
on it.Otherwise, put the lock request in the write
lock queue.
MySQL grants table read locks as follows:
-If there are no write locks on the table, put a read
lock on it.Otherwise, put the lock request in the
read lock queue.
External Locking
• External locking is used in situations where a
single process such as the MySQL server cannot
be assumed to be the only process that requires
access to tables.
• If you run multiple servers that use the same
database directory, each server must have
external locking enabled.
• With external locking in effect, each process
that requires access to a table acquires a file
system lock for the table files before proceeding
to access the table.
External Locking
• External locking affects server performance
because the server must sometimes wait for
other processes before it can access tables.
• The easiest way to satisfy these conditions is to
always use --external-locking together with
• skip_external_locking = OFF
• SET delay-key-write=OFF
• SET query-cache-size=0.
Concurrent Inserts
• The MySQL storage engine supports
concurrent inserts to reduce contention
between readers and writers for a given table
• An INSERT statement can be executed to add
rows to the end of the table at the same time
that SELECT statements are reading rows
from the table.
• If there are multiple INSERT statements,
they are queued and performed in sequence,
concurrently with the SELECT statements.
Concurrent Inserts
- concurrent_insert = 0, 1, 2
0) If concurrent_insert is set to 0, concurrent
inserts are disabled.
1) By default, the variable is set to 1 and
concurrent inserts are handled.
2) If the variable is set to 2, concurrent inserts at
the end of the table are permitted even for
tables that have deleted rows(holes).
Connection Pooling
• By default, connection pooling is enabled in
ADO.NET, Unless you explicitly disable it.
• Only connections with the same configuration
can be pooled. ADO.NET keeps several pools at
the same time, one for each configuration.
• Connections are separated into pools by
connection string, and by Windows identity when
integrated security is used.
• A connection pool is created for each unique
connection string.
Connection Pooling
- Connections are added to the pool as needed, up to
the maximum pool size specified (100 is the
default).
- Connections are released back into the pool when
they are closed or disposed.
- If MinPoolSize is either not specified in the
connection string or is specified as 0, the
connections in the pool will be closed after a
period of inactivity.
- However, if the specified MinPoolSize is greater
than zero, the connection pool is not destroyed
until the AppDomain is unloaded and the process
Take Away

More Related Content

PDF
Barcelona mysqlnd qc
PDF
MySQL Manchester TT - Performance Tuning
PPT
MySQL Performance Tuning at COSCUP 2014
PDF
MySQL Server Defaults
ODP
MySQL 5.7 - What's new and How to upgrade
PDF
Mysql 57-upcoming-changes
PDF
MySQL NoSQL APIs
PDF
My sql 5.7-upcoming-changes-v2
Barcelona mysqlnd qc
MySQL Manchester TT - Performance Tuning
MySQL Performance Tuning at COSCUP 2014
MySQL Server Defaults
MySQL 5.7 - What's new and How to upgrade
Mysql 57-upcoming-changes
MySQL NoSQL APIs
My sql 5.7-upcoming-changes-v2

What's hot (20)

PDF
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
PDF
MySQL: From Single Instance to Big Data
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
PDF
MySQL Performance Metrics that Matter
PDF
MySQL 5.6 - Operations and Diagnostics Improvements
PDF
Upcoming changes in MySQL 5.7
PPTX
Proxysql use case scenarios fosdem17
PDF
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
PDF
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
PDF
MySQL configuration - The most important Variables
PDF
MySQL For Linux Sysadmins
PDF
MySQL :What's New #GIDS16
PDF
Optimizing MySQL for Cascade Server
PDF
Using MySQL in Automated Testing
PDF
Mysql server query path
PPTX
MySQL Tech Tour 2015 - 5.7 InnoDB
PDF
Mysql User Camp : 20th June - Mysql New Features
PDF
My sql 5.6&MySQL Cluster 7.3
PPTX
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
PDF
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
MySQL: From Single Instance to Big Data
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Metrics that Matter
MySQL 5.6 - Operations and Diagnostics Improvements
Upcoming changes in MySQL 5.7
Proxysql use case scenarios fosdem17
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
MySQL configuration - The most important Variables
MySQL For Linux Sysadmins
MySQL :What's New #GIDS16
Optimizing MySQL for Cascade Server
Using MySQL in Automated Testing
Mysql server query path
MySQL Tech Tour 2015 - 5.7 InnoDB
Mysql User Camp : 20th June - Mysql New Features
My sql 5.6&MySQL Cluster 7.3
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
Ad

Similar to Understanding MySql locking issues (20)

PDF
MariaDB/MySQL_: Developing Scalable Applications
PPT
Advance MySQL Docstore Features
PDF
MySQL 5.5 Guide to InnoDB Status
ODP
InnoDB: архитектура транзакционного хранилища (Константин Осипов)
PPTX
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
PDF
MySQL 简要介绍
PDF
MySQL Performance Schema in Action
PPT
Mysql Introduction
PPT
PPT
Mysql2
PPT
PDF
MySQL 5.5&5.6 new features summary
PDF
MySQL Storage Engines Basics.
PPT
PHP tips by a MYSQL DBA
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
PDF
Group-2.pdf
PDF
Pldc2012 innodb architecture and internals
PPTX
Ibm db2 case study
PPT
MySQL Atchitecture and Concepts
MariaDB/MySQL_: Developing Scalable Applications
Advance MySQL Docstore Features
MySQL 5.5 Guide to InnoDB Status
InnoDB: архитектура транзакционного хранилища (Константин Осипов)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 简要介绍
MySQL Performance Schema in Action
Mysql Introduction
Mysql2
MySQL 5.5&5.6 new features summary
MySQL Storage Engines Basics.
PHP tips by a MYSQL DBA
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Group-2.pdf
Pldc2012 innodb architecture and internals
Ibm db2 case study
MySQL Atchitecture and Concepts
Ad

More from Om Vikram Thapa (20)

PDF
Next Set of Leaders Series
PDF
Integration Testing at go-mmt
PDF
Understanding payments
PDF
System Alerting & Monitoring
PDF
Serverless computing
PDF
Sumologic Community
PPTX
Postman Integration Testing
PDF
Scalibility
PDF
5 Dysfunctions of a team
PDF
AWS Must Know
PDF
Continuous Feedback
PDF
Sql views, stored procedure, functions
PDF
Confluence + jira together
PDF
Understanding WhatFix
PDF
Tech Recruitment Process
PPTX
Jira Workshop
PPT
Security@ecommerce
PPT
Understanding iis part2
PPT
Understanding iis part1
PPT
.Net framework
Next Set of Leaders Series
Integration Testing at go-mmt
Understanding payments
System Alerting & Monitoring
Serverless computing
Sumologic Community
Postman Integration Testing
Scalibility
5 Dysfunctions of a team
AWS Must Know
Continuous Feedback
Sql views, stored procedure, functions
Confluence + jira together
Understanding WhatFix
Tech Recruitment Process
Jira Workshop
Security@ecommerce
Understanding iis part2
Understanding iis part1
.Net framework

Understanding MySql locking issues

  • 2. Contents  Server Variables  Query Cache  Locking Issues  Internal Locking  External Locking  Concurrent Inserts  Connection Pooling
  • 3. Server Variables The MySQL server maintains many system variables that indicate how it is configured. • Each system variable has its default value. • We can dynamically change these settings using SET command. • SHOW VARIABLES • Currently there are 291 variables defined in MySQL 5.1.6 • SHOW VARIABLES LIKE 'have_query_cache'; • SHOW STATUS LIKE 'Table%';
  • 4. Query Cache • The have_query_cache server system variable indicates whether the query cache is available. • SHOW VARIABLES LIKE 'have_query_cache'; • It totally depends upon query_cache_type and query_cache_size • query_cache_type is of 0,1 and 2 (On DEMAND) • You can set max query_cache_size (1MB) as well as query_cache_min_res_unit (4KB) • SHOW STATUS LIKE '%qcache%';
  • 5. Locking Issues • SHOW STATUS LIKE 'Table%'; To achieve a very high lock speed, MySQL uses table locking (instead of page, row, or column locking) for all storage engines except InnoDB and NDBCLUSTER. • Internal Locking • External Locking • Concurrent Inserts
  • 6. Internal Locking Performed within the MySQL server itself to manage contention for table contents by multiple sessions. MySQL grants table write locks as follows: -If there are no locks on the table, put a write lock on it.Otherwise, put the lock request in the write lock queue. MySQL grants table read locks as follows: -If there are no write locks on the table, put a read lock on it.Otherwise, put the lock request in the read lock queue.
  • 7. External Locking • External locking is used in situations where a single process such as the MySQL server cannot be assumed to be the only process that requires access to tables. • If you run multiple servers that use the same database directory, each server must have external locking enabled. • With external locking in effect, each process that requires access to a table acquires a file system lock for the table files before proceeding to access the table.
  • 8. External Locking • External locking affects server performance because the server must sometimes wait for other processes before it can access tables. • The easiest way to satisfy these conditions is to always use --external-locking together with • skip_external_locking = OFF • SET delay-key-write=OFF • SET query-cache-size=0.
  • 9. Concurrent Inserts • The MySQL storage engine supports concurrent inserts to reduce contention between readers and writers for a given table • An INSERT statement can be executed to add rows to the end of the table at the same time that SELECT statements are reading rows from the table. • If there are multiple INSERT statements, they are queued and performed in sequence, concurrently with the SELECT statements.
  • 10. Concurrent Inserts - concurrent_insert = 0, 1, 2 0) If concurrent_insert is set to 0, concurrent inserts are disabled. 1) By default, the variable is set to 1 and concurrent inserts are handled. 2) If the variable is set to 2, concurrent inserts at the end of the table are permitted even for tables that have deleted rows(holes).
  • 11. Connection Pooling • By default, connection pooling is enabled in ADO.NET, Unless you explicitly disable it. • Only connections with the same configuration can be pooled. ADO.NET keeps several pools at the same time, one for each configuration. • Connections are separated into pools by connection string, and by Windows identity when integrated security is used. • A connection pool is created for each unique connection string.
  • 12. Connection Pooling - Connections are added to the pool as needed, up to the maximum pool size specified (100 is the default). - Connections are released back into the pool when they are closed or disposed. - If MinPoolSize is either not specified in the connection string or is specified as 0, the connections in the pool will be closed after a period of inactivity. - However, if the specified MinPoolSize is greater than zero, the connection pool is not destroyed until the AppDomain is unloaded and the process