1 /* $Id: benchmark.c,v 1.4 2004-01-26 21:05:34 mike Exp $
2 * Copyright (C) 2003-2004 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.
23 int nconnect; /* number of connections to make */
24 int nsearch; /* number of searches on each connection */
25 int npresent; /* number of presents for each search */
26 int full; /* 1 = fetch full records, 0 = brief */
27 int delay; /* number of ms to delay between ops */
28 int random; /* if true, delay is random 0-specified */
29 int verbosity; /* 0 = quiet, higher => more verbose */
41 static int test(char *host, int port);
42 static void dprintf(int level, char *fmt, ...);
45 int main(int argc, char **argv)
54 while ((c = getopt(argc, argv, "c:s:p:fbd:rv:")) != -1) {
56 case 'c': options.nconnect = atoi(optarg); break;
57 case 's': options.nsearch = atoi(optarg); break;
58 case 'p': options.npresent = atoi(optarg); break;
59 case 'f': options.full = 1; break;
60 case 'b': options.full = 0; break;
61 case 'd': options.delay = atoi(optarg); break;
62 case 'r': options.random = 1; break;
63 case 'v': options.verbosity = atoi(optarg); break;
68 if (argc-optind != 2) {
70 fprintf(stderr, "Usage: %s [options] <host> <port>\n"
71 " -c <n> Make <n> connection to the server [default: 3]\n"
72 " -s <n> Perform <n> searches on each connection [3]\n"
73 " -p <n> Make <n> present requests after each search [3]\n"
74 " -f Fetch full records [default: brief]\n"
75 " -b Fetch brief records\n"
76 " -d <n> Delay <n> ms after each operation\n"
77 " -r Delays are random between 0 and the specified number of ms\n"
78 " -v <n> Set verbosity level to <n> [0, silent on success]\n"
84 port = atoi(argv[optind+1]);
86 for (i = 0; i < options.nconnect; i++) {
87 dprintf(2, "iteration %d of %d", i+1, options.nconnect);
88 ok = test(host, port);
92 dprintf(1, "passed %d of %d tests", nok, options.nconnect);
93 if (nok < options.nconnect)
94 printf("Failed %d of %d tests\n",
95 options.nconnect-nok, options.nconnect);
102 static int test(char *host, int port)
104 ZOOM_connection conn;
106 const char *errmsg, *addinfo;
108 conn = ZOOM_connection_new(host, port);
109 if ((error = ZOOM_connection_error(conn, &errmsg, &addinfo))) {
110 fprintf(stderr, "ZOOM error: %s (%d): %s\n", errmsg, error, addinfo);
114 ZOOM_connection_destroy(conn);
119 static void dprintf(int level, char *fmt, ...)
123 if (level > options.verbosity)
126 fprintf(stderr, "DEBUG(%d): ", level);
128 vfprintf(stderr, fmt, ap);