Download - All IT eBooks

Transcript
The third kind of resources are those shared by all threads, usually internal caches.
With such options, you generally don’t need to worry that adding more connections
will increase memory usage. One potential issue with them, though, is that changing
the data can invalidate the cache and cause subsequent statements to take longer.
Usually this is a very quick operation, but if a cache is very large, invalidation can take
a long time, so this can affect the user while a thread waits for the cache to become
accessible again.
Finally, performance can run up against limits on operating resources such as file
descriptors and CPU. The number of file descriptors available on the system limits the
number of connections the server can make, the number of tables that can be opened
simultaneously, and even the number of partitions in a single table. You may find it
impossible even to open a table if it has more partitions than available file descriptors.
We will discuss how the operating system can affect MySQL in Chapter 4.
Other Locking Issues
Other resources that can affect your application are internal locks and mutexes acquired
when the server executes particular operations. Most of them protect data integrity.
With a few exceptions, such as InnoDB mutexes and spin locks, you cannot and should
not try to control them, but because a few of them can become visible to user applications, I’ll describe them here.
Transactions can create race conditions and therefore deadlocks, but so can other
activities. When the MySQL server starts using a resource such as a file or modifies a
variable that is shared between threads, it locks access to the resource to prevent concurrent access to the same resource by other threads. This is done for data consistency.
But at the same time, such protection can lead to deadlocks.
These deadlocks are hard to diagnose and theoretically should never happen, but
because they have turned up in the past, I’ll describe what to do when you suspect it.
As an example, I will create a deadlock of this kind using a test case from a bug report.
This bug is not related to troubleshooting a metadata lock (MDL), so I will concentrate
on just the debugging aspect, not on the actions that led to the deadlock.
It might seem artificial to illustrate a problem caused by a MySQL bug
instead of a user error, but the message is useful. Nobody is insured
against hitting a bug, and it is good to be prepared. Forewarned is
forearmed.
The symptoms of a “resource” deadlock are the same as for deadlocks caused by row
locking: queries just hang. No internal mechanism can find such a deadlock and kill it,
so don’t expect that the thread will time out (as with an InnoDB lock) or immediately
Other Locking Issues | 79