From a134707b0766f8857fb7e8bd6b7de2efa0e44f37 Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 18 Jun 2008 00:16:57 +0000 Subject: [PATCH] disable nagle algorithm in ldapclient and server add a benchmark mode to ldapbench that does not reconnect for each query but does all the queries over the same connection. --- ldapclient.c | 35 ++++++++++++++++++------ tinyldap.c | 76 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 73 insertions(+), 38 deletions(-) diff --git a/ldapclient.c b/ldapclient.c index 5c97f7d..86375ad 100644 --- a/ldapclient.c +++ b/ldapclient.c @@ -13,6 +13,8 @@ #include #include +#include +#include #define BUFSIZE 8192 @@ -54,23 +56,32 @@ int main(int argc,char* argv[]) { int len=0; char* me; long n,durchlauf; - int bench; + int bench,bench2; if ((me=strrchr(argv[0],'/'))) ++me; else me=argv[0]; n=1; if ((bench=!strcmp(me,"ldapbench"))) { - n=atoi(getenv("NUM")); + char* c=getenv("NUM"); + if (!c) goto usage; + n=atoi(c); + if (n<1) goto usage; + if (getenv("CONNECT")) + bench=2; buffer_putsflush(buffer_2,"benchmark mode\n"); } + bench2=0; if (argc<4) { usage: buffer_putsflush(buffer_2,"usage: ldapclient ip baseObject filter [foo...]\n"); + if (bench) + buffer_putsflush(buffer_2,"and set $NUM to the number of iterations,\nand $CONNECT to anything to do only one connection (instead of one per request).\n"); return 0; } for (durchlauf=0; durchlauf +#include +#include #ifdef DEBUG #include @@ -1415,6 +1418,40 @@ static void normalize_string_dn(struct string* s) { static void update(); +void reply_with_index(struct SearchRequest* sr,unsigned long* messageid,int out) { + size_t returned=0; + struct bitfield result; + size_t i; +#if (debug != 0) + if (debug) buffer_putsflush(buffer_2,"query can be answered with index!\n"); +#endif + result.bits=alloca(record_set_length*sizeof(unsigned long)); + /* Use the index to find matching data. Put the offsets + * of the matches in a table. Use findrec to locate + * the records that point to the data. */ + useindex(sr->filter,&result); +// assert(result.last<=record_count); + for (i=result.first; i<=result.last; ) { + size_t ni=i+8*sizeof(long); + if (!result.bits[i/(8*sizeof(long))]) { + i=ni; + continue; + } + if (ni>record_count) ni=record_count; + for (; isizeLimit && sr->sizeLimit<++returned) + break; + answerwith(j,sr,*messageid,out); + } + } + } + } +} + /* a standard LDAP session looks like this: * 1. connect to server * 2. send a BindRequest @@ -1592,36 +1629,7 @@ authfailure: fixup(sr.filter); fixupadl(sr.attributes); if (indexable(sr.filter)) { - struct bitfield result; - size_t i; -#if (debug != 0) - if (debug) buffer_putsflush(buffer_2,"query can be answered with index!\n"); -#endif - result.bits=alloca(record_set_length*sizeof(unsigned long)); - /* Use the index to find matching data. Put the offsets - * of the matches in a table. Use findrec to locate - * the records that point to the data. */ - useindex(sr.filter,&result); -// assert(result.last<=record_count); - for (i=result.first; i<=result.last; ) { - size_t ni=i+8*sizeof(long); - if (!result.bits[i/(8*sizeof(long))]) { - i=ni; - continue; - } - if (ni>record_count) ni=record_count; - for (; i