[1951] in Kerberos-V5-bugs

home help back first fref pref prev next nref lref last post

So where are the bottlenecks? (Audit for post Beta-6)

daemon@ATHENA.MIT.EDU (epeisach@MIT.EDU)
Tue Jun 4 20:58:06 1996

From: epeisach@MIT.EDU
Date: Tue, 4 Jun 1996 20:57:31 -0400
To: krbdev@MIT.EDU
Cc: krb5-bugs@MIT.EDU


The issue of bottlenecks and performance was recently raised,
particularly with regard to database locking....

I ran a profiling kdc briefly and found the following amusing time
sinks....

The time sinks in the server. %time is % of time in code or functions
below this point...

%time		function
10.2		mit_des_cbc_encrypt
8.5		_doprnt
8.1		asn1buf_expand
6.8		asn1_encode_generaltime (all in sprintf)
6.8		sprintf
6.6		klog_vsyslog
3.9		krb5_free_context
3.8		asn12krb5_buf

Note that the database code is relatively small (at the moment)...

Looking at the numbers, I see some biggies that can be fixed (post
beta-6) that would be (portable) performance gainers....

a) asn1_encode_generaltime - we are using sprintf here which may not be
the most efficient method of getting the date into a string....

b) asn1buf_expand is invoked about 12040 times in my simple test. The
break down is 111 times to malloc and 11939 to realloc... Memory
allocation is theoretcially dolled out in 200 byte increments....
Note however that there is a serious bug in that the new buffer length 
is not stored properly in the data structures - only the amount that was
needed!! With a small patch (inidicated below) the usage drops to 60th
or 0.6% of the application...

I really would like someone to audit this so it can be included post
beta-6...

c) Random nitpick... asn1buf.c uses calloc throughout the code and the
the entire buffer which is allocated is assigned... This means the time
that calloc is zeroing the memory is wasted...
For instance....
    *s = calloc(sizeof("<EMPTY>")+1, sizeof(char));
    if(*s == NULL) return ENOMEM;
    strcpy(*s,"<EMPTY>");
is a little silly, but examples like this abound...


------------------------------------------------
Patch to be audited for post beta-6

cvs diff: Diffing .
Index: asn1buf.c
===================================================================
RCS file: /mit/krb5/.cvsroot/src/lib/krb5/asn.1/asn1buf.c,v
retrieving revision 5.10
diff -c -r5.10 asn1buf.c
*** asn1buf.c	1995/04/14 00:51:51	5.10
--- asn1buf.c	1996/06/05 00:38:32
***************
*** 350,356 ****
  					    inc : STANDARD_INCREMENT))
  			* sizeof(asn1_octet));
    if(buf->base == NULL) return ENOMEM;
!   buf->bound = (buf->base) + bound_offset + inc;
    buf->next = (buf->base) + next_offset;
    return 0;
  }
--- 350,357 ----
  					    inc : STANDARD_INCREMENT))
  			* sizeof(asn1_octet));
    if(buf->base == NULL) return ENOMEM;
!   buf->bound = (buf->base) + bound_offset + (inc > STANDARD_INCREMENT ?
! 					   inc : STANDARD_INCREMENT);
    buf->next = (buf->base) + next_offset;
    return 0;
  }










home help back first fref pref prev next nref lref last post