-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposix_bench.c
187 lines (162 loc) · 4.13 KB
/
posix_bench.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <omp.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <syslog.h>
#include "kv_err.h"
#include "fs.h"
#include "log.h"
int vsize = 4 * 1024;
void
kv_init(char *dir)
{
static const char diag[] = "kv_init";
if (dir == NULL)
printf("%s: invalid argument", diag);
fs_inode_init(dir, 0);
}
void
kv_term()
{
}
int
kv_put(void *key, size_t key_size, void *value, size_t value_size)
{
int r = fs_inode_create(key, key_size,
0, 0, 0100644, vsize,
value, 0);
if (r != 0) return r;
return fs_inode_write(key, key_size,
value, &value_size, 0, 0100644, vsize);
}
int
kv_get(void *key, size_t key_size, void *value, size_t *value_size)
{
//*value_size = 0;
return fs_inode_read(key, key_size, value, value_size, 0);
}
int
kv_remove(void *key, size_t key_size)
{
return fs_inode_remove(key, key_size);
}
void
usage(char *prog_name)
{
fprintf(stderr, "Usage: %s [-T nthreads] [-v vsize] "
"[-n n_keys] db_dir\n", prog_name);
fprintf(stderr, "Output: <vsize> <n_keys> <time> "
"<throughput MB/s> <IOPS count/s>\n");
exit(EXIT_FAILURE);
}
#define KEY_SIZE 20
__thread char key[KEY_SIZE], *value;
int
main(int argc, char *argv[])
{
//log_set_priority_max_level(LOG_DEBUG);
int c, ret;
char *db_dir = NULL, nthreads = 1;
size_t i, n_keys = 100000;
size_t osize;
struct timeval tv[2];
double t;
long long total_vsize;
while ((c = getopt(argc, argv, "s:T:v:n:")) != -1) {
switch (c) {
case 'T':
nthreads = atoi(optarg);
break;
case 'v':
vsize = atoi(optarg);
break;
case 'n':
n_keys = atoi(optarg);
break;
default:
usage("pmemkv_bench");
}
}
argc -= optind;
argv += optind;
if (argc == 0)
usage("pmemkv_bench");
db_dir = argv[0];
kv_init(db_dir);
omp_set_num_threads(nthreads);
#pragma omp parallel
if(vsize <= 512) {
if(posix_memalign((void**)&value, 512, 512)){
fprintf(stderr, "memalign error \n");
};
//fprintf(stderr, "vsize = %d, memory = %p \n", 512, value);
}else{
if(posix_memalign((void**)&value, 512, vsize)){
fprintf(stderr, "memalign error \n");
};
//fprintf(stderr, "vsize = %d, memory = %p \n", vsize, value);
}
//value = calloc(vsize, 1);
gettimeofday(&tv[0], NULL);
#pragma omp parallel for private(ret) schedule(static, 1)
for (i = 0; i < n_keys; ++i) {
sprintf(key, "%0*ld", KEY_SIZE - 1, i);
ret = kv_put(key, KEY_SIZE, value, vsize);
if (ret != KV_SUCCESS) {
fprintf(stderr, "put failed %ld \n", i);
/* break; */
}
}
gettimeofday(&tv[1], NULL);
t = tv[1].tv_sec - tv[0].tv_sec
+ .000001 * (tv[1].tv_usec - tv[0].tv_usec);
/* total_vsize = (long long)vsize * i; */
total_vsize = (long long)vsize * n_keys;
printf("put: %d %ld %f %f %f\n", vsize, n_keys, t,
1.0 / 1024 / 1024 * total_vsize / t, .001 * n_keys / t);
gettimeofday(&tv[0], NULL);
sync();
int fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
write(fd, "3", 1);
close(fd);
#pragma omp parallel for private(ret) schedule(static, 1)
for (i = 0; i < n_keys; ++i) {
sprintf(key, "%0*ld", KEY_SIZE - 1, i);
ret = kv_get(key, KEY_SIZE, value, &osize);
sync();
int fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
write(fd, "3", 1);
close(fd);
if (ret != KV_SUCCESS)
fprintf(stderr, "get failed %ld \n", i);
}
gettimeofday(&tv[1], NULL);
t = tv[1].tv_sec - tv[0].tv_sec
+ .000001 * (tv[1].tv_usec - tv[0].tv_usec);
total_vsize = (long long)vsize * n_keys;
printf("get: %d %ld %f %f %f\n", vsize, n_keys, t,
1.0 / 1024 / 1024 * total_vsize / t, .001 * n_keys / t);
gettimeofday(&tv[0], NULL);
#pragma omp parallel for private(ret) schedule(static, 1)
for (i = 0; i < n_keys; ++i) {
sprintf(key, "%0*ld", KEY_SIZE - 1, i);
ret = kv_remove(key, KEY_SIZE);
//if (ret != KV_SUCCESS)
// fprintf(stderr, "%ld \n", i);
}
gettimeofday(&tv[1], NULL);
t = tv[1].tv_sec - tv[0].tv_sec
+ .000001 * (tv[1].tv_usec - tv[0].tv_usec);
total_vsize = (long long)vsize * n_keys;
printf("remove: %d %ld %f %f %f\n", vsize, n_keys, t,
1.0 / 1024 / 1024 * total_vsize / t, .001 * n_keys / t);
kv_term();
return (0);
}