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.
This commit is contained in:
leitner
2008-06-18 00:16:57 +00:00
parent 7e2d134462
commit a134707b07
2 changed files with 73 additions and 38 deletions

View File

@@ -13,6 +13,8 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#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<n; ++durchlauf) {
if (bench==2 && bench2) goto skipconnect;
sock=socket_tcp4b();
{
char ip[4];
@@ -80,11 +91,15 @@ usage:
return 1;
}
}
{
int one=1;
setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,&one,sizeof(one));
}
if (ldapbind(sock)) {
struct Filter *f;
struct AttributeDescriptionList adl;
struct AttributeDescriptionList *next;
struct SearchRequest sr;
static struct Filter *f;
static struct AttributeDescriptionList adl;
static struct AttributeDescriptionList *next;
static struct SearchRequest sr;
int i;
if (!scan_ldapsearchfilterstring(argv[3],&f)) {
buffer_putsflush(buffer_2,"could not parse filter!\n");
@@ -121,13 +136,16 @@ usage:
sr.scope=wholeSubtree; sr.derefAliases=neverDerefAliases;
sr.sizeLimit=sr.timeLimit=sr.typesOnly=0;
sr.filter=f;
bench2=1;
skipconnect:
len=fmt_ldapsearchrequest(buf+100,&sr);
{
int tmp=fmt_ldapmessage(0,++messageid,SearchRequest,len);
fmt_ldapmessage(buf+100-tmp,messageid,SearchRequest,len);
write(sock,buf+100-tmp,len+tmp);
}
shutdown(sock,SHUT_WR);
if (bench!=2)
shutdown(sock,SHUT_WR);
{
char buf[32*1024]; /* arbitrary limit, bad! */
int len=0,tmp,tmp2;
@@ -246,7 +264,8 @@ copypartialandcontinue:
buffer_putsflush(buffer_2,"ldapbind failed\n");
return 2;
}
close(sock);
if (bench!=2)
close(sock);
}
if (bench) write(1,"\n",1);
return 0;

View File

@@ -34,6 +34,9 @@
#include "errmsg.h"
#include "textcode.h"
#include "fmt.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#ifdef DEBUG
#include <sys/poll.h>
@@ -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 (; i<ni; ++i) {
if (isset(&result,i)) {
uint32 j;
uint32_unpack(map+indices_offset+4*i,&j);
if (ldap_match_mapped(j,sr)) {
if (sr->sizeLimit && 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<ni; ++i) {
if (isset(&result,i)) {
uint32 j;
uint32_unpack(map+indices_offset+4*i,&j);
if (ldap_match_mapped(j,&sr)) {
if (sr.sizeLimit && sr.sizeLimit<++returned)
break;
answerwith(j,&sr,messageid,out);
}
}
}
}
reply_with_index(&sr,&messageid,out);
} else {
char* x=map+5*4+size_of_string_table+attribute_count*8;
size_t i;
@@ -2379,6 +2387,10 @@ again:
buffer_putsflush(buffer_2,"accept failed!\n");
exit(1);
}
{
int one=1;
setsockopt(asock,IPPROTO_TCP,TCP_NODELAY,&one,sizeof(one));
}
#ifdef DEBUG
{
struct pollfd p;
@@ -2401,6 +2413,10 @@ again:
}
}
#else
{
int one=1;
setsockopt(1,IPPROTO_TCP,TCP_NODELAY,&one,sizeof(one));
}
handle(0,1);
#endif
return 0;