-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench-clnt.c
More file actions
85 lines (72 loc) · 2.11 KB
/
Copy pathbench-clnt.c
File metadata and controls
85 lines (72 loc) · 2.11 KB
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
#include "lib/request.h"
#include "lib/utils.h"
int CLNT_ID = -1;
void cleanup(void) {
#ifdef LOG
err_msg("Client %d: shutting down...", CLNT_ID);
#endif /* LOG */
config_destroy();
#ifdef LOG
err_msg("Client %d: everything's cleaned up!", CLNT_ID);
#endif /* LOG */
}
int msleep(long tms) {
struct timespec ts;
int ret;
if (tms < 0) {
errno = EINVAL;
return -1;
}
ts.tv_sec = tms / 1000;
ts.tv_nsec = (tms % 1000) * 1000000;
do {
ret = nanosleep(&ts, &ts);
} while (ret && errno == EINTR);
return ret;
}
int main(int argc, char *argv[]) {
if (argc != 4) {
err_quit("usage: %s <config_file> <client_ID> <req_count>\n", argv[0]);
}
config_init(argv[1]);
CLNT_ID = (int) strtol(argv[2], NULL, 10);
long req_count = strtol(argv[3], NULL, 10);
atexit(cleanup);
printf("make sure all the replicas are running. Press ENTER to continue...\n");
getchar();
char msg_buf[MAXLINE];
XDR out_xdrs;
write_int(msg_buf, CLIENT_REQUEST);
request req;
int view_num = 0;
request_init(&req, CLNT_ID, 0, "random bench op");
TIME_T start, end;
Gettimeofday(&start, NULL);
#ifdef LOG
err_msg("Client %d: begin sending...", CLNT_ID);
#endif /* LOG */
int sockfd = Tcp_connect(SRV_ADDRS[view_num], SRV_PORTS[view_num]);
for (long i = 0; i < req_count; ++i) {
req.req_num++;
xdrmem_create(&out_xdrs, msg_buf + 4, MAXLINE - 4, XDR_ENCODE);
if (xdr_request(&out_xdrs, &req)) {
#ifdef LOG
err_msg("Client %d: sending request %d to replica %d", CLNT_ID, req.req_num, view_num);
#endif /* LOG */
Writen(sockfd, msg_buf, xdr_getpos(&out_xdrs) + 4);
} else {
#ifdef LOG
err_msg("Client %d: failed to encode request %d", CLNT_ID, req.req_num);
#endif /* LOG */
}
xdr_destroy(&out_xdrs);
}
Gettimeofday(&end, NULL);
#ifdef LOG
err_msg("Client %d: done!", CLNT_ID);
#endif /* LOG */
printf("done - total time: %ld ms\n", time_diff_ms(end, start));
Close(sockfd);
xdr_free((xdrproc_t) xdr_request, &req);
return 0;
}