-
Notifications
You must be signed in to change notification settings - Fork 31
/
fq_sndr.c
118 lines (111 loc) · 3.41 KB
/
fq_sndr.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
/*
* Copyright (c) 2013 OmniTI Computer Consulting, Inc.
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include "fq.h"
#define SEND_COUNT 1000
int send_count = SEND_COUNT;
void logger(fq_client c, const char *);
void logger(fq_client c, const char *s) {
(void)c;
fprintf(stderr, "fq_logger: %s\n", s);
}
static void
debug_status(char *key, uint32_t value, void *unused) {
(void)unused;
fq_debug(FQ_DEBUG_CONN, " ---> %s : %u\n", key, value);
}
static void
print_rate(fq_client c, hrtime_t s, hrtime_t f, uint64_t cnt, uint64_t icnt) {
double d;
fq_client_status(c, debug_status, NULL);
if(cnt) {
d = (double)cnt * 1000000000;
d /= (double)(f-s);
printf("[%d backlog] output %0.2f msg/sec\n",
fq_client_data_backlog(c), d);
}
if(icnt) {
d = (double)icnt * 1000000000;
d /= (double)(f-s);
printf("[%d backlog] input %0.2f msg/sec\n",
fq_client_data_backlog(c), d);
}
}
int main(int argc, char **argv) {
hrtime_t s0, s, f, f0;
uint64_t cnt = 0, icnt = 0;
int psize = 0, i = 0;
fq_client c;
fq_msg *m;
char *fq_debug = getenv("FQ_DEBUG");
if(fq_debug) fq_debug_set_bits(atoi(fq_debug));
signal(SIGPIPE, SIG_IGN);
fq_client_init(&c, 0, logger);
if(argc < 5) {
fprintf(stderr, "%s <host> <port> <user> <pass> [size [count]]\n",
argv[0]);
exit(-1);
}
fq_client_creds(c, argv[1], atoi(argv[2]), argv[3], argv[4]);
fq_client_heartbeat(c, 1000);
fq_client_set_backlog(c, 10000, 100);
fq_client_connect(c);
if(argc > 5) {
psize = atoi(argv[5]);
}
printf("payload size -> %d\n", psize);
if(argc > 6) {
send_count = atoi(argv[6]);
}
printf("message count -> %d\n", send_count);
s0 = s = fq_gethrtime();
while(i < send_count || fq_client_data_backlog(c) > 0) {
if(i < send_count) {
m = fq_msg_alloc_BLANK(psize);
memset(m->payload, 0, psize);
fq_msg_exchange(m, "maryland", 8);
fq_msg_route(m, "test.prefix.boo", 15);
fq_msg_id(m, NULL);
fq_client_publish(c, m);
cnt++;
i++;
fq_msg_free(m);
}
else usleep(100);
f = fq_gethrtime();
if(f-s > 1000000000) {
print_rate(c, s, f, cnt, icnt);
icnt = 0;
cnt = 0;
s = f;
}
}
f0 = fq_gethrtime();
print_rate(c, s0, f0, i, 0);
(void) argc;
return 0;
}