MySQL InnoDB Performance Tuning for the Solaris 10 OS
Abstract: You can maximize the performance of MySQL on the Solaris platform through configuration and tuning of the database server, along with optimizing the Solaris OS for MySQL. This paper is intended to help you define tuning parameters and tune them in your environment. Contents Introduction MySQL is one of the world's most popular open source databases. A key strength of the MySQL database is its excellent performance and scalability, making it well suited to serve as a back end for web sites, data warehousing, and other data-intensive applications in the enterprise environment. To maximize the performance of MySQL on the Solaris Operating System, database server configuration and tuning are important, as well as the optimization of the Solaris OS for MySQL. However, no universal MySQL server tuning parameters apply to all workloads on all platforms; the appropriate parameters will depend on your particular workload, hardware and OS platform, and MySQL usage. This paper is intended to help you define these parameters and tune them in your environment. MySQL includes several storage engines, including MyISAM, InnoDB, HEAP, and Berkeley DB (BDB). InnoDB and BDB storage support Atomic, Consistent, Isolation, and Durable (ACID) transactions with commit, rollback, and crash recovery capabilities, and only InnoDB storage supports row-level locks with queries running as non-locking consistent reads by default. The InnoDB storage engine supports all four isolation levels: read uncommitted, read committed, repeatable read, and serializable. InnoDB also has the feature known as referential integrity with foreign key constraints support, and it supports fast record lookups for queries using a primary key. Because of these and other powerful functions and features, InnoDB is often used in large, heavy-load production systems. This paper covers the different ways to improve the use of CPU, memory, and disk drive resources for the Solaris 10 OS. Topics include using optimized libraries, compiling 64-bit MySQL with Sun Studio 11 software, tuning the Solaris UFS file system, and MySQL server configuration and tuning for the InnoDB storage engine on the Solaris platform. InnoDB User Threads MySQL is a single-process, multithreaded application. One master thread has the highest priority among all the MySQL threads to control the server. The main thread is idle most of the time and “wakes up” every 300 milliseconds (msec) to check whether an action is required, such as flushing dirty blocks in the buffer pool. In addition to the main threads, a dedicated set of user threads run at normal priority in the thread pools to handle simultaneous client requests. For each client request, one single thread is created to process the client request and send back the result to each client once the result is ready. And there is one single user thread that waits for input from the console and a group of utility threads running at lower priority to handle some background tasks. Right now, MySQL cannot scale well with the number of the user threads handling client requests. Performance scales up efficiently with each additional user thread until it reaches the peak performance point. After that, increasing the number of user connections will decrease MySQL performance because of thread concurrency contention. For applications where the number of user connections is tunable, you need to determine -- for different workloads -- the optimum number of user connections for peak performance. We ran the SysBench CPU-bound benchmark test (1M-row data can be filled in the InnoDB data and index cache buffer) on a four-way UltraSPARC IV processor-based server. MySQL performance peaked at 16 user connections, and started to drop from 32 user connections, as shown in the following graph. (Please note: Results may vary.)
This test shows that for the SysBench workload, peak MySQL performance on the UltraSPARC IV processor-based server can be achieved by setting the number of user connections as 4*CPUs on a 1-4 CPU system. The peak MySQL performance scales in a nearly linear fashion up to 4 CPUs, and the scalability ratio starts to drop from 8 CPUs. The following figure shows the scalability test result using systems with 1-24 UltraSPARC IV processors. (Please note: Results may vary.)
For applications where the number of user connections is not tunable, the Using the Optimized Time Library to Minimize the time (2) System CallOn the Solaris platform, the
On the Solaris platform, we can optimize the Using the Solaris OS mtmalloc Memory Allocator in MySQLThe MySQL actively uses To use If it is 32-bit MySQL, preload
If it is 64-bit MySQL, set
MySQL 5.0 GA binary for Solaris OS released by MySQL has been built to use Using 64-bit MySQL on the Solaris Platform The Solaris OS is a full 64-bit computing environment providing binary compatibility with 32-bit applications, so that both 64-bit and 32-bit MySQL can run well on the Solaris platform. Compared to 32-bit MySQL, 64-bit MySQL can address more memory for the data cache, code cache, and metadata caches inside MySQL to reduce disk I/O. In addition, with wider CPU operations in the 64-bit computing environment, 64-bit MySQL operates faster than 32-bit MySQL. The following figure depicts the performance data in the SysBench CPU-bound test (1M-row data can be filled in the InnoDB data and index cache buffer) on an 8-way UltraSPARC IV based server. (Note: Results may vary.)
Building MySQL With Sun Studio 11 Software To build 64-bit MySQL on the Solaris platform using the Sun Studio 11 release, use the compiler flags and configuration options as shown here: With the Solaris OS for x64 platforms:
With the Solaris OS for SPARC platforms:
To compare the performance of the MySQL database built with different compiler releases (Sun Studio 10 and Sun Studio 11), we used the DBT2 test suite. The workload represents a wholesale parts supplier operating out of a number of warehouses and associated sales districts. The tasks involve the mixture of read-only and update-intensive transactions to enter and deliver orders, record payments, check the status of the orders, and monitor the level of stock at the warehouses. The nine tables include Warehouse, District, Item, Stock, Customer, Order, New order, Order-line and History, scaling with the number of warehouses (except the Item table). We ran the DBT2 test using the 10-warehouse database on the Solaris 10 OS on four dual-core 2200-MHz AMD Opteron processor-based Sun Fire x64 servers. In this test case, most database queries were cached in the
In addition to the optimized performance improvement for the MySQL database that Sun Studio 11 offers compared to Sun Studio 10 in the x64 architecture-based system, Sun Studio 11 also provides the multicore and chip multithreading (CMT) optimizations in the UltraSPARC processor-based system. The Sun Studio 11 release also includes an advanced graphical debugger tool to easily set breakpoints, examine variables, navigate the call stack, and debug the multithreaded code inside MySQL. The sophisticated performance analysis tool in Sun Studio 11 software provides additional data space profiling ability on the UltraSPARC processor-based system to evaluate the performance costs associated with the application memory references. The detailed instructions on how to use these new features in the debugger and performance analyzer tools in Sun Studio 11 software can be found in the comprehensive user guide. Sun Studio 11 software also bundles the Optimizing File System Performance File system cluster size can have a big impact on system performance -- particularly when MySQL is running a workload with a database size much bigger than system memory. On the Solaris platform, UFS file system cluster size (the One way to solve this problem is to reduce the value of the Another solution is to enable file system Direct I/O by mounting the file system with the option
InnoDB Data and Index Cache Size MySQL doesn't access the disk directly; instead, it reads data into the internal buffer cache, reads/writes blocks, and flushes the changes back to the disk. If the server requests data available in the cache, the data can be processed right away. Otherwise, the operating system will request that the data be loaded from the disk. The bigger the cache size, the more disk accesses can be avoided. The default value of 8 Mbytes is too small for most workloads. You will need to increase this number when you see that However, you should not set the value of the Transaction Log Flushing Mode InnoDB flushes the transaction log to disk approximately once per second in the background. As a default, the log flushes to the disk on each transaction commit. The safest way to avoid transaction loss in the event of MySQL, OS, or hardware crashes is to use the mode For workloads running with many short transactions, you can reduce disk writing by setting the When setting this value at 0, there is no log flushing on each transaction commit. It can reduce the disk I/O to improve performance, however, the transaction might be lost if MySQL crashes. When setting this value at 2, the log flushes to the OS cache (file system cache) instead of the disk on each transaction commit. It can also reduce the disk I/O and perform a little slower than when the value is set at 0; however, no transaction loss occurs in the event that MySQL crashes (although a loss will probably occur if the OS or hardware crashes). Log Buffer Size For large transactions, before the log buffer is flushed on each transaction commit, if your setting innodb_flush_log_at_trx_commit is at 1, the log can be loaded into the log buffer instead of flushing to the disk in the background to reduce the disk I/O. If you see large log I/O in the show innodb status output at runtime, you probably need to set a larger value for the innodb_log_buffer_size parameter. For most workloads without long transactions, it is not necessary to waste memory resources by setting a higher value for the log buffer. It is usually fine to set it between 8 and 64 Mbytes. Checkpoint Operation The recovery management subsystem inside InnoDB flushes database pages and transaction operations to the log files for the purpose of backup and recovery. It implements a fuzzy checkpoint operation by continually flushing modified database pages from the buffer pool in small batches. InnoDB writes to the log files in a circular fashion, so if the log file has reached the configure limit set by the The size of each log file should be chosen to avoid executing checkpoint operations too often. The bigger log file size reduces disk I/O in checkpointing. You will need to increase this parameter when you see large page writes in the Query Cache Size In addition to the data and index buffer cache, MySQL version 4.0.1 and later has a nice feature called query cache that stores the identical SELECT queries issued by clients to the database server. This makes it possible to locate and re-issue the same queries without repetitive hard parsing activities. MySQL also stores the query's result set in the query cache, which can significantly reduce the overhead of creating complex result sets for queries from the disk or memory caches, reducing both physical and logical I/O. For some applications executing the same queries from user clients, the query cache can greatly improve the response time. The If you see a high value for The Conclusion The outstanding performance and scalability of MySQL can be enhanced even further by tuning the storage engines within MySQL for specific workloads running on Sun systems. While there are many variables that impact performance and many parameters for tuning for each workload, this paper has attempted to provide general guidelines and practical advice to help you optimize the performance of InnoDB on the Solaris platform. We welcome your feedback on this paper and your insights into achieving higher performance for MySQL on Sun systems. Resources
About the Author Luojia Chen is a software engineer in Sun's Market Development Engineering organization, in the open source team. She is currently responsible for MySQL adoption and migration for Sun's latest technologies, and she is focused on making MySQL run and scale well on the Solaris platform. She can be reached at luojia.chen@sun.com. |
0 comments:
Post a Comment