在可扩展性方面,客户的要求变得越来越多,功能列表上经常会出现20条、50条甚至多达100多条要求,但总的来说,我们可以把它们缩短为五个大类,通过五条途径来解决可扩展性问题: 1. 调整查询操作 对查询进行优化能够让你付出最少的精力就得到最多的成果。将
在可扩展性方面,客户的要求变得越来越多,功能列表上经常会出现20条、50条甚至多达100多条要求,但总的来说,我们可以把它们缩短为五个大类,通过五条途径来解决可扩展性问题:
1. 调整查询操作
对查询进行优化能够让你付出最少的精力就得到最多的成果。将查询功能完善的发挥出来,达到业务需求,不会被过多的流量和过重的载荷压倒。这就是为什么我们经常看见客户碰到的麻烦越来越多,随着他们网站的访问量越来越大,可扩展性的挑战也变得越来越严重,这就是问题的所在。对网站角落里那些不常用的页面做查询优化是并不必要的,那些页面并不会收到真实世界的流量。根据反映对网络应用做一定的调整是很普遍的做法,而且效果很好。
查询优化需要启用缓慢查询日志并且不断观察。使用mk-query-digest这个Maatkit套件中的强大工具来分析日志,而且要确定设置了log_queries_not_using_indexes。一旦你发现某个查询严重占用资源,那就要优化它。使用EXPLAIN解释机制,使用profiler,观察索引的使用情况,创建失踪的索引,理解它是怎么进行添加和排序的。
2.使用Master-Master复制
Master-Master的active-passive复制模式,或者称为循环复制,不仅能带来高可用性,也能够带来高度的可扩展性。这是因为你能够即刻给你的应用分配到一块只读的从属盘。许多网络应用都按照80/20的规律来分割,80%的活动用来进行读取或SELECT,剩下的分配给INSERT和UPDATE。配置你的应用或者进行重新架构,把读取需要的流量发送到从盘,这样做是可行的,这种类型的横向可扩展能力可以进一步延伸,在必要时能够附加更多块只读从盘。
3. 使用存储
这听起来是很基础的东西,也很直接,但是经常会被忽视,你至少应该确认设置了这些:
- innodb_buffer_pool_size
- key_buffer_size (MyISAM索引缓存)
- query_cache_size – 使用大型SMP时需要小心
- thread_cache & table_cache
- innodb_log_file_size & innodb_log_buffer_size
- sort_buffer_size, join_buffer_size, read_buffer_size, read_rnd_buffer_size
- tmp_table_size & max_heap_table_size
4. 磁盘读取的RAID
你的数据库下面是什么?不知道吗,请找出来。你是在用RAID 5吗?这对于性能来说可是一个巨大的阻碍。RAID5的插入和更新操作速度很慢,而且如果你丢失了一块硬盘,RAID 5在重建时几乎无能为力。RAID 5实在是太慢了,那么应该用什么代替它呢?用RAID 10做镜像和分段,这就可以充分利用你的服务器或机箱里的所有硬盘了。即使你的内存能够容纳下整个数据库,依然需要对硬盘进行许多读取操作。为什么呢?因为比如排序操作需要重新安排行列,群组和联接等等也一样,还有添加交易日志等等这些都是磁盘I/O操作。
5. 调整Key参数
另外,有些附加的参数也可以用来提高性能:
innodb_flush_log_at_trx_commit=2
它可以极大的提升insert和update的速度,只是在清除innodb日志缓冲区时有点偷懒。你可以对它多做些研究,但大多数情况下是非常值得推荐的。
innodb_file_per_table
innodb开发就像Oracle,存储方面使用的是tablespace模式。显然内核开发者们做的并不完善,因为使用单独tablespace的默认设置就会出现性能瓶颈。这个参数设置可以帮助innodb为每个表创建tablespace和数据文件,就像MyISAM所做的一样。
文章出自:Dzone
译文出自:PHPchina
(责任编辑:夏梦竹)

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

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