bitsCN.com
在过往与很多人的交流过程中发现,在谈到基于硬件来进行数据库性能瓶颈分析的时候,常被大家误解为简单的使用更为强劲的主机或者存储来替换现有的设备。
个人觉得这其中可能存在一个非常大的误区。我们在谈论基于硬件进行优化的时候,不能仅仅将数据库使用的硬件划分为主机和存储两部分,而是需要进一步对硬件进行更细的分解,至少也应该分解到如下范畴:
主机
1. CPU:仅仅只能决定运算速度,即使是运算速度都还取决于与内存之间的总线带宽以及内存本身的速度。
2. 内存:大小决定了所能缓存的数据量,主要决定了热点数据的访问速度。
3. 磁盘:
3.1 大小:决定了你最终能存放多少数据量。
3.2 转速:决定了你每一次IO请求的延时时间,也就是决定了我们常说的IOPS和MBPS。
3.3 数目:磁盘数目决定了。
3.4 类型
3.4.1 机械:SAS or SATA or FC ?
3.4.2 SSD:磁盘 or PCI卡?
4. Raid卡:
4.1 缓存:缓存大小对数据写入速度有较大影响,使用策略也会直接影响IO效率。
4.2 电池:电池充放电策略会影响到瞬时IO的波动。
5. 其他:如总线带宽等,决定了CPU与内存间数据传输效率,这一点很多时候关注较少,但也可能会出现瓶颈。
存储
1. 内存:存储设备同样也有内存,用来存储前端主机访问的热点数据。存储的内存大小同样决定了热点数据的访问速度。
2. 磁盘:和主机磁盘类似。
3. 线路/环路带宽:环路带宽必须能够匹配磁盘带宽,至少不能少于磁盘所能输出的能力,否则就想被堵在高速收费站等待通行的车辆一样。
网络
1. 延时:不同的网络设备其延时会有差异,对于 OLTP 设备来说,延时自然是越小越好。
2. 吞吐量:对于数据库集群来说,各个节点之间的网络吞吐量可能直接决定集群的处理能力。
3. iops:对于 OLTP 系统,数据传输更多是以小IO多并发方式,有时候光有大带宽并不一定能满足需求。
硬件角度所能提供的处理能力,一定是上面所列的多个方面(这里仅仅只是主要部分,可能还有其他)共同决定的整体能力,任何一个方面出现瓶颈,都能导致整体性能上不去,也就是我们常说的木桶原理。
在以往的经验中,最容易出现性能瓶颈的地方主要会出现在以下几个方面:
IO资源方面瓶颈
出现 IO 资源方面瓶颈的时候,主要表现在服务器 iowait 很高,usr 占比较少,系统响应较慢,数据库中经常会存在大量执行状态的 session。
遇到 IO 资源方面的瓶颈,我们可以使用的硬件层面优化方案主要就是:
1. 增加内存加大可缓存的数据量:这个方案能否达到效果取决于系统热点数据的总量,毕竟内存的成本也是比较高的,而且单台设备所能管理的内存量也是有限的。
2. 改善底层存储设备的 IO 能力:如本文前面所述,底层存储能力的改善同时取决于多个方面,既有单个磁盘本身的能力问题,也包括磁盘数目方面的策略,同时还受到存储自身以及存储和主机之间的带宽限制。所以在优化底层存储能力的同时需要同时考虑到这3方面的因素,做好总体分析和局部的平衡。
CPU资源方面瓶颈
当 CPU 方面资源遇到瓶颈的时候,主要表现在服务器CPU利用率中 usr 所占比例很高,iowait却很小。这类问题大多出现在数据量并不是太大,同时又有足够内存来对数据进行缓存的应用场景。同时也是目前大多数中小网站所面临的数据库性能瓶颈。
当遇到 CPU 方面的资源瓶颈的时候,可能由两个方面造成:
1. 过多依赖数据库进行逻辑运算:对于这种状况,最好的优化方式是将运算尽可能从数据库端迁移到应用端,降低数据库主机的计算量。毕竟对有状态的系统设备(数据库)进行扩容的成本远高于无状态类系统设备(应用)。当然如果非要从数据库端的硬件来解决问题,那就只有通过增加设备CPU数目(如果支持),或者是使用CPU能力更为高端的主机来替换老主机。
2. 数据库逻辑IO太大:对于这类状况,从硬件角度来说能做的就只有提升CPU处理能力。要么增加 CPU 数目(如果支持),要么换CPU更强劲的主机。但是在这之前,还是建议先尝试从应用角度优化看看是否能够尽量降低非必要请求或者是减少每次请求的数据量。同时从数据库角度针对 Schema结构以及索引进行相应的优化调整,尽可能让完成一次请求所需要检索的数据量更小,从而达到降低逻辑IO的目的。
网络资源方面的瓶颈
一般来说应用与数据库之间的网络交互所需的资源并不是非常大,所以这个环境遇到瓶颈的可能并不是非常大。但是在分布式的集群环境中,各个数据库节点之间的网络环境经常会称为系统的瓶颈。
比较常见的场景如 MySQL Cluster 或者是 Oracle RAC 环境中,节点之间的数据交换网络环境的优劣可能直接影响到系统的整体处理能力,因为在节点间会存在大量的数据交换,都是依赖网络传输来完成。
在这样的场景中,廉价一点的解决方案是通过 万兆交换机 来替换现在常用的 千兆交换机来提升网络处理能力降低网络延时。不过这个方案主要提升的是吞吐量方面,对于延时方面的提升可能并不一定能满足某些要求非常高的场景。这时候就该考虑使用更为昂贵但也更高效的方案:用 Infiniband 替换普通交换机来极大的降低网络方面所带来的数据交换延时。
以上仅仅只针对主要类型的硬件资源瓶颈做了一些分析和相应可能的处理方式,欢迎大家一起探讨,也可以包括目前比较“热”的SSD。后面我可能还会再写一篇关于 SSD 的文章,国内接触 SSD 并将之正式用于核心产品环境的,可能比我更早人还是比较少的。
bitsCN.com
MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.

The main reasons for poor MySQL query performance include not using indexes, wrong execution plan selection by the query optimizer, unreasonable table design, excessive data volume and lock competition. 1. No index causes slow querying, and adding indexes can significantly improve performance. 2. Use the EXPLAIN command to analyze the query plan and find out the optimizer error. 3. Reconstructing the table structure and optimizing JOIN conditions can improve table design problems. 4. When the data volume is large, partitioning and table division strategies are adopted. 5. In a high concurrency environment, optimizing transactions and locking strategies can reduce lock competition.

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function