More timing for performance testing. Re-introduction of cache.c_mutex.

This commit is contained in:
Kurt Spanier 1999-02-22 11:22:44 +00:00
parent 9e2fc1ed06
commit 9cb23b462e
17 changed files with 156 additions and 68 deletions

View file

@ -23,6 +23,7 @@ bdb2i_back_add_internal(
char *pdn;
Entry *p = NULL;
int rc;
struct timeval time1;
Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0);
@ -106,8 +107,12 @@ bdb2i_back_add_internal(
/*
* Try to add the entry to the cache, assign it a new dnid.
*/
bdb2i_start_timing( be->bd_info, &time1 );
rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
bdb2i_stop_timing( be->bd_info, time1, "ADD-CACHE", conn, op );
if ( rc != 0 ) {
if( p != NULL) {
/* free parent and writer lock */
@ -138,37 +143,57 @@ bdb2i_back_add_internal(
* add it to the id2children index for the parent
*/
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
goto return_results;
}
bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
/*
* Add the entry to the attribute indexes, then add it to
* the id2children index, dn2id index, and the id2entry index.
*/
bdb2i_start_timing( be->bd_info, &time1 );
/* attribute indexes */
if ( bdb2i_index_add_entry( be, e ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
goto return_results;
}
bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
bdb2i_start_timing( be->bd_info, &time1 );
/* dn2id index */
if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
goto return_results;
}
bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
bdb2i_start_timing( be->bd_info, &time1 );
/* id2entry index */
if ( bdb2i_id2entry_add( be, e ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0,
@ -176,9 +201,13 @@ bdb2i_back_add_internal(
(void) bdb2i_dn2id_delete( be, e->e_ndn );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
goto return_results;
}
bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
rc = 0;
@ -186,7 +215,6 @@ return_results:;
if (p != NULL) {
/* free parent and writer lock */
bdb2i_cache_return_entry_w( &li->li_cache, p );
}
/* free entry and writer lock */
@ -206,7 +234,7 @@ bdb2_back_add(
{
DB_LOCK lock;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
struct timeval time1;
struct timeval time1, time2;
int ret;
bdb2i_start_timing( be->bd_info, &time1 );
@ -218,6 +246,8 @@ bdb2_back_add(
}
bdb2i_start_timing( be->bd_info, &time2 );
/* check, if a new default attribute index will be created,
in which case we have to open the index file BEFORE TP */
switch ( slapMode ) {
@ -229,7 +259,8 @@ bdb2_back_add(
}
ret = bdb2i_back_add_internal( be, conn, op, e );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time2, "ADD-INTERN", conn, op );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );
return( ret );

View file

@ -79,6 +79,7 @@ struct cache {
Avlnode *c_idtree;
Entry *c_lruhead; /* lru - add accessed entries here */
Entry *c_lrutail; /* lru - rem lru entries from here */
ldap_pvt_thread_mutex_t c_mutex;
};
#define CACHE_READ_LOCK 1

View file

@ -242,7 +242,7 @@ bdb2_back_bind(
ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );

View file

@ -71,6 +71,9 @@ cache_entry_private_destroy( Entry*e )
void
bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
{
/* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
#ifdef LDAP_DEBUG
assert( e->e_private );
#endif
@ -104,6 +107,9 @@ bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
"====> bdb2i_cache_return_entry_%s( %ld ): returned (%d)\n",
rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt);
}
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
}
#define LRU_DELETE( cache, e ) { \
@ -147,6 +153,9 @@ bdb2i_cache_add_entry_rw(
int i;
Entry *ee;
/* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
#ifdef LDAP_DEBUG
assert( e->e_private == NULL );
#endif
@ -167,6 +176,8 @@ bdb2i_cache_add_entry_rw(
cache_entry_private_destroy(e);
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 1 );
}
@ -188,6 +199,8 @@ bdb2i_cache_add_entry_rw(
cache_entry_private_destroy(e);
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( -1 );
}
@ -233,6 +246,8 @@ bdb2i_cache_add_entry_rw(
}
}
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 0 );
}
@ -251,6 +266,9 @@ bdb2i_cache_update_entry(
int i;
Entry *ee;
/* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
#ifdef LDAP_DEBUG
assert( e->e_private );
#endif
@ -262,6 +280,8 @@ bdb2i_cache_update_entry(
"====> bdb2i_cache_add_entry( %ld ): \"%s\": already in dn cache\n",
e->e_id, e->e_dn, 0 );
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 1 );
}
@ -281,6 +301,8 @@ bdb2i_cache_update_entry(
0, 0, 0 );
}
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( -1 );
}
@ -325,11 +347,13 @@ bdb2i_cache_update_entry(
}
}
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 0 );
}
/*
* cache_find_entry_dn2id - find an entry in the cache, given dn
* bdb2i_cache_find_entry_dn2id - find an entry in the cache, given dn
*/
ID
@ -343,6 +367,9 @@ bdb2i_cache_find_entry_dn2id(
Entry e, *ep;
ID id;
/* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
e.e_dn = dn;
e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
@ -371,6 +398,8 @@ bdb2i_cache_find_entry_dn2id(
"====> bdb2i_cache_find_entry_dn2id(\"%s\"): %ld (not ready) %d\n",
dn, ep->e_id, LEI(ep)->lei_state);
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( NOID );
}
@ -385,11 +414,17 @@ bdb2i_cache_find_entry_dn2id(
/* save id */
id = ep->e_id;
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( id );
}
free(e.e_ndn);
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( NOID );
}
@ -410,6 +445,9 @@ bdb2i_cache_find_entry_id(
e.e_id = id;
try_again:
/* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
entry_id_cmp )) != NULL )
{
@ -428,6 +466,8 @@ try_again:
"====> bdb2i_cache_find_entry_id( %ld ): %ld (not ready) %d\n",
id, ep->e_id, LEI(ep)->lei_state);
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( NULL );
}
@ -441,9 +481,15 @@ try_again:
LEI(ep)->lei_refcnt++;
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( ep );
}
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( NULL );
}
@ -466,6 +512,9 @@ bdb2i_cache_delete_entry(
{
int rc;
/* set cache mutex */
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
#ifdef LDAP_DEBUG
assert( e->e_private );
#endif
@ -475,6 +524,8 @@ bdb2i_cache_delete_entry(
rc = cache_delete_entry_internal( cache, e );
/* free cache mutex */
ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( rc );
}

View file

@ -86,7 +86,7 @@ bdb2_back_compare(
}
ret = bdb2i_back_compare_internal( be, conn, op, dn, ava );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "CMP", conn, op );
return( ret );

View file

@ -139,6 +139,7 @@ bdb2i_cache_store(
)
{
int rc;
struct timeval time1;
#ifdef LDBM_DEBUG
Statslog( LDAP_DEBUG_STATS,
@ -158,8 +159,23 @@ bdb2i_cache_store(
flags, 0, 0, 0, 0 );
#endif /* LDBM_DEBUG */
if ( slapMode == SLAP_TIMEDSERVER_MODE )
bdb2i_uncond_start_timing( &time1 );
rc = ldbm_store( db->dbc_db, key, data, flags );
if ( slapMode == SLAP_TIMEDSERVER_MODE ) {
char buf[BUFSIZ];
char buf2[BUFSIZ];
*buf2 = '\0';
if ( !( strcasecmp( db->dbc_name, "dn.bdb2" )))
sprintf( buf2, " [%s]", key.dptr );
sprintf( buf, "ADD-BDB2( %s%s )", db->dbc_name, buf2 );
bdb2i_uncond_stop_timing( time1, buf,
NULL, NULL, LDAP_DEBUG_TRACE );
}
return( rc );
}

View file

@ -164,7 +164,7 @@ bdb2_back_delete(
}
ret = bdb2i_back_delete_internal( be, conn, op, dn );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );
return( ret );

View file

@ -150,7 +150,7 @@ bdb2_back_group(
ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn,
objectclassValue, groupattrName );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "GRP", NULL, NULL );
return( ret );

View file

@ -172,6 +172,9 @@ bdb2i_back_db_init_internal(
1 );
free( argv[ 1 ] );
/* initialize the cache mutex */
ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
/* initialize the TP file head */
if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )
return 1;

View file

@ -149,7 +149,7 @@ bdb2_back_modify(
}
ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op );
return( ret );

View file

@ -209,7 +209,7 @@ bdb2_back_modrdn(
ret = bdb2i_back_modrdn_internal( be, conn, op, dn,
newrdn, deleteoldrdn );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "MODRDN", conn, op );
return( ret );

View file

@ -13,8 +13,8 @@
#define PORTER_OBJ "bdb2_backend"
static int
bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
int
bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
{
u_int32_t locker;
db_lockmode_t lock_type;
@ -76,21 +76,7 @@ bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
int
bdb2i_enter_backend_r( DB_ENV *dbEnv, DB_LOCK *lock )
{
return( bdb2i_enter_backend( dbEnv, lock, 0 ));
}
int
bdb2i_enter_backend_w( DB_ENV *dbEnv, DB_LOCK *lock )
{
return( bdb2i_enter_backend( dbEnv, lock, 1 ));
}
int
bdb2i_leave_backend( DB_ENV *dbEnv, DB_LOCK lock )
bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer )
{
int ret = 0;
@ -103,26 +89,26 @@ bdb2i_leave_backend( DB_ENV *dbEnv, DB_LOCK lock )
case 0:
Debug( LDAP_DEBUG_TRACE,
"bdb2i_leave_backend() -- lock released\n",
0, 0, 0 );
"bdb2i_leave_backend() -- %s lock released\n",
writer ? "write" : "read", 0, 0 );
break;
case DB_LOCK_NOTHELD:
Debug( LDAP_DEBUG_ANY,
"bdb2i_leave_backend() -- lock NOT held\n",
0, 0, 0 );
"bdb2i_leave_backend() -- %s lock NOT held\n",
writer ? "write" : "read", 0, 0 );
break;
case DB_LOCK_DEADLOCK:
Debug( LDAP_DEBUG_ANY,
"bdb2i_leave_backend() -- lock returned DEADLOCK\n",
0, 0, 0 );
"bdb2i_leave_backend() -- %s lock returned DEADLOCK\n",
writer ? "write" : "read", 0, 0 );
break;
default:
Debug( LDAP_DEBUG_ANY,
"bdb2i_leave_backend() -- lock returned ERROR: %s\n",
strerror( errno ), 0, 0 );
"bdb2i_leave_backend() -- %s lock returned ERROR: %s\n",
writer ? "write" : "read", strerror( errno ), 0 );
ret = errno;
break;

View file

@ -153,19 +153,22 @@ int bdb2i_back_db_shutdown LDAP_P(( BackendDB *be ));
* timing.c
*/
char *bdb2i_elapsed LDAP_P(( struct timeval firsttime,
struct timeval secondtime ));
void bdb2i_start_timing LDAP_P(( BackendInfo *bi, struct timeval *time1 ));
void bdb2i_stop_timing LDAP_P(( BackendInfo *bi, struct timeval time1,
char *func, Connection *conn, Operation *op ));
void bdb2i_uncond_start_timing LDAP_P(( struct timeval *time1 ));
#define bdb2i_start_timing(bi,time1) if ( with_timing( bi )) bdb2i_uncond_start_timing( (time1) )
void bdb2i_uncond_stop_timing LDAP_P(( struct timeval time1,
char *func, Connection *conn, Operation *op, int level ));
#define bdb2i_stop_timing(bi,time1,func,conn,op) if ( with_timing( bi )) bdb2i_uncond_stop_timing( (time1), (func), (conn), (op), LDAP_DEBUG_ANY )
/*
* porter.c
*/
int bdb2i_enter_backend_r LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock ));
int bdb2i_enter_backend_w LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock ));
int bdb2i_leave_backend LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock ));
int bdb2i_enter_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock, int writer ));
#define bdb2i_enter_backend_r(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 0 )
#define bdb2i_enter_backend_w(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 1 )
int bdb2i_leave_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock, int writer ));
#define bdb2i_leave_backend_r(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 0 )
#define bdb2i_leave_backend_w(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 1 )
/*
* txn.c

View file

@ -347,7 +347,7 @@ bdb2_back_search(
ret = bdb2i_back_search_internal( be, conn, op, base, scope, deref,
slimit, tlimit, filter, filterstr, attrs, attrsonly );
(void) bdb2i_leave_backend( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "SRCH", conn, op );
return( ret );

View file

@ -43,7 +43,7 @@ bdb2i_back_startup_internal(
(void) getcwd( cwd, MAXPATHLEN );
sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, lty->lty_dbhome );
free( lty->lty_dbhome );
lty->lty_dbhome = strdup( cwd );
lty->lty_dbhome = ch_strdup( cwd );
}
home = lty->lty_dbhome;
@ -158,7 +158,7 @@ bdb2i_back_db_startup_internal(
(void) getcwd( cwd, MAXPATHLEN );
sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
free( li->li_directory );
li->li_directory = strdup( cwd );
li->li_directory = ch_strdup( cwd );
}

View file

@ -12,7 +12,7 @@
#include "back-bdb2.h"
char *
static char *
bdb2i_elapsed( struct timeval firsttime, struct timeval secondtime )
{
long int elapsedmicrosec, elapsedsec;
@ -26,47 +26,44 @@ bdb2i_elapsed( struct timeval firsttime, struct timeval secondtime )
}
sprintf( elapsed_string, "%ld.%.6ld", elapsedsec, elapsedmicrosec );
return( strdup( elapsed_string ));
return( ch_strdup( elapsed_string ));
}
void
bdb2i_start_timing(
BackendInfo *bi,
bdb2i_uncond_start_timing(
struct timeval *time1
)
{
if ( with_timing( bi )) gettimeofday( time1, NULL );
gettimeofday( time1, NULL );
}
void
bdb2i_stop_timing(
BackendInfo *bi,
bdb2i_uncond_stop_timing(
struct timeval time1,
char *func,
Connection *conn,
Operation *op
Operation *op,
int level
)
{
if ( with_timing( bi )) {
struct timeval time2;
char *elapsed_time;
char buf[BUFSIZ];
struct timeval time2;
char *elapsed_time;
char buf[BUFSIZ];
*buf = '\0';
*buf = '\0';
gettimeofday( &time2, NULL);
elapsed_time = bdb2i_elapsed( time1, time2 );
gettimeofday( &time2, NULL);
elapsed_time = bdb2i_elapsed( time1, time2 );
if ( conn != NULL ) sprintf( buf, "conn=%d ", conn->c_connid );
if ( op != NULL ) sprintf( buf, "%sop=%d ", buf, op->o_opid );
if ( conn != NULL ) sprintf( buf, "conn=%d ", conn->c_connid );
if ( op != NULL ) sprintf( buf, "%sop=%d ", buf, op->o_opid );
Debug( LDAP_DEBUG_ANY, "%s%s elapsed=%s\n", buf, func, elapsed_time );
Debug( level, "%s%s elapsed=%s\n", buf, func, elapsed_time );
free( elapsed_time );
free( elapsed_time );
}
}

View file

@ -26,7 +26,7 @@ bdb2i_txn_head_init( BDB2_TXN_HEAD *head )
}
sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], BDB2_SUFFIX );
(*fileNodeH)->dbc_name = strdup( fileName );
(*fileNodeH)->dbc_name = ch_strdup( fileName );
fileNodeH = &(*fileNodeH)->next;
@ -119,7 +119,7 @@ bdb2i_txn_attr_config(
}
}
p->dbc_name = strdup( fileName );
p->dbc_name = ch_strdup( fileName );
/* if requested for, we have to open the DB file */
/* BUT NOT "objectclass", 'cause that's a default index ! */