1 /* $Id: benchmark.c,v 1.9 2005-10-22 13:13:56 adam Exp $
2 * Copyright (C) 1995-2005, Index Data ApS
4 * This file is part of the YAZ toolkit.
6 * See the file LICENSE.
8 * This is an elementary benchmarker for server performance. It works
9 * by repeatedly connecting to, seaching in and retrieving from the
10 * specified server, and keeps statistics about the minimum, maximum
11 * and average times for each operation.
17 #include <yaz/options.h>
24 int nconnect; /* number of connections to make */
25 int nsearch; /* number of searches on each connection */
26 int npresent; /* number of presents for each search */
27 int full; /* 1 = fetch full records, 0 = brief */
28 int delay; /* number of ms to delay between ops */
29 int random; /* if true, delay is random 0-specified */
30 int verbosity; /* 0 = quiet, higher => more verbose */
42 static int test(char *host, int port);
43 static void db_printf(int level, char *fmt, ...);
44 static void usage(const char *prog);
46 int main(int argc, char **argv)
56 while ((c = options("c:s:p:fbd:rv:", argv, argc, &arg)) != -2) {
66 case 'c': boptions.nconnect = atoi(arg); break;
67 case 's': boptions.nsearch = atoi(arg); break;
68 case 'p': boptions.npresent = atoi(arg); break;
69 case 'f': boptions.full = 1; break;
70 case 'b': boptions.full = 0; break;
71 case 'd': boptions.delay = atoi(arg); break;
72 case 'r': boptions.random = 1; break;
73 case 'v': boptions.verbosity = atoi(arg); break;
74 default: usage(*argv);
81 for (i = 0; i < boptions.nconnect; i++) {
82 db_printf(2, "iteration %d of %d", i+1, boptions.nconnect);
83 ok = test(host, port);
87 db_printf(1, "passed %d of %d tests", nok, boptions.nconnect);
88 if (nok < boptions.nconnect)
89 printf("Failed %d of %d tests\n",
90 boptions.nconnect-nok, boptions.nconnect);
95 static void usage(const char *prog)
97 fprintf(stderr, "Usage: %s [options] <host> <port>\n"
98 " -c <n> Make <n> connection to the server [default: 3]\n"
99 " -s <n> Perform <n> searches on each connection [3]\n"
100 " -p <n> Make <n> present requests after each search [3]\n"
101 " -f Fetch full records [default: brief]\n"
102 " -b Fetch brief records\n"
103 " -d <n> Delay <n> ms after each operation\n"
104 " -r Delays are random between 0 and the specified number of ms\n"
105 " -v <n> Set verbosity level to <n> [0, silent on success]\n"
110 static int test(char *host, int port)
112 ZOOM_connection conn;
114 const char *errmsg, *addinfo;
116 conn = ZOOM_connection_new(host, port);
117 if ((error = ZOOM_connection_error(conn, &errmsg, &addinfo))) {
118 fprintf(stderr, "ZOOM error: %s (%d): %s\n", errmsg, error, addinfo);
122 ZOOM_connection_destroy(conn);
126 static void db_printf(int level, char *fmt, ...)
130 if (level > boptions.verbosity)
133 fprintf(stderr, "DEBUG(%d): ", level);
135 vfprintf(stderr, fmt, ap);
142 * indent-tabs-mode: nil
144 * vim: shiftwidth=4 tabstop=8 expandtab