]> git.sur5r.net Git - openldap/commitdiff
Use per-thread slap_counters to eliminate lock contention
authorHoward Chu <hyc@openldap.org>
Thu, 25 Oct 2007 08:45:00 +0000 (08:45 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 25 Oct 2007 08:45:00 +0000 (08:45 +0000)
servers/slapd/back-monitor/operation.c
servers/slapd/back-monitor/sent.c
servers/slapd/connection.c
servers/slapd/daemon.c
servers/slapd/init.c
servers/slapd/proto-slap.h
servers/slapd/result.c
servers/slapd/slap.h

index 74bd27402c2805d361cacb098eec6c8bb4ff937c..10086079187bbbf407b1bff772b495ec2bad9464 100644 (file)
@@ -177,6 +177,7 @@ monitor_subsys_ops_update(
        struct berval           rdn;
        int                     i;
        Attribute               *a;
+       slap_counters_t *sc;
        static struct berval    bv_ops = BER_BVC( "cn=operations" );
 
        assert( mi != NULL );
@@ -188,21 +189,35 @@ monitor_subsys_ops_update(
                ldap_pvt_mp_init( nInitiated );
                ldap_pvt_mp_init( nCompleted );
 
-               ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
+               ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
                for ( i = 0; i < SLAP_OP_LAST; i++ ) {
                        ldap_pvt_mp_add( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
                        ldap_pvt_mp_add( nCompleted, slap_counters.sc_ops_completed_[ i ] );
                }
-               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
+               for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+                       ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+                       for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+                               ldap_pvt_mp_add( nInitiated, sc->sc_ops_initiated_[ i ] );
+                               ldap_pvt_mp_add( nCompleted, sc->sc_ops_completed_[ i ] );
+                       }
+                       ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+               }
+               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
                
        } else {
                for ( i = 0; i < SLAP_OP_LAST; i++ ) {
                        if ( dn_match( &rdn, &monitor_op[ i ].nrdn ) )
                        {
-                               ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
+                               ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
                                ldap_pvt_mp_init_set( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
                                ldap_pvt_mp_init_set( nCompleted, slap_counters.sc_ops_completed_[ i ] );
-                               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
+                               for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+                                       ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+                                       ldap_pvt_mp_add( nInitiated, sc->sc_ops_initiated_[ i ] );
+                                       ldap_pvt_mp_add( nCompleted, sc->sc_ops_completed_[ i ] );
+                                       ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+                               }
+                               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
                                break;
                        }
                }
index 1be74711d9a0c38f68c9b0fc7b30f7bc94f9962c..d4d11fd30cd868749826dc5b4c0cc6ee8a13b161 100644 (file)
@@ -166,6 +166,7 @@ monitor_subsys_sent_update(
        struct berval           nrdn;
        ldap_pvt_mp_t           n;
        Attribute               *a;
+       slap_counters_t *sc;
        int                     i;
 
        assert( mi != NULL );
@@ -183,28 +184,48 @@ monitor_subsys_sent_update(
                return SLAP_CB_CONTINUE;
        }
 
-       ldap_pvt_thread_mutex_lock(&slap_counters.sc_sent_mutex);
+       ldap_pvt_thread_mutex_lock(&slap_counters.sc_mutex);
        switch ( i ) {
        case MONITOR_SENT_ENTRIES:
                ldap_pvt_mp_init_set( n, slap_counters.sc_entries );
+               for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+                       ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+                       ldap_pvt_mp_add( n, sc->sc_entries );
+                       ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+               }
                break;
 
        case MONITOR_SENT_REFERRALS:
                ldap_pvt_mp_init_set( n, slap_counters.sc_refs );
+               for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+                       ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+                       ldap_pvt_mp_add( n, sc->sc_refs );
+                       ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+               }
                break;
 
        case MONITOR_SENT_PDU:
                ldap_pvt_mp_init_set( n, slap_counters.sc_pdu );
+               for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+                       ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+                       ldap_pvt_mp_add( n, sc->sc_pdu );
+                       ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+               }
                break;
 
        case MONITOR_SENT_BYTES:
                ldap_pvt_mp_init_set( n, slap_counters.sc_bytes );
+               for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+                       ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+                       ldap_pvt_mp_add( n, sc->sc_bytes );
+                       ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+               }
                break;
 
        default:
                assert(0);
        }
-       ldap_pvt_thread_mutex_unlock(&slap_counters.sc_sent_mutex);
+       ldap_pvt_thread_mutex_unlock(&slap_counters.sc_mutex);
        
        a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
        assert( a != NULL );
index d1794964979b55e22fef6be199d34899ad900dae..c2e5a74318186f7f14de9048f4415d7129e69b6f 100644 (file)
@@ -83,8 +83,6 @@ connection_state2str( int state )
 
 static Connection* connection_get( ber_socket_t s );
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
-
 typedef struct conn_readinfo {
        Operation *op;
        ldap_pvt_thread_start_t *func;
@@ -94,15 +92,10 @@ typedef struct conn_readinfo {
 } conn_readinfo;
 
 static int connection_input( Connection *c, conn_readinfo *cri );
-#else
-static int connection_input( Connection *c );
-#endif
 static void connection_close( Connection *c );
 
 static int connection_op_activate( Operation *op );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 static void connection_op_queue( Operation *op );
-#endif
 static int connection_resched( Connection *conn );
 static void connection_abandon( Connection *conn );
 static void connection_destroy( Connection *c );
@@ -983,24 +976,24 @@ void connection_done( Connection *c )
 /* FIXME: returns 0 in case of failure */
 #define INCR_OP_INITIATED(index) \
        do { \
-               ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
-               ldap_pvt_mp_add_ulong(slap_counters.sc_ops_initiated_[(index)], 1); \
-               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
+               ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); \
+               ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_initiated_[(index)], 1); \
+               ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); \
        } while (0)
 #define INCR_OP_COMPLETED(index) \
        do { \
-               ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
-               ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed, 1); \
-               ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed_[(index)], 1); \
-               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
+               ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); \
+               ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_completed, 1); \
+               ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_completed_[(index)], 1); \
+               ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); \
        } while (0)
 #else /* !SLAPD_MONITOR */
 #define INCR_OP_INITIATED(index) do { } while (0)
 #define INCR_OP_COMPLETED(index) \
        do { \
-               ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
-               ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed, 1); \
-               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
+               ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); \
+               ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_completed, 1); \
+               ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); \
        } while (0)
 #endif /* !SLAPD_MONITOR */
 
@@ -1021,6 +1014,62 @@ static BI_op_func *opfun[] = {
        NULL
 };
 
+/* Counters are per-thread, not per-connection.
+ */
+static void
+conn_counter_destroy( void *key, void *data )
+{
+       slap_counters_t **prev, *sc;
+
+       ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
+       for ( prev = &slap_counters.sc_next, sc = slap_counters.sc_next; sc;
+               prev = &sc->sc_next, sc = sc->sc_next ) {
+               if ( sc == data ) {
+                       int i;
+
+                       *prev = sc->sc_next;
+                       /* Copy data to main counter */
+                       ldap_pvt_mp_add( slap_counters.sc_bytes, sc->sc_bytes );
+                       ldap_pvt_mp_add( slap_counters.sc_pdu, sc->sc_pdu );
+                       ldap_pvt_mp_add( slap_counters.sc_entries, sc->sc_entries );
+                       ldap_pvt_mp_add( slap_counters.sc_refs, sc->sc_refs );
+                       ldap_pvt_mp_add( slap_counters.sc_ops_initiated, sc->sc_ops_initiated );
+                       ldap_pvt_mp_add( slap_counters.sc_ops_completed, sc->sc_ops_completed );
+#ifdef SLAPD_MONITOR
+                       for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+                               ldap_pvt_mp_add( slap_counters.sc_ops_initiated_[ i ], sc->sc_ops_initiated_[ i ] );
+                               ldap_pvt_mp_add( slap_counters.sc_ops_initiated_[ i ], sc->sc_ops_completed_[ i ] );
+                       }
+#endif /* SLAPD_MONITOR */
+                       slap_counters_destroy( sc );
+                       ber_memfree_x( data, NULL );
+                       break;
+               }
+       }
+       ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
+}
+
+static void
+conn_counter_init( Operation *op, void *ctx )
+{
+       slap_counters_t *sc;
+       void *vsc = NULL;
+
+       if ( ldap_pvt_thread_pool_getkey( ctx, conn_counter_init, &vsc, NULL ) || !vsc ) {
+               vsc = ch_malloc( sizeof( slap_counters_t ));
+               sc = vsc;
+               slap_counters_init( sc );
+               ldap_pvt_thread_pool_setkey( ctx, conn_counter_init, vsc,
+                       conn_counter_destroy );
+
+               ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
+               sc->sc_next = slap_counters.sc_next;
+               slap_counters.sc_next = sc;
+               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
+       }
+       op->o_counters = vsc;
+}
+
 static void *
 connection_operation( void *ctx, void *arg_v )
 {
@@ -1034,10 +1083,11 @@ connection_operation( void *ctx, void *arg_v )
        void *memctx_null = NULL;
        ber_len_t memsiz;
 
-       ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
+       conn_counter_init( op, ctx );
+       ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
        /* FIXME: returns 0 in case of failure */
-       ldap_pvt_mp_add_ulong(slap_counters.sc_ops_initiated, 1);
-       ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
+       ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_initiated, 1);
+       ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
 
        op->o_threadctx = ctx;
        op->o_tid = ldap_pvt_thread_pool_tid( ctx );
@@ -1219,8 +1269,6 @@ void connection_client_stop(
        connection_return( c );
 }
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
-
 static int connection_read( ber_socket_t s, conn_readinfo *cri );
 
 static void* connection_read_thread( void* ctx, void* argv )
@@ -1273,14 +1321,9 @@ int connection_read_activate( ber_socket_t s )
 
        return rc;
 }
-#endif
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 static int
 connection_read( ber_socket_t s, conn_readinfo *cri )
-#else
-int connection_read(ber_socket_t s)
-#endif
 {
        int rc = 0;
        Connection *c;
@@ -1309,15 +1352,9 @@ int connection_read(ber_socket_t s)
        }
 
        if ( c->c_conn_state == SLAP_C_CLIENT ) {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                cri->func = c->c_clientfunc;
                cri->arg = c->c_clientarg;
                /* read should already be cleared */
-#else
-               slapd_clr_read( s, 0 );
-               ldap_pvt_thread_pool_submit( &connection_pool,
-                       c->c_clientfunc, c->c_clientarg );
-#endif
                connection_return( c );
                return 0;
        }
@@ -1372,10 +1409,7 @@ int connection_read(ber_socket_t s)
                /* if success and data is ready, fall thru to data input loop */
                if( !ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) )
                {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        slapd_set_read( s, 1 );
-#endif
-
                        connection_return( c );
                        return 0;
                }
@@ -1386,10 +1420,7 @@ int connection_read(ber_socket_t s)
        if ( c->c_sasl_layers ) {
                /* If previous layer is not removed yet, give up for now */
                if ( !c->c_sasl_sockctx ) {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        slapd_set_read( s, 1 );
-#endif
-
                        connection_return( c );
                        return 0;
                }
@@ -1417,11 +1448,7 @@ int connection_read(ber_socket_t s)
 
        do {
                /* How do we do this without getting into a busy loop ? */
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                rc = connection_input( c, cri );
-#else
-               rc = connection_input( c );
-#endif
        }
 #ifdef DATA_READY_LOOP
        while( !rc && ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ));
@@ -1443,33 +1470,18 @@ int connection_read(ber_socket_t s)
                return 0;
        }
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
        if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
                slapd_set_write( s, 0 );
        }
 
        slapd_set_read( s, 1 );
-#else
-       if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) ) {
-               slapd_set_read( s, 1 );
-       }
-
-       if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
-               slapd_set_write( s, 1 );
-       }
-#endif
-
        connection_return( c );
 
        return 0;
 }
 
 static int
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 connection_input( Connection *conn , conn_readinfo *cri )
-#else
-connection_input( Connection *conn )
-#endif
 {
        Operation *op;
        ber_tag_t       tag;
@@ -1563,11 +1575,7 @@ connection_input( Connection *conn )
                connection_abandon( conn );
        }
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
        ctx = cri->ctx;
-#else
-       ctx = NULL;
-#endif
        op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++, ctx );
 
        op->o_conn = conn;
@@ -1658,7 +1666,6 @@ connection_input( Connection *conn )
        } else {
                conn->c_n_ops_executing++;
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                /*
                 * The first op will be processed in the same thread context,
                 * as long as there is only one op total.
@@ -1677,9 +1684,6 @@ connection_input( Connection *conn )
                        }
                        connection_op_activate( op );
                }
-#else
-               connection_op_activate( op );
-#endif
        }
 
 #ifdef NO_THREADS
@@ -2002,6 +2006,7 @@ connection_fake_init2(
        op->o_threadctx = ctx;
        op->o_tid = ldap_pvt_thread_pool_tid( ctx );
 
+       op->o_counters = &slap_counters;
        op->o_conn = conn;
        op->o_connid = op->o_conn->c_connid;
        connection_init_log_prefix( op );
index 5949e543d732d4b177689720dcaf5778d0fdcae5..641e4380424fefb7711fe0965df42458b8d4c547 100644 (file)
@@ -182,14 +182,12 @@ static struct slap_daemon {
 # define SLAP_SOCK_CLR_READ(s)         SLAP_EPOLL_SOCK_CLR((s), EPOLLIN)
 # define SLAP_SOCK_CLR_WRITE(s)                SLAP_EPOLL_SOCK_CLR((s), EPOLLOUT)
 
-# ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 #  define SLAP_SOCK_SET_SUSPEND(s) \
        ( slap_daemon.sd_suspend[SLAP_EPOLL_SOCK_IX(s)] = 1 )
 #  define SLAP_SOCK_CLR_SUSPEND(s) \
        ( slap_daemon.sd_suspend[SLAP_EPOLL_SOCK_IX(s)] = 0 )
 #  define SLAP_SOCK_IS_SUSPEND(s) \
        ( slap_daemon.sd_suspend[SLAP_EPOLL_SOCK_IX(s)] == 1 )
-# endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
 # define SLAP_EPOLL_EVENT_CLR(i, mode) (revents[(i)].events &= ~(mode))
 
@@ -356,14 +354,12 @@ static struct slap_daemon {
 # define SLAP_SOCK_CLR_READ(s)         SLAP_DEVPOLL_SOCK_CLR((s), POLLIN)
 # define SLAP_SOCK_CLR_WRITE(s)                SLAP_DEVPOLL_SOCK_CLR((s), POLLOUT)
 
-# ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 #  define SLAP_SOCK_SET_SUSPEND(s) \
        ( slap_daemon.sd_suspend[SLAP_DEVPOLL_SOCK_IX((s))] = 1 )
 #  define SLAP_SOCK_CLR_SUSPEND(s) \
        ( slap_daemon.sd_suspend[SLAP_DEVPOLL_SOCK_IX((s))] = 0 )
 #  define SLAP_SOCK_IS_SUSPEND(s) \
        ( slap_daemon.sd_suspend[SLAP_DEVPOLL_SOCK_IX((s))] == 1 )
-# endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
 # define SLAP_DEVPOLL_EVENT_CLR(i, mode)       (revents[(i)].events &= ~(mode))
 
@@ -704,9 +700,7 @@ slapd_add( ber_socket_t s, int isactive, Listener *sl )
 
        ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
        WAKE_LISTENER(1);
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 }
 
 /*
@@ -1128,9 +1122,7 @@ slap_open_listener(
 
        l.sl_url.bv_val = NULL;
        l.sl_mute = 0;
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
        l.sl_busy = 0;
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
 #ifndef HAVE_TLS
        if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
@@ -1608,13 +1600,11 @@ slap_listener(
 
        s = accept( sl->sl_sd, (struct sockaddr *) &from, &len );
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
        /* Resume the listener FD to allow concurrent-processing of
         * additional incoming connections.
         */
        sl->sl_busy = 0;
        WAKE_LISTENER(1);
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
        if ( s == AC_SOCKET_INVALID ) {
                int err = sock_errno();
@@ -1844,7 +1834,6 @@ slap_listener(
        return 0;
 }
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 static void*
 slap_listener_thread(
        void* ctx,
@@ -1885,7 +1874,6 @@ slap_listener_activate(
        }
        return rc;
 }
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
 static void *
 slapd_daemon_task(
@@ -1972,7 +1960,6 @@ slapd_daemon_task(
                        return (void*)-1;
                }
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                /* make the listening socket non-blocking */
                if ( ber_pvt_socket_set_nonblock( slap_listeners[l]->sl_sd, 1 ) < 0 ) {
                        Debug( LDAP_DEBUG_ANY, "slapd_daemon_task: "
@@ -1981,7 +1968,6 @@ slapd_daemon_task(
                        slapd_shutdown = 2;
                        return (void*)-1;
                }
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
                slapd_add( slap_listeners[l]->sl_sd, 0, slap_listeners[l] );
        }
@@ -2061,11 +2047,7 @@ slapd_daemon_task(
 
                        if ( lr->sl_sd == AC_SOCKET_INVALID ) continue;
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        if ( lr->sl_mute || lr->sl_busy )
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
-                       if ( lr->sl_mute )
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
                        {
                                SLAP_SOCK_CLR_READ( lr->sl_sd );
                        } else {
@@ -2140,7 +2122,6 @@ slapd_daemon_task(
                                continue;
                        }
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        if ( lr->sl_busy ) {
                                Debug( LDAP_DEBUG_CONNS,
                                        "daemon: " SLAP_EVENT_FNAME ": "
@@ -2148,7 +2129,6 @@ slapd_daemon_task(
                                        lr->sl_sd, 0, 0 );
                                continue;
                        }
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
 
                        Debug( LDAP_DEBUG_CONNS,
                                "daemon: " SLAP_EVENT_FNAME ": "
@@ -2231,11 +2211,7 @@ slapd_daemon_task(
                        SLAP_EVENT_CLR_WRITE( slap_listeners[l]->sl_sd );
                        ns--;
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        rc = slap_listener_activate( slap_listeners[l] );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
-                       rc = slap_listener( slap_listeners[l] );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
                }
 
                /* bypass the following tests if no descriptors left */
@@ -2339,11 +2315,7 @@ slapd_daemon_task(
                         * active.
                         */
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                        connection_read_activate( rd );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
-                       connection_read( rd );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
                }
 #else  /* !SLAP_EVENTS_ARE_INDEXED */
        /* FIXME */
@@ -2395,11 +2367,7 @@ slapd_daemon_task(
                        int rc = 1, fd;
 
                        if ( SLAP_EVENT_IS_LISTENER( i ) ) {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                                rc = slap_listener_activate( SLAP_EVENT_LISTENER( i ) );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
-                               rc = slap_listener( SLAP_EVENT_LISTENER( i ) );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
                        }
 
                        /* If we found a regular listener, rc is now zero, and we
@@ -2441,17 +2409,7 @@ slapd_daemon_task(
                                                fd, 0, 0 );
 
                                        SLAP_EVENT_CLR_READ( i );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
                                        connection_read_activate( fd );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
-                                       /*
-                                        * NOTE: it is possible that the connection was closed
-                                        * and that the stream is now inactive.
-                                        * connection_read() must valid the stream is still
-                                        * active.
-                                        */
-                                       connection_read( fd );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
                                } else {
                                        Debug( LDAP_DEBUG_CONNS,
                                                "daemon: hangup on %d\n", fd, 0, 0 );
index 28f30521c6913a6eec4709a5538f39a5f9461421..d1cb5ecc6eabebe18adb2918a263b0f359ff7415 100644 (file)
@@ -67,7 +67,7 @@ int                   connection_pool_max = SLAP_MAX_WORKER_THREADS;
 int            slap_tool_thread_max = 1;
 ldap_pvt_thread_mutex_t        gmtime_mutex;
 
-slap_counters_t                        slap_counters;
+slap_counters_t                        slap_counters, *slap_counters_list;
 
 static const char* slap_name = NULL;
 int slapMode = SLAP_UNDEFINED_MODE;
@@ -76,7 +76,6 @@ int
 slap_init( int mode, const char *name )
 {
        int rc;
-       int i;
 
        assert( mode );
 
@@ -144,27 +143,12 @@ slap_init( int mode, const char *name )
                ldap_pvt_thread_pool_init( &connection_pool,
                                connection_pool_max, 0);
 
-               ldap_pvt_thread_mutex_init( &slap_counters.sc_sent_mutex );
-               ldap_pvt_thread_mutex_init( &slap_counters.sc_ops_mutex );
-               ldap_pvt_mp_init( slap_counters.sc_bytes );
-               ldap_pvt_mp_init( slap_counters.sc_pdu );
-               ldap_pvt_mp_init( slap_counters.sc_entries );
-               ldap_pvt_mp_init( slap_counters.sc_refs );
-
-               ldap_pvt_mp_init( slap_counters.sc_ops_initiated );
-               ldap_pvt_mp_init( slap_counters.sc_ops_completed );
+               slap_counters_init( &slap_counters );
 
                ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex );
                LDAP_STAILQ_INIT( &slapd_rq.task_list );
                LDAP_STAILQ_INIT( &slapd_rq.run_list );
 
-#ifdef SLAPD_MONITOR
-               for ( i = 0; i < SLAP_OP_LAST; i++ ) {
-                       ldap_pvt_mp_init( slap_counters.sc_ops_initiated_[ i ] );
-                       ldap_pvt_mp_init( slap_counters.sc_ops_completed_[ i ] );
-               }
-#endif /* SLAPD_MONITOR */
-
                ldap_pvt_thread_mutex_init( &gmtime_mutex );
                slap_passwd_init();
 
@@ -264,7 +248,6 @@ int slap_shutdown( Backend *be )
 int slap_destroy(void)
 {
        int rc;
-       int i;
 
        Debug( LDAP_DEBUG_TRACE,
                "%s destroy: freeing system resources.\n",
@@ -288,24 +271,8 @@ int slap_destroy(void)
 
        switch ( slapMode & SLAP_MODE ) {
        case SLAP_SERVER_MODE:
-
        case SLAP_TOOL_MODE:
-
-               ldap_pvt_thread_mutex_destroy( &slap_counters.sc_sent_mutex );
-               ldap_pvt_thread_mutex_destroy( &slap_counters.sc_ops_mutex );
-               ldap_pvt_mp_clear( slap_counters.sc_bytes );
-               ldap_pvt_mp_clear( slap_counters.sc_pdu );
-               ldap_pvt_mp_clear( slap_counters.sc_entries );
-               ldap_pvt_mp_clear( slap_counters.sc_refs );
-               ldap_pvt_mp_clear( slap_counters.sc_ops_initiated );
-               ldap_pvt_mp_clear( slap_counters.sc_ops_completed );
-
-#ifdef SLAPD_MONITOR
-               for ( i = 0; i < SLAP_OP_LAST; i++ ) {
-                       ldap_pvt_mp_clear( slap_counters.sc_ops_initiated_[ i ] );
-                       ldap_pvt_mp_clear( slap_counters.sc_ops_completed_[ i ] );
-               }
-#endif /* SLAPD_MONITOR */
+               slap_counters_destroy( &slap_counters );
                break;
 
        default:
@@ -324,3 +291,46 @@ int slap_destroy(void)
        /* should destroy the above mutex */
        return rc;
 }
+
+void slap_counters_init( slap_counters_t *sc )
+{
+       int i;
+
+       ldap_pvt_thread_mutex_init( &sc->sc_mutex );
+       ldap_pvt_mp_init( sc->sc_bytes );
+       ldap_pvt_mp_init( sc->sc_pdu );
+       ldap_pvt_mp_init( sc->sc_entries );
+       ldap_pvt_mp_init( sc->sc_refs );
+
+       ldap_pvt_mp_init( sc->sc_ops_initiated );
+       ldap_pvt_mp_init( sc->sc_ops_completed );
+
+#ifdef SLAPD_MONITOR
+       for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+               ldap_pvt_mp_init( sc->sc_ops_initiated_[ i ] );
+               ldap_pvt_mp_init( sc->sc_ops_completed_[ i ] );
+       }
+#endif /* SLAPD_MONITOR */
+}
+
+void slap_counters_destroy( slap_counters_t *sc )
+{
+       int i;
+
+       ldap_pvt_thread_mutex_destroy( &sc->sc_mutex );
+       ldap_pvt_mp_clear( sc->sc_bytes );
+       ldap_pvt_mp_clear( sc->sc_pdu );
+       ldap_pvt_mp_clear( sc->sc_entries );
+       ldap_pvt_mp_clear( sc->sc_refs );
+
+       ldap_pvt_mp_clear( sc->sc_ops_initiated );
+       ldap_pvt_mp_clear( sc->sc_ops_completed );
+
+#ifdef SLAPD_MONITOR
+       for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+               ldap_pvt_mp_clear( sc->sc_ops_initiated_[ i ] );
+               ldap_pvt_mp_clear( sc->sc_ops_completed_[ i ] );
+       }
+#endif /* SLAPD_MONITOR */
+}
+
index 2a56f59c12528618999336dec0ee237fa91c8cad..11f05fec56d1c6bdf559a3f0b549bfab003d8ac6 100644 (file)
@@ -736,11 +736,7 @@ LDAP_SLAPD_F (int) connection_state_closing LDAP_P(( Connection *c ));
 LDAP_SLAPD_F (const char *) connection_state2str LDAP_P(( int state ))
        LDAP_GCCATTR((const));
 
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
 LDAP_SLAPD_F (int) connection_read_activate LDAP_P((ber_socket_t s));
-#else
-LDAP_SLAPD_F (int) connection_read LDAP_P((ber_socket_t s));
-#endif
 LDAP_SLAPD_F (int) connection_write LDAP_P((ber_socket_t s));
 
 LDAP_SLAPD_F (unsigned long) connections_nextid(void);
@@ -1067,6 +1063,8 @@ LDAP_SLAPD_F (int)        slap_init LDAP_P((int mode, const char* name));
 LDAP_SLAPD_F (int)     slap_startup LDAP_P(( Backend *be ));
 LDAP_SLAPD_F (int)     slap_shutdown LDAP_P(( Backend *be ));
 LDAP_SLAPD_F (int)     slap_destroy LDAP_P((void));
+LDAP_SLAPD_F (void) slap_counters_init LDAP_P((slap_counters_t *sc));
+LDAP_SLAPD_F (void) slap_counters_destroy LDAP_P((slap_counters_t *sc));
 
 LDAP_SLAPD_V (char *)  slap_known_controls[];
 
index 2befb75233e909d4ab625a95e09b57b3e2d746c5..7be8d952494c4f50a856de25e982e7e63e31f708 100644 (file)
@@ -506,10 +506,10 @@ send_ldap_response(
                goto cleanup;
        }
 
-       ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
-       ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
-       ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
-       ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+       ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
+       ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
+       ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
+       ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
 
 cleanup:;
        /* Tell caller that we did this for real, as opposed to being
@@ -1192,11 +1192,11 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
                }
                rs->sr_nentries++;
 
-               ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
-               ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
-               ldap_pvt_mp_add_ulong( slap_counters.sc_entries, 1 );
-               ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
-               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+               ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
+               ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
+               ldap_pvt_mp_add_ulong( op->o_counters->sc_entries, 1 );
+               ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
+               ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
        }
 
        Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
@@ -1359,11 +1359,11 @@ slap_send_search_reference( Operation *op, SlapReply *rs )
        if ( bytes < 0 ) {
                rc = LDAP_UNAVAILABLE;
        } else {
-               ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
-               ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
-               ldap_pvt_mp_add_ulong( slap_counters.sc_refs, 1 );
-               ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
-               ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+               ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
+               ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
+               ldap_pvt_mp_add_ulong( op->o_counters->sc_refs, 1 );
+               ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
+               ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
        }
 #ifdef LDAP_CONNECTIONLESS
        }
index d3d35a09c132ac34233dd8ceb13bf103caf80cdc..8e12ed64c6f2224a8c0e9ee9588b631006771800 100644 (file)
@@ -2388,6 +2388,39 @@ struct slap_control_ids {
        int sc_valuesReturnFilter;
 };
 
+/*
+ * Operation indices
+ */
+typedef enum {
+       SLAP_OP_BIND = 0,
+       SLAP_OP_UNBIND,
+       SLAP_OP_SEARCH,
+       SLAP_OP_COMPARE,
+       SLAP_OP_MODIFY,
+       SLAP_OP_MODRDN,
+       SLAP_OP_ADD,
+       SLAP_OP_DELETE,
+       SLAP_OP_ABANDON,
+       SLAP_OP_EXTENDED,
+       SLAP_OP_LAST
+} slap_op_t;
+
+typedef struct slap_counters_t {
+       struct slap_counters_t  *sc_next;
+       ldap_pvt_thread_mutex_t sc_mutex;
+       ldap_pvt_mp_t           sc_bytes;
+       ldap_pvt_mp_t           sc_pdu;
+       ldap_pvt_mp_t           sc_entries;
+       ldap_pvt_mp_t           sc_refs;
+
+       ldap_pvt_mp_t           sc_ops_completed;
+       ldap_pvt_mp_t           sc_ops_initiated;
+#ifdef SLAPD_MONITOR
+       ldap_pvt_mp_t           sc_ops_completed_[SLAP_OP_LAST];
+       ldap_pvt_mp_t           sc_ops_initiated_[SLAP_OP_LAST];
+#endif /* SLAPD_MONITOR */
+} slap_counters_t;
+
 /*
  * represents an operation pending from an ldap client
  */
@@ -2405,6 +2438,8 @@ typedef struct Opheader {
        void    *oh_tmpmemctx;          /* slab malloc context */
        BerMemoryFunctions *oh_tmpmfuncs;
 
+       slap_counters_t *oh_counters;
+
        char            oh_log_prefix[ /* sizeof("conn=18446744073709551615 op=18446744073709551615") */ SLAP_TEXT_BUFLEN ];
 
 #ifdef LDAP_SLAPI
@@ -2437,6 +2472,7 @@ struct Operation {
 #define o_threadctx o_hdr->oh_threadctx
 #define o_tmpmemctx o_hdr->oh_tmpmemctx
 #define o_tmpmfuncs o_hdr->oh_tmpmfuncs
+#define o_counters o_hdr->oh_counters
 
 #define        o_tmpalloc      o_tmpmfuncs->bmf_malloc
 #define o_tmpcalloc    o_tmpmfuncs->bmf_calloc
@@ -2817,39 +2853,6 @@ struct slap_listener {
 #define sl_addr        sl_sa.sa_in_addr
 };
 
-/*
- * Operation indices
- */
-typedef enum {
-       SLAP_OP_BIND = 0,
-       SLAP_OP_UNBIND,
-       SLAP_OP_SEARCH,
-       SLAP_OP_COMPARE,
-       SLAP_OP_MODIFY,
-       SLAP_OP_MODRDN,
-       SLAP_OP_ADD,
-       SLAP_OP_DELETE,
-       SLAP_OP_ABANDON,
-       SLAP_OP_EXTENDED,
-       SLAP_OP_LAST
-} slap_op_t;
-
-typedef struct slap_counters_t {
-       ldap_pvt_thread_mutex_t sc_sent_mutex;
-       ldap_pvt_mp_t           sc_bytes;
-       ldap_pvt_mp_t           sc_pdu;
-       ldap_pvt_mp_t           sc_entries;
-       ldap_pvt_mp_t           sc_refs;
-
-       ldap_pvt_thread_mutex_t sc_ops_mutex;
-       ldap_pvt_mp_t           sc_ops_completed;
-       ldap_pvt_mp_t           sc_ops_initiated;
-#ifdef SLAPD_MONITOR
-       ldap_pvt_mp_t           sc_ops_completed_[SLAP_OP_LAST];
-       ldap_pvt_mp_t           sc_ops_initiated_[SLAP_OP_LAST];
-#endif /* SLAPD_MONITOR */
-} slap_counters_t;
-
 /*
  * Better know these all around slapd
  */