Linux performance learning (3.3): IO_How to optimize IO performance


Reference materials:
1. Disk optimization for Linux performance optimization (3)

1 Application Optimization

The core of application optimization is to optimize performance by using cached I/O as much as possible.

For example, use an external cache system similar to Redis to build your own cache system;

Use library functions such as fopen/fread to replace system calls such as open/read, because library functions will have their own cache;

When reading and writing files, do not use DirectI/O(O_DIRECT);

When writing a file, do not use synchronous I/O (O_SYNC), and after writing, explicitly call fsync() /sync() for synchronization;

Put frequently accessed files or data in memory to reduce read and write to disk.

The above method should be chosen according to your actual scenario, such as whether to use synchronous I/O, using synchronous I/O can output the data in the kernel buffer to a file, which can ensure data integrity and data security, but otherwise On the one hand, it will also reduce the performance of the system.

2 File system optimization

Optimize the configuration options of the file system, such as specifying synchronous or asynchronous writing async/sync, disabling atime and other options when mounting;

Optimize the cache of the file system, optimize the refresh frequency and quota of dirty pages, and adjust the value of vfs_cache_pressure to optimize the tendency of the kernel to recycle the directory entry cache and inode cache.

3 Disk Optimization

According to the I/O characteristics of disks and applications, select different I/O scheduling algorithms;
in scenarios where there are many sequential reads, increase the read-ahead data of the disk, you can adjust the kernel option /sys/block/sdb/queue/read_ahead_kb or Use the blockdev tool to set;
optimize the I/O options of the kernel block device, adjust the length of the disk queue, and improve the throughput of the disk.

おすすめ

転載: blog.csdn.net/u011003120/article/details/128286973