1 /* $Id: benchmark.c,v 1.7 2005-01-15 19:47:15 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.
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 db_printf(int level, char *fmt, ...);
44 int main(int argc, char **argv)
53 while ((c = getopt(argc, argv, "c:s:p:fbd:rv:")) != -1) {
55 case 'c': options.nconnect = atoi(optarg); break;
56 case 's': options.nsearch = atoi(optarg); break;
57 case 'p': options.npresent = atoi(optarg); break;
58 case 'f': options.full = 1; break;
59 case 'b': options.full = 0; break;
60 case 'd': options.delay = atoi(optarg); break;
61 case 'r': options.random = 1; break;
62 case 'v': options.verbosity = atoi(optarg); break;
67 if (argc-optind != 2) {
69 fprintf(stderr, "Usage: %s [options] <host> <port>\n"
70 " -c <n> Make <n> connection to the server [default: 3]\n"
71 " -s <n> Perform <n> searches on each connection [3]\n"
72 " -p <n> Make <n> present requests after each search [3]\n"
73 " -f Fetch full records [default: brief]\n"
74 " -b Fetch brief records\n"
75 " -d <n> Delay <n> ms after each operation\n"
76 " -r Delays are random between 0 and the specified number of ms\n"
77 " -v <n> Set verbosity level to <n> [0, silent on success]\n"
83 port = atoi(argv[optind+1]);
85 for (i = 0; i < options.nconnect; i++) {
86 db_printf(2, "iteration %d of %d", i+1, options.nconnect);
87 ok = test(host, port);
91 db_printf(1, "passed %d of %d tests", nok, options.nconnect);
92 if (nok < options.nconnect)
93 printf("Failed %d of %d tests\n",
94 options.nconnect-nok, options.nconnect);
101 static int test(char *host, int port)
103 ZOOM_connection conn;
105 const char *errmsg, *addinfo;
107 conn = ZOOM_connection_new(host, port);
108 if ((error = ZOOM_connection_error(conn, &errmsg, &addinfo))) {
109 fprintf(stderr, "ZOOM error: %s (%d): %s\n", errmsg, error, addinfo);
113 ZOOM_connection_destroy(conn);
117 static void db_printf(int level, char *fmt, ...)
121 if (level > options.verbosity)
124 fprintf(stderr, "DEBUG(%d): ", level);
126 vfprintf(stderr, fmt, ap);