|
Io performance is crucial to a system. After a system is optimized in multiple ways, the bottleneck often falls into the database. After the database is optimized in multiple ways, the bottleneck eventually falls into the I/O. The development of Io performance lags behind the development of CPU. Memchached or nosql, these popular technologies are directly or indirectly behind the IO bottleneck, thus improving system performance.
IoSystem hierarchy:
There are many layers, but there are three parts in total.Disk(Storage ),VM(Volume management) andFile System. The terminology is not easy to understand. For example, a disk is equivalent to a space to be used, and an LVM is equivalent to a wall on the space (dividing the space into multiple parts ); the file system is equivalent to a building built on each open space (which determines how many rooms are there, how the house number is, and how many people can be accommodated, it is equivalent to the data stored in the system.
- File System-how to store data?
Corresponding filesystem and buffer cache.
Filesystem(File System): solves the problem of space management.That is, how to store and read data.
Buffercache: Solve the data buffer problem. Cache read and write data, that is, the data frequently used in the cache. Write and buffer data, buffer certain data, and write data at a time.
- VM-what if the disk space is insufficient?
The corresponding VOL Mgmt.
In fact, VMS are not necessarily related to Io. It is a layer in the middle of the file system and disk (storage.VMThe impact of underlying disks on upper-layer file systems is shielded.. When there is no Vm, the file system directly uses the address space on the storage, so the file system is directly restricted by the physical hard disk. In this case, if the disk space is insufficient, it would be a nightmare for applications. They had to add hard disks and then copy data again. The VM can achieve dynamic expansion without affecting the file system. In addition, the VM can also combine multiple disks into one disk to present a unified address space to the file system. This feature is self-evident in its lethality.
- Storage-where is the data stored? How to access it? How to Increase Io speed?
Corresponding Device Driver, Io channel, and disk device
Data will eventually be stored here. Therefore, efficiency, data security, and disaster tolerance are issues that need to be considered here. To improve the storage performance, you can directly improve the performance of physical Io.
2. Logical Io vs physical Io
Logical Io is the IO initiated by the operating system. This data may be stored on the disk or in the memory (the cache of the file system.
Physical Io is the IO initiated by the device driver, and the data will eventually be stored on the disk.
Logical IO does not correspond to physical Io one by one.
This part is often seen in network programming, but it is similar in all Io processing.
IoRequestedTwo Phases:
Waiting for resources: IO requests generally need to request special resources (such as disks, ram, and files). When resources are not released by the previous user, IO requests will be blocked, until you can use this resource.
Resource usage phase: Receives and generates data.
For exampleQueuingAndService.
InWaiting for DataIo is divided into blocking Io and non-blocking Io.
Blocking Io: When the resource is unavailable, IO requests are blocked until the feedback result (data or timeout occurs ).
Non-blocking Io: When the resource is unavailable, IO requests exit and return data to identify that the resource is unavailable
InUse resourcesPhase, Io is divided into synchronous Io and asynchronous Io.
Synchronous Io: The application is blocked in the status of sending or receiving data until the data is successfully transmitted or the response fails.
Asynchronous Io: The application returns immediately after sending or receiving data. The data is written to the OS cache. The OS sends or receives the data and returns success or failure information to the application.
According to UnixOf 5I/OModel Division
- Blocking Io
- Non-blocking Io
- Io multiplexing
- Signal-driven I/O
- Asynchronous Io
In terms of performance, the performance of asynchronous Io is undoubtedly the best.
Various IoFeatures
- Blocking Io: Simple to use, but the problem that comes with it is blocking, which requires the cooperation of independent threads, which are not computed in most cases. Java bio uses this method, and the problem is obvious. A socket requires an independent thread, which causes thread expansion.
- Non-blocking Io: Uses the round-robin method to avoid thread blocking. Java NiO uses this method, which has obvious advantages over bio. You can use a single thread to listen to all Sockets (select ). This greatly reduces the number of threads.
- Synchronous Io: Synchronous I/O ensures that a result is returned only after an I/O operation is completed. Therefore, the synchronization I/O efficiency is lower, but the programming method is simple for applications. Java bio and NiO both use this method for data processing.
- Asynchronous Io: Because asynchronous IO requests are only written to the cache, it is unknown whether the cache is successful to the hard disk. Therefore, asynchronous Io is equivalent to splitting an IO into two parts. One is to initiate a request, the second is to obtain the processing result. Therefore, application complexity is increased. However, the performance of asynchronous Io is all good, And the asynchronous idea runs through the IT system.
|