23 #ifdef HAVE_SYS_WAIT_H
26 #ifdef HAVE_NETINET_IN_H
27 #include <netinet/in.h>
30 #define DEFAULT_PORT 10041
31 #define DEFAULT_HOST "localhost"
32 #define DEFAULT_MAX_CONCURRENCY 10
33 #define DEFAULT_MAX_THROUGHPUT 10000
41 static int proto =
'g';
42 static int verbose = 0;
43 static int dest_cnt = 0;
50 lprint(
grn_ctx *ctx,
const char *fmt, ...)
61 vsnprintf(buf + len, 1023 - len, fmt, argp);
72 if ((d = strchr(deststr,
':'))) {
73 if ((p = atoi(d + 1))) {
88 "Usage: grnslap [options...] [dest...]\n"
90 " -P <protocol>: http or gqtp (default: gqtp)\n"
91 " -m <max concurrency>: number of max concurrency (default: %d)\n"
92 "dest: hostname:port number (default: \"%s:%d\")\n",
96 #define BUFSIZE 0x1000000
115 static int nsent = 0;
116 static int nrecv = 0;
118 static int etime_max = 0;
119 static int64_t etime_amount = 0;
139 if (!s->
stat) {
return; }
153 return session_open(ctx, dest);
165 gettimeofday(&tv, NULL);
166 etime = (tv.tv_sec - s->
tv.tv_sec) * 1000000 + (tv.tv_usec - s->
tv.tv_usec);
167 if (etime > etime_max) { etime_max = etime; }
168 if (etime < etime_min) { etime_min = etime; }
169 if (ctx->
rc) { m->header.proto = 0; }
170 switch (m->header.proto) {
173 etime_amount += etime;
205 if (nsent == nrecv && done) {
break; }
225 struct timeval tvb, tve;
245 if (!THREAD_CREATE(thread, receiver, NULL)) {
247 gettimeofday(&tvb, NULL);
248 lprint(ctx,
"begin: procotol=%c max_concurrency=%d max_tp=%d", proto, max_con, max_tp);
249 while (fgets(buf,
BUFSIZE, stdin)) {
250 uint32_t size = strlen(buf) - 1;
251 session *s = session_alloc(ctx, dests + (cnt++ % dest_cnt));
253 gettimeofday(&s->
tv, NULL);
261 fprintf(stderr,
"grn_com_send_http failed\n");
271 fprintf(stderr,
"grn_com_send failed\n");
276 fprintf(stderr,
"grn_com_copen failed\n");
279 gettimeofday(&tve, NULL);
280 if ((nrecv < max_tp * (tve.tv_sec - tvb.tv_sec)) &&
281 (nsent - nrecv) < max_con) {
break; }
285 if (!(nsent % 1000)) { lprint(ctx,
" : %d", nsent); }
288 if (THREAD_JOIN(thread)) {
289 fprintf(stderr,
"THREAD_JOIN failed\n");
291 gettimeofday(&tve, NULL);
294 uint64_t etime = (tve.tv_sec - tvb.tv_sec);
296 etime += (tve.tv_usec - tvb.tv_usec);
297 qps = (double)nsent * 1000000 / etime;
298 lprint(ctx,
"end : n=%d min=%d max=%d avg=%d qps=%f etime=%d.%06d", nsent, etime_min, etime_max, (
int)(etime_amount / nsent), qps, etime / 1000000, etime % 1000000);
303 session_close(ctx, s);
308 fprintf(stderr,
"THREAD_CREATE failed\n");
312 fprintf(stderr,
"grn_com_event_init failed\n");
329 const char *protostr = NULL, *maxconstr = NULL, *maxtpstr = NULL;
337 {
'\0', NULL, NULL, 0, 0}
339 opts[0].
arg = &protostr;
340 opts[1].
arg = &maxconstr;
341 opts[2].
arg = &maxtpstr;
343 if (protostr) { proto = *protostr; }
344 if (maxconstr) { max_con = atoi(maxconstr); }
345 if (maxtpstr) { max_tp = atoi(maxtpstr); }
352 }
else if (i > 0 && argc <= (i +
MAX_DEST)){
353 for (dest_cnt = 0; i < argc; i++) {
354 parse_dest(argv[i], &dests[dest_cnt]);
355 if (dests[dest_cnt].host) {