optimize number of calls to slap_get_time()

This commit is contained in:
Mark Adamson 2001-11-13 01:38:30 +00:00
parent 52d3f7b3da
commit 8c16d30087
4 changed files with 35 additions and 16 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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 );