- 论坛徽章:
- 0
|
原帖由 jamesr 于 2009-2-5 14:43 发表
能说说你是怎么测试的吗?
别告诉我你所谓的性能下降就是唤醒一个被swap到磁盘的程序时间变长了。
我实际测试的例子就是一直读不断增大的文件然后处理数据发给另外一个服务
我写了一个写 和 读文件的例子看看, 大家有兴趣都测试一下 看看是否会出现系统效率下降的问题,
最好找一个空间大一点的磁盘多测试一段时间, 直到出现swapd 占用很高的时候就知道了。
具体测试先执行写数据的程序:
gcc -o writefile writefile.c -D_FILE_OFFSET_BITS=64 && ./writefile abc.doc &
然后读文件
gcc -o readfile readfile.c -D_FILE_OFFSET_BITS=64 && ./readfile abc.doc &
writefile.c
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <errno.h>
- #define BUF_SIZE 1024 * 1024 * 64
- // gcc -o writefile writefile.c -D_FILE_OFFSET_BITS=64
- int main(int argc, char **argv)
- {
- int fd = 0, n = 0, i = 0;
- char *s = (char *)calloc(1, BUF_SIZE);
- if(argc < 2)
- {
- fprintf(stderr, "Usage:%s file\n", argv[0]);
- _exit(-1);
- }
- if((fd = open(argv[1], O_WRONLY|O_CREAT, 0644)) > 0)
- {
- n = 0;
- while((write(fd, s, BUF_SIZE)) > 0)n++;
- close(fd);
- }
- else
- {
- fprintf(stderr, "open file failed, %s\n", strerror(errno));
- }
- if(s) free(s);
- while(1)sleep(1);
- return 0;
- }
复制代码
gcc -o readfile readfile.c -D_FILE_OFFSET_BITS=64
readfile.c
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <errno.h>
- #define BUF_SIZE 1024 * 1024 * 8
- // gcc -o readfile readfile.c -D_FILE_OFFSET_BITS=64
- int main(int argc, char **argv)
- {
- int fd = 0, n = 0, i = 0;
- char *s = (char *)calloc(1, BUF_SIZE);
- if(argc < 2)
- {
- fprintf(stderr, "Usage:%s file...\n", argv[0]);
- _exit(-1);
- }
- for(i = 1; i < argc; i++)
- {
- if((fd = open(argv[i], O_RDONLY)) > 0)
- {
- n = 0;
- while((read(fd, s, BUF_SIZE)) > 0)n++;
- fprintf(stdout, "times:%d\n", n);
- close(fd);
- }
- else
- {
- fprintf(stderr, "open file failed, %s\n", strerror(errno));
- }
- }
- if(s) free(s);
- while(1)sleep(1);
- return 0;
- }
复制代码
[ 本帖最后由 redor 于 2009-2-5 15:27 编辑 ] |
|