2 * $Id: zoom-benchmark.c,v 1.1 2005-09-07 13:45:15 marc Exp $
4 * Asynchronous multi-target client doing search and piggyback retrieval
13 #include <yaz/xmalloc.h>
19 int main(int argc, char **argv)
29 ZOOM_connection z[1024]; /* allow at most 1024 connections */
30 ZOOM_resultset r[1024]; /* and result sets .. */
31 ZOOM_options o = ZOOM_options_create ();
35 fprintf (stderr, "usage:\n%s target1 target2 ... targetN query\n",
39 if (argc == 4 && isdigit(argv[1][0]) && !strchr(argv[1],'.'))
51 // ZOOM_EVENT_NONE = 0,
52 // ZOOM_EVENT_CONNECT = 1,
53 // ZOOM_EVENT_SEND_DATA = 2,
54 // ZOOM_EVENT_RECV_DATA = 3,
55 // ZOOM_EVENT_TIMEOUT = 4,
56 // ZOOM_EVENT_UNKNOWN = 5,
57 // ZOOM_EVENT_SEND_APDU = 6,
58 // ZOOM_EVENT_RECV_APDU = 7,
59 // ZOOM_EVENT_RECV_RECORD = 8,
60 // ZOOM_EVENT_RECV_SEARCH = 9
63 char* zoom_events[10];
64 zoom_events[ZOOM_EVENT_NONE] = "ZOOM_EVENT_NONE";
65 zoom_events[ZOOM_EVENT_CONNECT] = "ZOOM_EVENT_CONNECT";
66 zoom_events[ZOOM_EVENT_SEND_DATA] = "ZOOM_EVENT_SEND_DATA";
67 zoom_events[ZOOM_EVENT_RECV_DATA] = "ZOOM_EVENT_RECV_DATA";
68 zoom_events[ZOOM_EVENT_TIMEOUT] = "ZOOM_EVENT_TIMEOUT";
69 zoom_events[ZOOM_EVENT_UNKNOWN] = "ZOOM_EVENT_UNKNOWN";
70 zoom_events[ZOOM_EVENT_SEND_APDU] = "ZOOM_EVENT_SEND_APDU";
71 zoom_events[ZOOM_EVENT_RECV_APDU] = "ZOOM_EVENT_RECV_APDU";
72 zoom_events[ZOOM_EVENT_RECV_RECORD] = "ZOOM_EVENT_RECV_RECORD";
73 zoom_events[ZOOM_EVENT_RECV_SEARCH] = "ZOOM_EVENT_RECV_SEARCH";
75 int zoom_progress[10];
76 zoom_progress[ZOOM_EVENT_NONE] = 0;
77 zoom_progress[ZOOM_EVENT_CONNECT] = 1;
78 zoom_progress[ZOOM_EVENT_SEND_DATA] = 3;
79 zoom_progress[ZOOM_EVENT_RECV_DATA] = 4;
80 zoom_progress[ZOOM_EVENT_TIMEOUT] = 8;
81 zoom_progress[ZOOM_EVENT_UNKNOWN] = 9;
82 zoom_progress[ZOOM_EVENT_SEND_APDU] = 2;
83 zoom_progress[ZOOM_EVENT_RECV_APDU] = 5;
84 zoom_progress[ZOOM_EVENT_RECV_RECORD] = 7;
85 zoom_progress[ZOOM_EVENT_RECV_SEARCH] = 6;
89 ZOOM_options_set (o, "async", "1");
91 /* get first 10 records of result set (using piggyback) */
92 ZOOM_options_set (o, "count", "1");
94 /* preferred record syntax */
95 //ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
96 //ZOOM_options_set (o, "elementSetName", "F");
99 for (i = 0; i<no; i++)
101 /* create connection - pass options (they are the same for all) */
102 z[i] = ZOOM_connection_create (o);
104 /* connect and init */
106 ZOOM_connection_connect (z[i], argv[2], 0);
108 ZOOM_connection_connect (z[i], argv[1+i], 0);
111 for (i = 0; i<no; i++)
112 r[i] = ZOOM_connection_search_pqf (z[i], argv[argc-1]);
114 printf ("second.usec target progress event eventname error errorname\n");
117 gettimeofday(&then, 0);
118 /* network I/O. pass number of connections and array of connections */
119 while ((i = ZOOM_event (no, z)))
122 int event = ZOOM_connection_last_event(z[i-1]);
126 int progress = zoom_progress[event];
128 gettimeofday(&now, 0);
129 //stamp(&now, &then);
130 sec = now.tv_sec - then.tv_sec;
131 usec = now.tv_usec - then.tv_usec;
137 error = ZOOM_connection_error(z[i-1] , &errmsg, &addinfo);
139 progress = -progress;
141 printf ("%i.%06i %d %d %d %s %d '%s' \n", sec, usec,
143 event, zoom_events[event],
148 /* no more to be done. Inspect results */
149 for (i = 0; i<no && 0; i++)
152 const char *errmsg, *addinfo;
153 const char *tname = (same_target ? argv[2] : argv[1+i]);
154 /* display errors if any */
155 if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
156 fprintf (stderr, "%s error: %s (%d) %s\n", tname, errmsg,
160 /* OK, no major errors. Look at the result count */
162 printf ("%s: %d hits\n", tname, ZOOM_resultset_size(r[i]));
163 /* go through all records at target */
164 for (pos = 0; pos < 10; pos++)
166 int len; /* length of buffer rec */
169 ZOOM_resultset_record (r[i], pos), "render", &len);
170 /* if rec is non-null, we got a record for display */
173 printf ("%d\n", pos+1);
175 fwrite (rec, 1, len, stdout);
182 /* destroy and exit */
183 for (i = 0; i<no; i++)
185 ZOOM_resultset_destroy (r[i]);
186 ZOOM_connection_destroy (z[i]);
188 ZOOM_options_destroy(o);
194 * indent-tabs-mode: nil
196 * vim: shiftwidth=4 tabstop=8 expandtab