磁盘缓存专题之一 缓存命中和缓存未命中&缓存与缓冲间的差异
在大多数计算机中,缓存是一个很重要的技术。事实上,计算机中的所有数据访问都可以看成是基本缓存概念的某种变体
不论什么时候,只要系统带有多个设备,而这些设备的性能又各不相同,就存在从慢速设备到快速设备不断更换工作地点以改善系统性能的可能性,这就是缓存的基本思想。即数据从一个地点拷贝到另一个地点,使之检索起来更快。虽然这是一个简单概念,但却包含着许多奇思妙想。简单地说,为满足某种预期的未来需要所做的准备即缓存。缓存是一种人类的本性,为了保证充分的物品供应量,需要预先进行计划,然后选择一个能够提供最快服务的地方,存放它们,这就是所谓的可靠物资管理。它也是计算机系统的核心概念,即将需要的信息放在可以最快访问的地方,其描述如图。
缓存的概念可以用于几种设备,这些设备包括:
• 比正常内存更快的高速内存缓存。
• 比磁盘驱动器更快的、由内存芯片组成的磁盘缓存。
• 比通过Internet访问更快的、由磁盘实现的Internet缓存。
本专题主要涉及的是磁盘缓存。通常,用于缓存的内存是易失内存,假如电源切断,存放在缓存中的数据内容将会丢失。从这个意义上说,缓存内存是一个临时存储,但磁盘设备和子系统所使用的缓存是非易失存储。易失(内存)和非易失存储关系如图所示
本篇主题如下:
缓存命中和缓存未命中
缓存与缓冲间的差异
缓存命中和缓存未命中
当I / O操作开始从磁盘缓存而不是从非易失存储中检索数据时,(如磁盘设备或子系统)缓存命中发生。除了提供来自内存的快速响应之外,缓存命中还缩短了I / O路径的距离。如图所示。
另一种情况是,虽然搜索了缓存,但没有发现数据,因此数据必须从非易失存储读取,这就是缓存未命中。由于搜索缓存时需要花费时间,所以缓存未命中增加了I / O操作的时间。缓存未命中工作过程如图所示:
如果缓存实现不理想,将产生很高的未命中率,由于每次缓存未命中都需要花费额外的时间,所以导致系统性能的下降。用于描述缓存相对精确度的术语叫缓存命中率,缓存命中率是缓存命中数除以I / O请求总数所得的结果。对于开放系统服务器,如UNIX、Win NT及NETWare系统等,通常的命中率率不超过50 %。顺便指出,由于大型计算机系统使用的数据访问方法不同,它能到达更高的命中率(90 %)。
缓存命中率的计算如下:
缓存与缓冲间的差异
“缓存”和“内存”有时可以互换使用。然而,磁带驱动器中的内存通常并不是缓存,而是缓冲。虽然它们的物理组成是一样的,但缓冲只起临时存储数据的作用,由此数据从一个位置或设备传到另一个位置或设备。一般地,缓冲是在生命期较短的进程控制下工作,一旦数据传输完毕,这些进程将立即释放内存地址。一种常见类型的缓冲是F I F O缓冲,即一种先进先出结构,其结构如图所示:
另一方面,缓存内存由一个或更多的系统算法所控制,这些算法在一个长时间里维护和管理着内存资源,缓存的数据可以长时间地保存在缓存中。
在协调性能有差异的控制器和设备工作方面,缓冲常常能够发挥作用,这种方式的缓冲可以看作是某种转换器。主机I / O控制器上的芯片可以快速地通过I / O路径传输数据,它们的性能可以达到纳秒级,而对于磁盘和磁带驱动器这样一类的机电存储设备,其数据的传输速度只能在微秒范围内。因此,设备制造商把缓冲内存放入设备中,以减少访问延迟,以适合主机控制器的性能。这样,主机控制器可以同时地在多个设备上实施重叠操作,图显示了这种重叠过程。
另一方面,缓存利用更复杂的智能技术决定它将存储什么数据。缓冲是由相对简单的内存芯片构成,这些芯片不停地卸出和填充,但是磁盘缓存算法运用复杂的逻辑处理:那些数据应存放在缓存中,那些数据应从缓存中撤出。根据应用的不同,这些缓存的算法变化很大。
缓存算法既可以在主机软件中实现,也可以在存储子系统或在主机控制器中实现。当缓存由一块电子线路实现时,它被称为缓存控制器,除了管理磁盘缓存内存中的内容外,它还可以控制子系统中的磁盘操作,这些操作的细节是下一章的主要论题。图显示了带有一个缓存控制器和缓存内存的磁盘缓存结构:

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.
