Mysql Optimization Overview

8.1 Optimization Overview

 

   Database performance depends on several factors at the database level, such as tables, queries,and configuration settings. These software constructs result in CPU and I/O operations at the hardware level, which you must minimize and make as efficient as possible. As you work on database performance, you start by learning the high-level rules and guidelines for the software side, and measuring performance using wall-clock time. As you become an expert, you learn more about what happens internally, and start measuring things such as CPU cycles and I/O operations.

   数据库性能取决于数据库级别的几个因素,例如表、查询和配置设置。这些软件结构会导致在硬件级别执行CPU和I/O操作,您必须将这些操作最小化并尽可能提高效率。在研究数据库性能时,首先要学习软件方面的高级规则和准则,并使用wall-clock时间来衡量性能。当您成为专家后,您将了解更多关于内部发生的事情,并开始测量诸如CPU周期和I/O操作之类的事情。

 

   Typical users aim to get the best database performance out of their existing software and hardwareconfigurations. Advanced users look for opportunities to improve the MySQL software itself, or develop their own storage engines and hardware appliances to expand the MySQL ecosystem.

   普通用户的目标是从现有的软件和硬件配置中获得最佳的数据库性能。高级用户寻找机会来改进MySQL软件本身,或者开发自己的存储引擎和硬件设备来扩展MySQL生态系统。

 

• Optimizing at the Database Level 

• Optimizing at the Hardware Level 

• Balancing Portability and Performance

 

 

Optimizing at the Database Level

          The most important factor in making a database application fast is its basic design:

           使数据库应用程序快速运行的最重要因素是其基本设计:

             • Are the tables structured properly? In particular, do the columns have the right data types, and does each table have the appropriate columns for the type of work? For example, applications that perform frequent updates often have many tables with few columns, while applications that analyze large amounts of data often have few tables with many columns.

             表格结构是否正确?特别是,列是否具有正确的数据类型,以及每个表是否具有适合工作类型的列?例如,执行频繁更新的应用程序通常具有多个少列的表,而分析大量数据的应用程序通常具有少个多列的表。

 

            • Are the right indexes in place to make queries efficient?

            是否有适当的索引来提高查询效率?

 

           • Are you using the appropriate storage engine for each table, and taking advantage of the strengths and features of each storage engine you use? In particular, the choice of a transactional storage engine such as InnoDB or a nontransactional one such as MyISAM can be very important for performance and scalability.

           您是否为每个表使用了适当的存储引擎,并利用了您使用的每个存储引擎的优势和特性?特别是事务存储的选择引擎(如InnoDB)或非事务引擎(如MyISAM)对于性能和可伸缩性非常重要。

 

Note
           I
nnoDB is the default storage engine for new tables. In practice, the advanced InnoDB performance features mean that InnoDB tables often outperform the simpler MyISAM tables, especially for a busy database.

          InnoDB是新表的默认存储引擎。实际上,先进的InnoDB性能特性意味着InnoDB表的性能通常优于更简单的MyISAM表,特别是对于繁忙的数据库。

 

         • Does each table use an appropriate row format? This choice also depends on the storage engine used for the table. In particular, compressed tables use less disk space and so require less disk I/O to read and write the data. Compression is available for all kinds of workloads with InnoDB tables, and for read-only MyISAM tables.

         每个表是否使用适当的行格式?此选择还取决于用于表的存储引擎。特别是,压缩表使用更少的磁盘空间,因此需要更少的磁盘I/O来读写数据。压缩可用于InnoDB表的各种工作负载,也可用于只读MyISAM表。

 

        • Does the application use an appropriate locking strategy? For example, by allowing shared access when possible so that database operations can run concurrently, and requesting exclusive access when appropriate so that critical operations get top priority. Again, the choice of storage engine is significant. The InnoDB storage engine handles most locking issues without involvement from you, allowing for better concurrency in the database and reducing the amount of experimentation and tuning for your code.

         应用程序是否使用了适当的锁定策略?例如,在可能的情况下允许共享访问,以便数据库操作可以并发运行,并在适当的情况下请求独占访问,以便关键操作获得最高优先级。同样,存储引擎的选择也很重要。InnoDB存储引擎可以处理大多数锁定问题,而不需要您的参与,从而可以在数据库中实现更好的并发性,并减少代码的实验和调优量。

 

       • Are all memory areas used for caching sized correctly? That is, large enough to hold frequently accessed data, but not so large that they overload physical memory and cause paging. The main memory areas to configure are the InnoDB buffer pool, the MyISAM key cache, and the MySQL query cache.

       用于缓存的所有内存区域大小是否正确?也就是说,大到足以容纳频繁访问的数据,但不能大到使物理内存过载并导致分页。要配置的主内存区域是InnoDB buffer pool、MyISAMkey cache和MySQLquery cache。

 

 

Optimizing at the Hardware Level

     Any database application eventually hits hardware limits as the database becomes more and more busy. A DBA must evaluate whether it is possible to tune the application or reconfigure the server to avoid these bottlenecks, or whether more hardware resources are required. System bottlenecks typically arise from these sources:

     随着数据库变得越来越繁忙,任何数据库应用程序最终都会遇到硬件限制。DBA必须评估是否有可能调整应用程序或重新配置服务器以避免这些瓶颈,或者是否需要更多的硬件资源。系统瓶颈通常来自以下来源:

 

    • Disk seeks. It takes time for the disk to find a piece of data. With modern disks, the mean time for this is usually lower than 10ms, so we can in theory do about 100 seeks a second. This time improves slowly with new disks and is very hard to optimize for a single table. The way to optimize seek time is to distribute the data onto more than one disk.

     磁盘搜索。磁盘查找数据需要时间。对于现代磁盘,平均时间通常低于10毫秒,因此理论上我们可以每秒搜索100次。这一时间随着新磁盘的出现而缓慢提高,并且很难针对单个表进行优化。优化寻道时间的方法是将数据分发到多个磁盘上。

 

    • Disk reading and writing. When the disk is at the correct position, we need to read or write the data.With modern disks, one disk delivers at least 10–20MB/s throughput. This is easier to optimize than seeks because you can read in parallel from multiple disks.

    磁盘读写。当磁盘位于正确的位置时,我们需要读取或写入数据。对于现代磁盘,一个磁盘的吞吐量至少为10–20MB/s。这比查找更容易优化,因为您可以并行读取多个磁盘。

 

    • CPU cycles. When the data is in main memory, we must process it to get our result. Having large tables compared to the amount of memory is the most common limiting factor. But with small tables,speed is usually not the problem.

    CPU周期。当数据在主存中时,我们必须对它进行处理才能得到结果。与内存量相比,拥有大表是最常见的限制因素。但是对于小表,速度通常不是问题。

 

    • Memory bandwidth. When the CPU needs more data than can fit in the CPU cache, main memory bandwidth becomes a bottleneck. This is an uncommon bottleneck for most systems, but one to be aware of.

    内存带宽。当CPU需要的数据超过CPU缓存的容量时,主存带宽就成了瓶颈。对于大多数系统来说,这是一个不常见的瓶颈,但需要注意。

 

 

Balancing Portability and Performance

    To use performance-oriented SQL extensions in a portable MySQL program, you can wrap MySQL-specific keywords in a statement within /*! */ comment delimiters. Other SQL servers ignore the commented keywords. For information about writing comments, see Section 9.6, “Comment Syntax”.

    要在可移植的MySQL程序中使用面向性能的SQL扩展,可以将MySQL特定的关键字包装在/*中的语句中!*/注释分隔符。其他SQL服务器忽略已注释的关键字。有关编写注释的信息,请参阅第9.6节“注释语法”。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(MYSQL,mysql)