2 * $Id: zoom-benchmark.c,v 1.4 2005-09-11 20:21:27 adam Exp $
4 * Asynchronous multi-target client doing search and piggyback retrieval
13 #include <yaz/xmalloc.h>
14 #include <yaz/options.h>
19 static char* zoom_events[10];
21 /* re-sorting event numbers to progress numbers */
22 static int zoom_progress[10];
24 /* commando line parameters */
25 static struct parameters_t {
36 zoom_events[ZOOM_EVENT_NONE] = "ZOOM_EVENT_NONE";
37 zoom_events[ZOOM_EVENT_CONNECT] = "ZOOM_EVENT_CONNECT";
38 zoom_events[ZOOM_EVENT_SEND_DATA] = "ZOOM_EVENT_SEND_DATA";
39 zoom_events[ZOOM_EVENT_RECV_DATA] = "ZOOM_EVENT_RECV_DATA";
40 zoom_events[ZOOM_EVENT_TIMEOUT] = "ZOOM_EVENT_TIMEOUT";
41 zoom_events[ZOOM_EVENT_UNKNOWN] = "ZOOM_EVENT_UNKNOWN";
42 zoom_events[ZOOM_EVENT_SEND_APDU] = "ZOOM_EVENT_SEND_APDU";
43 zoom_events[ZOOM_EVENT_RECV_APDU] = "ZOOM_EVENT_RECV_APDU";
44 zoom_events[ZOOM_EVENT_RECV_RECORD] = "ZOOM_EVENT_RECV_RECORD";
45 zoom_events[ZOOM_EVENT_RECV_SEARCH] = "ZOOM_EVENT_RECV_SEARCH";
47 /* re-sorting event numbers to progress numbers */
48 zoom_progress[ZOOM_EVENT_NONE] = 0;
49 zoom_progress[ZOOM_EVENT_CONNECT] = 1;
50 zoom_progress[ZOOM_EVENT_SEND_DATA] = 3;
51 zoom_progress[ZOOM_EVENT_RECV_DATA] = 4;
52 zoom_progress[ZOOM_EVENT_TIMEOUT] = 8;
53 zoom_progress[ZOOM_EVENT_UNKNOWN] = 9;
54 zoom_progress[ZOOM_EVENT_SEND_APDU] = 2;
55 zoom_progress[ZOOM_EVENT_RECV_APDU] = 5;
56 zoom_progress[ZOOM_EVENT_RECV_RECORD] = 7;
57 zoom_progress[ZOOM_EVENT_RECV_SEARCH] = 6;
60 //parameters.host = "";
61 //parameters.query = "";
62 parameters.concurrent = 1;
63 parameters.timeout = 0;
74 void time_init(struct time_type *ptime)
76 gettimeofday(&(ptime->now), 0);
77 gettimeofday(&(ptime->then), 0);
82 void time_stamp(struct time_type *ptime)
84 gettimeofday(&(ptime->now), 0);
85 ptime->sec = ptime->now.tv_sec - ptime->then.tv_sec;
86 ptime->usec = ptime->now.tv_usec - ptime->then.tv_usec;
89 ptime->usec += 1000000;
93 long time_sec(struct time_type *ptime)
98 long time_usec(struct time_type *ptime)
103 void print_option_error()
105 fprintf(stderr, "zoom-benchmark: Call error\n");
106 fprintf(stderr, "zoom-benchmark -h host:port -q pqf-query "
107 "[-c no_concurrent] "
113 void read_params(int argc, char **argv, struct parameters_t *p_parameters){
116 while ((ret = options("h:q:c:t:", argv, argc, &arg)) != -2)
121 strcpy(p_parameters->host, arg);
124 strcpy(p_parameters->query, arg);
127 p_parameters->concurrent = atoi(arg);
130 p_parameters->timeout = atoi(arg);
133 //for (i = 0; i<number; i++)
134 // yaz_log(level, "%s", arg);
135 print_option_error();
138 print_option_error();
142 //printf("zoom-benchmark\n");
143 //printf(" host: %s \n", p_parameters->host);
144 //printf(" query: %s \n", p_parameters->query);
145 //printf(" concurrent: %d \n", p_parameters->concurrent);
146 //printf(" timeout: %d \n\n", p_parameters->timeout);
148 if (! strlen(p_parameters->host))
149 print_option_error();
150 if (! strlen(p_parameters->query))
151 print_option_error();
152 if (! (p_parameters->concurrent > 0))
153 print_option_error();
154 if (! (p_parameters->timeout >= 0))
155 print_option_error();
160 int main(int argc, char **argv)
162 struct time_type time;
170 read_params(argc, argv, ¶meters);
172 z = xmalloc(sizeof(*z) * parameters.concurrent);
173 r = xmalloc(sizeof(*r) * parameters.concurrent);
174 o = ZOOM_options_create();
177 ZOOM_options_set (o, "async", "1");
179 /* get first record of result set (using piggyback) */
180 ZOOM_options_set (o, "count", "1");
182 /* preferred record syntax */
183 //ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
184 //ZOOM_options_set (o, "elementSetName", "F");
186 /* connect to all concurrent connections*/
187 for ( i = 0; i < parameters.concurrent; i++){
188 /* create connection - pass options (they are the same for all) */
189 z[i] = ZOOM_connection_create(o);
191 /* connect and init */
192 ZOOM_connection_connect(z[i], parameters.host, 0);
195 for (i = 0; i < parameters.concurrent; i++)
196 r[i] = ZOOM_connection_search_pqf (z[i], parameters.query);
198 // print header of table
199 printf ("second.usec\ttarget\tprogress\tevent\teventname\terror\terrorname\n");
201 /* network I/O. pass number of connections and array of connections */
202 while ((i = ZOOM_event (parameters.concurrent, z)))
204 int event = ZOOM_connection_last_event(z[i-1]);
208 int progress = zoom_progress[event];
212 error = ZOOM_connection_error(z[i-1] , &errmsg, &addinfo);
214 progress = -progress;
216 printf ("%ld.%06ld\t%d\t%d\t%d\t%s\t%d\t%s\n",
217 time_sec(&time), time_usec(&time),
219 event, zoom_events[event],
224 /* no more to be done. Inspect results */
225 // commented out right now - do nothing
226 /* for (i = 0; i<parameters.concurrent; i++) */
229 /* const char *errmsg, *addinfo; */
230 /* const char *tname = (same_target ? argv[2] : argv[1+i]); */
231 /* /\* display errors if any *\/ */
232 /* if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo))) */
233 /* fprintf (stderr, "%s error: %s (%d) %s\n", tname, errmsg, */
234 /* error, addinfo); */
237 /* /\* OK, no major errors. Look at the result count *\/ */
239 /* printf ("%s: %d hits\n", tname, ZOOM_resultset_size(r[i])); */
240 /* /\* go through all records at target *\/ */
241 /* for (pos = 0; pos < 10; pos++) */
243 /* int len; /\* length of buffer rec *\/ */
244 /* const char *rec = */
245 /* ZOOM_record_get ( */
246 /* ZOOM_resultset_record (r[i], pos), "render", &len); */
247 /* /\* if rec is non-null, we got a record for display *\/ */
250 /* printf ("%d\n", pos+1); */
252 /* fwrite (rec, 1, len, stdout); */
259 /* destroy and exit */
260 for (i = 0; i<parameters.concurrent; i++)
262 ZOOM_resultset_destroy (r[i]);
263 ZOOM_connection_destroy (z[i]);
267 ZOOM_options_destroy(o);
273 * indent-tabs-mode: nil
275 * vim: shiftwidth=4 tabstop=8 expandtab