2 * $Id: zoom-benchmark.c,v 1.6 2005-09-15 20:51:16 marc 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 {
37 zoom_events[ZOOM_EVENT_NONE] = "ZOOM_EVENT_NONE";
38 zoom_events[ZOOM_EVENT_CONNECT] = "ZOOM_EVENT_CONNECT";
39 zoom_events[ZOOM_EVENT_SEND_DATA] = "ZOOM_EVENT_SEND_DATA";
40 zoom_events[ZOOM_EVENT_RECV_DATA] = "ZOOM_EVENT_RECV_DATA";
41 zoom_events[ZOOM_EVENT_TIMEOUT] = "ZOOM_EVENT_TIMEOUT";
42 zoom_events[ZOOM_EVENT_UNKNOWN] = "ZOOM_EVENT_UNKNOWN";
43 zoom_events[ZOOM_EVENT_SEND_APDU] = "ZOOM_EVENT_SEND_APDU";
44 zoom_events[ZOOM_EVENT_RECV_APDU] = "ZOOM_EVENT_RECV_APDU";
45 zoom_events[ZOOM_EVENT_RECV_RECORD] = "ZOOM_EVENT_RECV_RECORD";
46 zoom_events[ZOOM_EVENT_RECV_SEARCH] = "ZOOM_EVENT_RECV_SEARCH";
48 /* re-sorting event numbers to progress numbers */
49 zoom_progress[ZOOM_EVENT_NONE] = 0;
50 zoom_progress[ZOOM_EVENT_CONNECT] = 1;
51 zoom_progress[ZOOM_EVENT_SEND_DATA] = 3;
52 zoom_progress[ZOOM_EVENT_RECV_DATA] = 4;
53 zoom_progress[ZOOM_EVENT_TIMEOUT] = 8;
54 zoom_progress[ZOOM_EVENT_UNKNOWN] = 9;
55 zoom_progress[ZOOM_EVENT_SEND_APDU] = 2;
56 zoom_progress[ZOOM_EVENT_RECV_APDU] = 5;
57 zoom_progress[ZOOM_EVENT_RECV_RECORD] = 7;
58 zoom_progress[ZOOM_EVENT_RECV_SEARCH] = 6;
61 //parameters.host = "";
62 //parameters.query = "";
63 parameters.concurrent = 1;
64 parameters.timeout = 0;
66 /* progress initializing */
68 for (i = 0; i < 4096; i++){
69 parameters.progress[i] = 0;
82 void time_init(struct time_type *ptime)
84 gettimeofday(&(ptime->now), 0);
85 gettimeofday(&(ptime->then), 0);
90 void time_stamp(struct time_type *ptime)
92 gettimeofday(&(ptime->now), 0);
93 ptime->sec = ptime->now.tv_sec - ptime->then.tv_sec;
94 ptime->usec = ptime->now.tv_usec - ptime->then.tv_usec;
97 ptime->usec += 1000000;
101 long time_sec(struct time_type *ptime)
106 long time_usec(struct time_type *ptime)
111 void print_option_error()
113 fprintf(stderr, "zoom-benchmark: Call error\n");
114 fprintf(stderr, "zoom-benchmark -h host:port -q pqf-query "
115 "[-c no_concurrent] "
121 void read_params(int argc, char **argv, struct parameters_t *p_parameters){
124 while ((ret = options("h:q:c:t:", argv, argc, &arg)) != -2)
129 strcpy(p_parameters->host, arg);
132 strcpy(p_parameters->query, arg);
135 p_parameters->concurrent = atoi(arg);
138 p_parameters->timeout = atoi(arg);
141 //for (i = 0; i<number; i++)
142 // yaz_log(level, "%s", arg);
143 print_option_error();
146 print_option_error();
150 //printf("zoom-benchmark\n");
151 //printf(" host: %s \n", p_parameters->host);
152 //printf(" query: %s \n", p_parameters->query);
153 //printf(" concurrent: %d \n", p_parameters->concurrent);
154 //printf(" timeout: %d \n\n", p_parameters->timeout);
156 if (! strlen(p_parameters->host))
157 print_option_error();
158 if (! strlen(p_parameters->query))
159 print_option_error();
160 if (! (p_parameters->concurrent > 0))
161 print_option_error();
162 if (! (p_parameters->timeout >= 0))
163 print_option_error();
168 int main(int argc, char **argv)
170 struct time_type time;
178 read_params(argc, argv, ¶meters);
180 z = xmalloc(sizeof(*z) * parameters.concurrent);
181 r = xmalloc(sizeof(*r) * parameters.concurrent);
182 o = ZOOM_options_create();
185 ZOOM_options_set (o, "async", "1");
187 /* get first record of result set (using piggyback) */
188 ZOOM_options_set (o, "count", "1");
190 /* preferred record syntax */
191 //ZOOM_options_set (o, "preferredRecordSyntax", "usmarc");
192 //ZOOM_options_set (o, "elementSetName", "F");
194 /* connect to all concurrent connections*/
195 for ( i = 0; i < parameters.concurrent; i++){
196 /* create connection - pass options (they are the same for all) */
197 z[i] = ZOOM_connection_create(o);
199 /* connect and init */
200 ZOOM_connection_connect(z[i], parameters.host, 0);
203 for (i = 0; i < parameters.concurrent; i++)
204 r[i] = ZOOM_connection_search_pqf (z[i], parameters.query);
206 // print header of table
207 printf ("target\tsecond.usec\tprogress\tevent\teventname\t");
208 printf("error\terrorname\n");
210 /* network I/O. pass number of connections and array of connections */
211 while ((i = ZOOM_event (parameters.concurrent, z)))
213 int event = ZOOM_connection_last_event(z[i-1]);
217 int progress = zoom_progress[event];
219 if (event == ZOOM_EVENT_SEND_DATA | event == ZOOM_EVENT_RECV_DATA)
225 error = ZOOM_connection_error(z[i-1] , &errmsg, &addinfo);
227 parameters.progress[i] = -progress;
229 parameters.progress[i] += 1;
231 printf ("%d\t%ld.%06ld\t%d\t%d\t%s\t%d\t%s\n",
232 i-1, time_sec(&time), time_usec(&time),
233 parameters.progress[i],
234 event, zoom_events[event],
239 /* no more to be done. Inspect results */
240 // commented out right now - do nothing
241 /* for (i = 0; i<parameters.concurrent; i++) */
244 /* const char *errmsg, *addinfo; */
245 /* const char *tname = (same_target ? argv[2] : argv[1+i]); */
246 /* /\* display errors if any *\/ */
247 /* if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo))) */
248 /* fprintf (stderr, "%s error: %s (%d) %s\n", tname, errmsg, */
249 /* error, addinfo); */
252 /* /\* OK, no major errors. Look at the result count *\/ */
254 /* printf ("%s: %d hits\n", tname, ZOOM_resultset_size(r[i])); */
255 /* /\* go through all records at target *\/ */
256 /* for (pos = 0; pos < 10; pos++) */
258 /* int len; /\* length of buffer rec *\/ */
259 /* const char *rec = */
260 /* ZOOM_record_get ( */
261 /* ZOOM_resultset_record (r[i], pos), "render", &len); */
262 /* /\* if rec is non-null, we got a record for display *\/ */
265 /* printf ("%d\n", pos+1); */
267 /* fwrite (rec, 1, len, stdout); */
274 /* destroy and exit */
275 for (i = 0; i<parameters.concurrent; i++)
277 ZOOM_resultset_destroy (r[i]);
278 ZOOM_connection_destroy (z[i]);
282 ZOOM_options_destroy(o);
288 * indent-tabs-mode: nil
290 * vim: shiftwidth=4 tabstop=8 expandtab