From 8c16d3008784435471cc489779e1e9d1266872ca Mon Sep 17 00:00:00 2001 From: Mark Adamson Date: Tue, 13 Nov 2001 01:38:30 +0000 Subject: [PATCH] optimize number of calls to slap_get_time() --- servers/slapd/back-ldbm/dbcache.c | 12 ++++++------ servers/slapd/back-ldbm/search.c | 2 +- servers/slapd/connection.c | 16 ++++++++++++++-- servers/slapd/daemon.c | 21 ++++++++++++++------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 36e19e9771..c5f92b8761 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -28,7 +28,7 @@ ldbm_cache_open( { struct ldbminfo *li = (struct ldbminfo *) be->be_private; int i, lru, empty; - time_t oldtime, curtime; + time_t oldtime; char buf[MAXPATHLEN]; #ifdef HAVE_ST_BLKSIZE struct stat st; @@ -61,13 +61,12 @@ ldbm_cache_open( #endif - curtime = slap_get_time(); empty = MAXDBCACHE; ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); do { lru = 0; - oldtime = curtime; + oldtime = 1; for ( i = 0; i < MAXDBCACHE; i++ ) { /* see if this slot is free */ if ( li->li_dbcache[i].dbc_name == NULL) { @@ -113,8 +112,9 @@ ldbm_cache_open( } /* keep track of lru db */ - if ( li->li_dbcache[i].dbc_lastref < oldtime - && li->li_dbcache[i].dbc_refcnt == 0 ) + if (( li->li_dbcache[i].dbc_refcnt == 0 ) && + (( oldtime == 1 ) || + ( li->li_dbcache[i].dbc_lastref < oldtime )) ) { lru = i; oldtime = li->li_dbcache[i].dbc_lastref; @@ -170,7 +170,7 @@ ldbm_cache_open( } li->li_dbcache[i].dbc_name = ch_strdup( buf ); li->li_dbcache[i].dbc_refcnt = 1; - li->li_dbcache[i].dbc_lastref = curtime; + li->li_dbcache[i].dbc_lastref = slap_get_time(); li->li_dbcache[i].dbc_flags = flags; li->li_dbcache[i].dbc_dirty = 0; #ifdef HAVE_ST_BLKSIZE diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 1b95248dd6..3f8d76a2ad 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -299,7 +299,7 @@ searchit: ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); /* check time limit */ - if ( tlimit != -1 && slap_get_time() > stoptime ) { + if ( tlimit != -1 && (ID_BLOCK_NIDS(candidates) > 2) && slap_get_time() > stoptime ) { send_search_result( conn, op, LDAP_TIMELIMIT_EXCEEDED, NULL, NULL, v2refs, NULL, nentries ); rc = 0; diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 46d84cfd9c..4d8fa9b3fb 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -300,7 +300,13 @@ static Connection* connection_get( ber_socket_t s ) assert( c->c_conn_state != SLAP_C_INVALID ); assert( sd != AC_SOCKET_INVALID ); - c->c_activitytime = slap_get_time(); +#ifdef SLAPD_MONITOR + c->c_activitytime = slap_get_time(); +#else + if( global_idletimeout > 0 ) { + c->c_activitytime = slap_get_time(); + } +#endif } return c; @@ -474,7 +480,13 @@ long connection_init( /* set to zero until bind, implies LDAP_VERSION3 */ c->c_protocol = 0; - c->c_activitytime = c->c_starttime = slap_get_time(); +#ifdef SLAPD_MONITOR + c->c_activitytime = c->c_starttime = slap_get_time(); +#else + if( global_idletimeout > 0 ) { + c->c_activitytime = c->c_starttime = slap_get_time(); + } +#endif #ifdef LDAP_CONNECTIONLESS c->c_is_udp = 0; diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 8e6ef5b1ff..ddb202bfea 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -940,9 +940,12 @@ slapd_daemon_task( ) { int l; - time_t last_idle_check = slap_get_time(); + time_t last_idle_check; time( &starttime ); + if ( global_idletimeout > 0 ) { + last_idle_check = slap_get_time(); + } for ( l = 0; slap_listeners[l] != NULL; l++ ) { if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) continue; @@ -993,7 +996,7 @@ slapd_daemon_task( int emfile = 0; #define SLAPD_IDLE_CHECK_LIMIT 4 - time_t now = slap_get_time(); + time_t now; fd_set readfds; @@ -1006,11 +1009,15 @@ slapd_daemon_task( struct timeval zero; struct timeval *tvp; - if( emfile || ( global_idletimeout > 0 && difftime( - last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, - now ) < 0 )) - { - connections_timeout_idle(now); + if( emfile ) { + now = slap_get_time(); + connections_timeout_idle( now ); + } + else if ( global_idletimeout > 0 ) { + now = slap_get_time(); + if ( difftime( last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) { + connections_timeout_idle( now ); + } } FD_ZERO( &writefds ); -- 2.39.5