2 * $Id: zoom-benchmark.c,v 1.3 2005-09-11 13:32:39 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;
166 read_params(argc, argv, ¶meters);
168 ZOOM_connection z[parameters.concurrent];
169 ZOOM_resultset r[parameters.concurrent];
170 ZOOM_options o = ZOOM_options_create();
174 ZOOM_options_set (o, "async", "1");
176 /* get first record of result set (using piggyback) */
177 ZOOM_options_set (o, "count", "1");
179 /* preferred record syntax */
180 //ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
181 //ZOOM_options_set (o, "elementSetName", "F");
183 /* connect to all concurrent connections*/
185 for ( i = 0; i < parameters.concurrent; i++){
186 /* create connection - pass options (they are the same for all) */
187 z[i] = ZOOM_connection_create(o);
189 /* connect and init */
190 ZOOM_connection_connect(z[i], parameters.host, 0);
193 for (i = 0; i < parameters.concurrent; i++)
194 r[i] = ZOOM_connection_search_pqf (z[i], parameters.query);
196 // print header of table
197 printf ("second.usec\ttarget\tprogress\tevent\teventname\terror\terrorname\n");
199 /* network I/O. pass number of connections and array of connections */
200 while ((i = ZOOM_event (parameters.concurrent, z)))
204 int event = ZOOM_connection_last_event(z[i-1]);
208 int progress = zoom_progress[event];
211 error = ZOOM_connection_error(z[i-1] , &errmsg, &addinfo);
213 progress = -progress;
215 printf ("%i.%06i\t%d\t%d\t%d\t%s\t%d\t%s\n",
216 time_sec(&time), time_usec(&time),
218 event, zoom_events[event],
223 /* no more to be done. Inspect results */
224 // commented out right now - do nothing
225 /* for (i = 0; i<parameters.concurrent; i++) */
228 /* const char *errmsg, *addinfo; */
229 /* const char *tname = (same_target ? argv[2] : argv[1+i]); */
230 /* /\* display errors if any *\/ */
231 /* if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo))) */
232 /* fprintf (stderr, "%s error: %s (%d) %s\n", tname, errmsg, */
233 /* error, addinfo); */
236 /* /\* OK, no major errors. Look at the result count *\/ */
238 /* printf ("%s: %d hits\n", tname, ZOOM_resultset_size(r[i])); */
239 /* /\* go through all records at target *\/ */
240 /* for (pos = 0; pos < 10; pos++) */
242 /* int len; /\* length of buffer rec *\/ */
243 /* const char *rec = */
244 /* ZOOM_record_get ( */
245 /* ZOOM_resultset_record (r[i], pos), "render", &len); */
246 /* /\* if rec is non-null, we got a record for display *\/ */
249 /* printf ("%d\n", pos+1); */
251 /* fwrite (rec, 1, len, stdout); */
258 /* destroy and exit */
259 for (i = 0; i<parameters.concurrent; i++)
261 ZOOM_resultset_destroy (r[i]);
262 ZOOM_connection_destroy (z[i]);
264 ZOOM_options_destroy(o);
270 * indent-tabs-mode: nil
272 * vim: shiftwidth=4 tabstop=8 expandtab