mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-24 13:24:56 +08:00
optimize number of calls to slap_get_time()
This commit is contained in:
parent
52d3f7b3da
commit
8c16d30087
@ -28,7 +28,7 @@ ldbm_cache_open(
|
|||||||
{
|
{
|
||||||
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
||||||
int i, lru, empty;
|
int i, lru, empty;
|
||||||
time_t oldtime, curtime;
|
time_t oldtime;
|
||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
#ifdef HAVE_ST_BLKSIZE
|
#ifdef HAVE_ST_BLKSIZE
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -61,13 +61,12 @@ ldbm_cache_open(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
curtime = slap_get_time();
|
|
||||||
empty = MAXDBCACHE;
|
empty = MAXDBCACHE;
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
|
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
|
||||||
do {
|
do {
|
||||||
lru = 0;
|
lru = 0;
|
||||||
oldtime = curtime;
|
oldtime = 1;
|
||||||
for ( i = 0; i < MAXDBCACHE; i++ ) {
|
for ( i = 0; i < MAXDBCACHE; i++ ) {
|
||||||
/* see if this slot is free */
|
/* see if this slot is free */
|
||||||
if ( li->li_dbcache[i].dbc_name == NULL) {
|
if ( li->li_dbcache[i].dbc_name == NULL) {
|
||||||
@ -113,8 +112,9 @@ ldbm_cache_open(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* keep track of lru db */
|
/* keep track of lru db */
|
||||||
if ( li->li_dbcache[i].dbc_lastref < oldtime
|
if (( li->li_dbcache[i].dbc_refcnt == 0 ) &&
|
||||||
&& li->li_dbcache[i].dbc_refcnt == 0 )
|
(( oldtime == 1 ) ||
|
||||||
|
( li->li_dbcache[i].dbc_lastref < oldtime )) )
|
||||||
{
|
{
|
||||||
lru = i;
|
lru = i;
|
||||||
oldtime = li->li_dbcache[i].dbc_lastref;
|
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_name = ch_strdup( buf );
|
||||||
li->li_dbcache[i].dbc_refcnt = 1;
|
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_flags = flags;
|
||||||
li->li_dbcache[i].dbc_dirty = 0;
|
li->li_dbcache[i].dbc_dirty = 0;
|
||||||
#ifdef HAVE_ST_BLKSIZE
|
#ifdef HAVE_ST_BLKSIZE
|
||||||
|
@ -299,7 +299,7 @@ searchit:
|
|||||||
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
|
||||||
|
|
||||||
/* check time limit */
|
/* 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,
|
send_search_result( conn, op, LDAP_TIMELIMIT_EXCEEDED,
|
||||||
NULL, NULL, v2refs, NULL, nentries );
|
NULL, NULL, v2refs, NULL, nentries );
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
@ -300,7 +300,13 @@ static Connection* connection_get( ber_socket_t s )
|
|||||||
assert( c->c_conn_state != SLAP_C_INVALID );
|
assert( c->c_conn_state != SLAP_C_INVALID );
|
||||||
assert( sd != AC_SOCKET_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;
|
return c;
|
||||||
@ -474,7 +480,13 @@ long connection_init(
|
|||||||
/* set to zero until bind, implies LDAP_VERSION3 */
|
/* set to zero until bind, implies LDAP_VERSION3 */
|
||||||
c->c_protocol = 0;
|
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
|
#ifdef LDAP_CONNECTIONLESS
|
||||||
c->c_is_udp = 0;
|
c->c_is_udp = 0;
|
||||||
|
@ -940,9 +940,12 @@ slapd_daemon_task(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
time_t last_idle_check = slap_get_time();
|
time_t last_idle_check;
|
||||||
time( &starttime );
|
time( &starttime );
|
||||||
|
|
||||||
|
if ( global_idletimeout > 0 ) {
|
||||||
|
last_idle_check = slap_get_time();
|
||||||
|
}
|
||||||
for ( l = 0; slap_listeners[l] != NULL; l++ ) {
|
for ( l = 0; slap_listeners[l] != NULL; l++ ) {
|
||||||
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
|
if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
|
||||||
continue;
|
continue;
|
||||||
@ -993,7 +996,7 @@ slapd_daemon_task(
|
|||||||
int emfile = 0;
|
int emfile = 0;
|
||||||
|
|
||||||
#define SLAPD_IDLE_CHECK_LIMIT 4
|
#define SLAPD_IDLE_CHECK_LIMIT 4
|
||||||
time_t now = slap_get_time();
|
time_t now;
|
||||||
|
|
||||||
|
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
@ -1006,11 +1009,15 @@ slapd_daemon_task(
|
|||||||
struct timeval zero;
|
struct timeval zero;
|
||||||
struct timeval *tvp;
|
struct timeval *tvp;
|
||||||
|
|
||||||
if( emfile || ( global_idletimeout > 0 && difftime(
|
if( emfile ) {
|
||||||
last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT,
|
now = slap_get_time();
|
||||||
now ) < 0 ))
|
connections_timeout_idle( now );
|
||||||
{
|
}
|
||||||
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 );
|
FD_ZERO( &writefds );
|
||||||
|
Loading…
Reference in New Issue
Block a user