目录
背景
在有一篇blog《用取样思想一探AIX上进程性能瓶颈》中我曾经提到一个客户问题:“磁盘被占满了,通过调查得知有个我们的进程刷数据刷的特变慢,于是就得查这个进程到底慢在哪?”。
我在研究时顺便比较了下顺序写与随机写直接的速度差距。
试验程序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FILENAME "AA"
#define BLOCK_SIZE 4096
#define FILE_SIZE (1024 * 1024 * 1024)
int main(int argc, char* argv[]) {
if(argc!=2){printf("usage: %s [steps]\n", argv[0]); exit(1);}
FILE *fp;
char *block = malloc(BLOCK_SIZE);
memset(block, 'A', BLOCK_SIZE);
fp = fopen(FILENAME, "wb+");
if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}
int i=