Commit e65c4ba7dedcbf34eb292c1fd19f7fb2b25a6078
1 parent
bfd14a387e
Exists in
master
File read time remote and local
Showing 4 changed files with 68 additions and 16 deletions Side-by-side Diff
filesystem/file_read_time.c
View file @
e65c4ba
... | ... | @@ -8,11 +8,10 @@ |
8 | 8 | #include <stdlib.h> |
9 | 9 | #include <sys/time.h> |
10 | 10 | #define BLOCK_SIZE 512 |
11 | + | |
11 | 12 | void main() |
12 | 13 | { |
13 | - char fname[20]="/mnt/file_"; | |
14 | - char *fno[] = {"1", "2", "3", "4", "5", "6", "7"}; | |
15 | - char *file; | |
14 | + char *fnames[] = {"file1", "file2", "file3", "file4", "file5", "file6", "file7"}; | |
16 | 15 | char buffer[BLOCK_SIZE] __attribute__ ((__aligned__ (512))); |
17 | 16 | struct timeval start, end; |
18 | 17 | int fd=0, count = 0; |
19 | 18 | |
20 | 19 | |
... | ... | @@ -20,21 +19,15 @@ |
20 | 19 | unsigned long long time; |
21 | 20 | int status; |
22 | 21 | for (i = 0; i < 7; i++) { |
23 | - count = 0; | |
24 | - file = strcat(fname, fno[i]); | |
25 | - printf("File %d: %s\n", i, file); | |
22 | + count = 0; //count number of blocks | |
23 | + printf("File %d: %s\n", i, fnames[i]); | |
26 | 24 | fflush(NULL); |
27 | - //fd = open(file, O_RDONLY); | |
28 | - fd = open(file, O_RDONLY | O_DIRECT | O_SYNC); | |
25 | + fd = open(fnames[i], O_RDONLY | O_DIRECT); | |
29 | 26 | if (!fd) { |
30 | 27 | printf("unable to open\n"); |
31 | 28 | exit(0); |
32 | 29 | } |
33 | 30 | posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM); |
34 | - // while(read(fd, buffer, BLOCK_SIZE)){ | |
35 | - // count++; | |
36 | - // } | |
37 | -// lseek(fd, 0, SEEK_SET); | |
38 | 31 | printf("You are here\n"); |
39 | 32 | gettimeofday(&start, NULL); |
40 | 33 | for (j = 0; j < 10; j++) { |
... | ... | @@ -50,7 +43,6 @@ |
50 | 43 | printf("timestamp %llu - %llu\n", end.tv_sec*1e6+end.tv_usec, start.tv_sec*1e6+start.tv_usec); |
51 | 44 | printf("time taken to read file # %d - %f\n", i, time/((float)count*10)); |
52 | 45 | |
53 | - | |
54 | 46 | sync(); |
55 | 47 | status = system("sudo /sbin/sysctl vm.drop_caches=3"); |
56 | 48 | sync(); |
57 | 49 | |
... | ... | @@ -67,9 +59,6 @@ |
67 | 59 | sync(); |
68 | 60 | status = system("sudo /sbin/sysctl vm.drop_caches=3"); |
69 | 61 | sync(); |
70 | - strcpy(fname, "/mnt/file_"); | |
71 | 62 | } |
72 | - | |
73 | - | |
74 | 63 | } |
filesystem/file_read_time.o
View file @
e65c4ba
filesystem/file_read_time_remote.c
View file @
e65c4ba
1 | +#define _GNU_SOURCE | |
2 | +#include <stdio.h> | |
3 | + | |
4 | +#include <sys/types.h> | |
5 | +#include <sys/stat.h> | |
6 | +#include <fcntl.h> | |
7 | +#include <string.h> | |
8 | +#include <stdlib.h> | |
9 | +#include <sys/time.h> | |
10 | +#define BLOCK_SIZE 512 | |
11 | + | |
12 | +void main() | |
13 | +{ | |
14 | + char *fnames[] = {"/mnt/file1", "/mnt/file2", "/mnt/file3", "/mnt/file4", "/mnt/file5", "/mnt/file6", "/mnt/file7"}; | |
15 | + char buffer[BLOCK_SIZE] __attribute__ ((__aligned__ (512))); | |
16 | + struct timeval start, end; | |
17 | + int fd=0, count = 0; | |
18 | + int i, j; | |
19 | + unsigned long long time; | |
20 | + int status; | |
21 | + for (i = 0; i < 7; i++) { | |
22 | + count = 0; //count number of blocks | |
23 | + printf("File %d: %s\n", i, fnames[i]); | |
24 | + fflush(NULL); | |
25 | + fd = open(fnames[i], O_RDONLY | O_DIRECT); | |
26 | + if (!fd) { | |
27 | + printf("unable to open\n"); | |
28 | + exit(0); | |
29 | + } | |
30 | + posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM); | |
31 | + printf("You are here\n"); | |
32 | + gettimeofday(&start, NULL); | |
33 | + for (j = 0; j < 10; j++) { | |
34 | + count = 0; | |
35 | + while(BLOCK_SIZE == read(fd, buffer, BLOCK_SIZE)) { | |
36 | + count++; | |
37 | + } | |
38 | + lseek(fd, 0, SEEK_SET); | |
39 | + } | |
40 | + gettimeofday(&end, NULL); | |
41 | + printf("You are here2\n"); | |
42 | + time = (end.tv_sec*1e6+end.tv_usec) - (start.tv_sec*1e6+start.tv_usec); | |
43 | + printf("timestamp %llu - %llu\n", end.tv_sec*1e6+end.tv_usec, start.tv_sec*1e6+start.tv_usec); | |
44 | + printf("time taken to read file # %d - %f\n", i, time/((float)count*10)); | |
45 | + | |
46 | + sync(); | |
47 | + status = system("sudo /sbin/sysctl vm.drop_caches=3"); | |
48 | + sync(); | |
49 | + | |
50 | + gettimeofday(&start, NULL); | |
51 | + for (j = 0; j < 1000; j++) { | |
52 | + pread(fd, buffer, BLOCK_SIZE, BLOCK_SIZE*(rand()%count)); | |
53 | + } | |
54 | + gettimeofday(&end, NULL); | |
55 | + time = (end.tv_sec*1e6+end.tv_usec) - (start.tv_sec*1e6+start.tv_usec); | |
56 | + printf("timestamp %llu - %llu\n", end.tv_sec*1e6+end.tv_usec, start.tv_sec*1e6+start.tv_usec); | |
57 | + printf("time taken to read file # %d - %f\n", i, time/1000.0); | |
58 | + | |
59 | + sync(); | |
60 | + status = system("sudo /sbin/sysctl vm.drop_caches=3"); | |
61 | + sync(); | |
62 | + } | |
63 | +} |
filesystem/file_read_time_remote.o
View file @
e65c4ba