You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2015/03/10 00:39:05 UTC

svn commit: r1665385 - in /httpd/httpd/trunk/server/mpm/motorz: motorz.c motorz.h

Author: ylavic
Date: Mon Mar  9 23:39:05 2015
New Revision: 1665385

URL: http://svn.apache.org/r1665385
Log:
motorz: revert bogus r1665381.

Modified:
    httpd/httpd/trunk/server/mpm/motorz/motorz.c
    httpd/httpd/trunk/server/mpm/motorz/motorz.h

Modified: httpd/httpd/trunk/server/mpm/motorz/motorz.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/motorz/motorz.c?rev=1665385&r1=1665384&r2=1665385&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/motorz/motorz.c (original)
+++ httpd/httpd/trunk/server/mpm/motorz/motorz.c Mon Mar  9 23:39:05 2015
@@ -81,25 +81,6 @@ static int indexing_compk(void *ac, void
     return ((*t1 < t2) ? -1 : ((*t1 > t2) ? 1 : 0));
 }
 
-static motorz_timer_t *motorz_acquire_timer(motorz_core_t *mz)
-{
-    motorz_timer_t *elem = mz->spare_timers;
-    if (elem) {
-        mz->spare_timers = elem->next;
-    }
-    else {
-        elem = apr_palloc(mz->pool, sizeof *elem);
-    }
-    memset(elem, 0, sizeof *elem);
-    return elem;
-}
-
-static void motorz_release_timer(motorz_core_t *mz, motorz_timer_t *elem)
-{
-    elem->next = mz->spare_timers;
-    mz->spare_timers = elem;;
-}
-
 static apr_status_t motorz_timer_pool_cleanup(void *baton)
 {
     motorz_timer_t *elem = (motorz_timer_t *)baton;
@@ -107,7 +88,6 @@ static apr_status_t motorz_timer_pool_cl
 
     apr_thread_mutex_lock(mz->mtx);
     apr_skiplist_remove(mz->timer_ring, elem, NULL);
-    motorz_release_timer(mz, elem);
     apr_thread_mutex_unlock(mz->mtx);
 
     return APR_SUCCESS;
@@ -217,25 +197,19 @@ static apr_status_t motorz_io_accept(mot
     return APR_SUCCESS;
 }
 
-static void *motorz_timer_invoke(apr_thread_t *thread, void *baton)
+static void motorz_timer_run(motorz_timer_t *ep)
 {
-    motorz_timer_t *ep = (motorz_timer_t *)baton;
-    motorz_conn_t *scon = (motorz_conn_t *) ep->baton;
+    apr_pool_cleanup_kill(ep->pool, ep, motorz_timer_pool_cleanup);
 
-    scon->c->current_thread = thread;
     ep->cb(ep->mz, ep->baton);
-
-    return NULL;
 }
 
-static apr_status_t motorz_timer_event_process(motorz_core_t *mz, motorz_timer_t *te)
+static void *motorz_timer_invoke(apr_thread_t *thread, void *baton)
 {
-    apr_pool_cleanup_kill(te->pool, te, motorz_timer_pool_cleanup);
-    motorz_release_timer(mz, te);
+    motorz_timer_t *ep = (motorz_timer_t *)baton;
 
-    return apr_thread_pool_push(mz->workers,
-                                motorz_timer_invoke,
-                                te, APR_THREAD_TASK_PRIORITY_NORMAL, NULL);
+    motorz_timer_run(ep);
+    return NULL;
 }
 
 static void *motorz_io_invoke(apr_thread_t * thread, void *baton)
@@ -291,7 +265,7 @@ static void motorz_register_timer(motorz
 
     apr_thread_mutex_lock(mz->mtx);
 
-    elem = motorz_acquire_timer(mz);
+    elem = (motorz_timer_t *) apr_pcalloc(shutdown_pool, sizeof(motorz_timer_t));
 
     elem->expires = t;
     elem->cb = cb;
@@ -420,9 +394,9 @@ static apr_status_t motorz_io_process(mo
             motorz_register_timer(scon->mz,
                                   motorz_io_timeout_cb,
                                   scon,
-                                  scon->c->base_server != NULL
-                                  ? scon->c->base_server->keep_alive_timeout
-                                  : ap_server_conf->keep_alive_timeout,
+                                  scon->c->base_server !=
+                                  NULL ? scon->c->base_server->
+                                  timeout : ap_server_conf->timeout,
                                   scon->pool);
 
             scon->pfd.reqevents = (
@@ -564,7 +538,6 @@ static void clean_child_exit(int code)
     exit(code);
 }
 
-#if 0 /* unused for now */
 static apr_status_t accept_mutex_on(void)
 {
     motorz_core_t *mz = motorz_core_get();
@@ -607,7 +580,6 @@ static apr_status_t accept_mutex_off(voi
     }
     return APR_SUCCESS;
 }
-#endif
 
 /* On some architectures it's safe to do unserialized accept()s in the single
  * Listen case.  But it's never safe to do it in the case where there's
@@ -1013,10 +985,16 @@ static void child_main(motorz_core_t *mz
             apr_thread_mutex_lock(mz->mtx);
 
             /* now iterate any timers and push to worker pool */
-            while (te && te->expires < tnow) {
-                apr_skiplist_pop(mz->timer_ring, NULL);
-                motorz_timer_event_process(mz, te);
-
+            while (te) {
+                if (te->expires < tnow) {
+                    apr_skiplist_pop(mz->timer_ring, NULL);
+                    apr_thread_pool_push(mz->workers,
+                                         motorz_timer_invoke,
+                                         te,
+                                         APR_THREAD_TASK_PRIORITY_NORMAL, NULL);
+                } else {
+                    break;
+                }
                 te = apr_skiplist_peek(mz->timer_ring);
             }
 

Modified: httpd/httpd/trunk/server/mpm/motorz/motorz.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/motorz/motorz.h?rev=1665385&r1=1665384&r2=1665385&view=diff
==============================================================================
--- httpd/httpd/trunk/server/mpm/motorz/motorz.h (original)
+++ httpd/httpd/trunk/server/mpm/motorz/motorz.h Mon Mar  9 23:39:05 2015
@@ -109,9 +109,6 @@
 /**
  * typedefs
  */
-struct motorz_timer_t;
-typedef struct motorz_timer_t motorz_timer_t;
-
 /* data retained by prefork across load/unload of the module
  * allocated on first call to pre-config hook; located on
  * subsequent calls to pre-config hook
@@ -134,7 +131,6 @@ struct motorz_core_t {
     apr_pollset_t *pollset;
     apr_skiplist *timer_ring;
     apr_thread_pool_t *workers;
-    motorz_timer_t *spare_timers;
 };
 
 typedef struct motorz_child_bucket motorz_child_bucket;
@@ -165,6 +161,7 @@ typedef void (*motorz_io_file_cb) (motor
                                    int flags, void *baton);
 
 
+typedef struct motorz_timer_t motorz_timer_t;
 struct motorz_timer_t
 {
     apr_time_t expires;
@@ -172,7 +169,6 @@ struct motorz_timer_t
     void *baton;
     apr_pool_t *pool;
     motorz_core_t *mz;
-    motorz_timer_t *next;
 };
 
 typedef struct motorz_conn_t motorz_conn_t;



Re: svn commit: r1665385 - in /httpd/httpd/trunk/server/mpm/motorz: motorz.c motorz.h

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Mar 10, 2015 at 12:06 PM, Jim Jagielski <ji...@jagunet.com> wrote:
>
>> On Mar 10, 2015, at 5:08 AM, Yann Ylavic <yl...@apache.org> wrote:
>>
>> On Tue, Mar 10, 2015 at 12:39 AM,  <yl...@apache.org> wrote:
>>> Author: ylavic
>>> Date: Mon Mar  9 23:39:05 2015
>>> New Revision: 1665385
>>>
>>> URL: http://svn.apache.org/r1665385
>>> Log:
>>> motorz: revert bogus r1665381.
>>
>> How about using a timer per connection, eg :
>> This also avoids allocating the timers on scon->pool and saves the
>> pool_cleanup_register()/kill() whenever a timer is registered/killed
>> (motorz_conn_pool_cleanup() is now registered once at creation time
>> and will determine itself whether or not it needs to deregister its
>> timer, based on expires [=!]= 0).
>
> Sounds good...

Thanks, done in r1665495.

Re: svn commit: r1665385 - in /httpd/httpd/trunk/server/mpm/motorz: motorz.c motorz.h

Posted by Jim Jagielski <ji...@jaguNET.com>.
> On Mar 10, 2015, at 5:08 AM, Yann Ylavic <yl...@apache.org> wrote:
> 
> On Tue, Mar 10, 2015 at 12:39 AM,  <yl...@apache.org> wrote:
>> Author: ylavic
>> Date: Mon Mar  9 23:39:05 2015
>> New Revision: 1665385
>> 
>> URL: http://svn.apache.org/r1665385
>> Log:
>> motorz: revert bogus r1665381.
> 
> How about using a timer per connection, eg :
> This also avoids allocating the timers on scon->pool and saves the
> pool_cleanup_register()/kill() whenever a timer is registered/killed
> (motorz_conn_pool_cleanup() is now registered once at creation time
> and will determine itself whether or not it needs to deregister its
> timer, based on expires [=!]= 0).

Sounds good... 

Re: svn commit: r1665385 - in /httpd/httpd/trunk/server/mpm/motorz: motorz.c motorz.h

Posted by Yann Ylavic <yl...@apache.org>.
On Tue, Mar 10, 2015 at 12:39 AM,  <yl...@apache.org> wrote:
> Author: ylavic
> Date: Mon Mar  9 23:39:05 2015
> New Revision: 1665385
>
> URL: http://svn.apache.org/r1665385
> Log:
> motorz: revert bogus r1665381.

How about using a timer per connection, eg :

Index: server/mpm/motorz/motorz.c
===================================================================
--- server/mpm/motorz/motorz.c    (revision 1665385)
+++ server/mpm/motorz/motorz.c    (working copy)
@@ -81,15 +81,18 @@ static int indexing_compk(void *ac, void *b)
     return ((*t1 < t2) ? -1 : ((*t1 > t2) ? 1 : 0));
 }

-static apr_status_t motorz_timer_pool_cleanup(void *baton)
+static apr_status_t motorz_conn_pool_cleanup(void *baton)
 {
-    motorz_timer_t *elem = (motorz_timer_t *)baton;
-    motorz_core_t *mz = elem->mz;
+    motorz_conn_t *scon = (motorz_conn_t *)baton;

-    apr_thread_mutex_lock(mz->mtx);
-    apr_skiplist_remove(mz->timer_ring, elem, NULL);
-    apr_thread_mutex_unlock(mz->mtx);
+    if (scon->timer.expires) {
+        motorz_core_t *mz = scon->mz;

+        apr_thread_mutex_lock(mz->mtx);
+        apr_skiplist_remove(mz->timer_ring, &scon->timer, NULL);
+        apr_thread_mutex_unlock(mz->mtx);
+    }
+
     return APR_SUCCESS;
 }

@@ -188,6 +191,9 @@ static apr_status_t motorz_io_accept(motorz_core_t
         scon->sock = socket;
         scon->mz = mz;

+        apr_pool_cleanup_register(scon->pool, scon, motorz_conn_pool_cleanup,
+                                  apr_pool_cleanup_null);
+
         return apr_thread_pool_push(mz->workers,
                                     motorz_io_setup_conn,
                                     scon,
@@ -197,19 +203,26 @@ static apr_status_t motorz_io_accept(motorz_core_t
     return APR_SUCCESS;
 }

-static void motorz_timer_run(motorz_timer_t *ep)
+static void *motorz_timer_invoke(apr_thread_t *thread, void *baton)
 {
-    apr_pool_cleanup_kill(ep->pool, ep, motorz_timer_pool_cleanup);
+    motorz_timer_t *ep = (motorz_timer_t *)baton;
+    motorz_conn_t *scon = (motorz_conn_t *)ep->baton;

+    scon->c->current_thread = thread;
+
     ep->cb(ep->mz, ep->baton);
+
+    return NULL;
 }

-static void *motorz_timer_invoke(apr_thread_t *thread, void *baton)
+static apr_status_t motorz_timer_event_process(motorz_core_t *mz,
motorz_timer_t *te)
 {
-    motorz_timer_t *ep = (motorz_timer_t *)baton;
+    motorz_conn_t *scon = (motorz_conn_t *)te->baton;
+    scon->timer.expires = 0;

-    motorz_timer_run(ep);
-    return NULL;
+    return apr_thread_pool_push(mz->workers,
+                                motorz_timer_invoke,
+                                te, APR_THREAD_TASK_PRIORITY_NORMAL, NULL);
 }

 static void *motorz_io_invoke(apr_thread_t * thread, void *baton)
@@ -255,24 +268,22 @@ static apr_status_t motorz_io_callback(void *baton
     return status;
 }

-static void motorz_register_timer(motorz_core_t *mz,
-                      motorz_timer_cb cb,
-                      void *baton, apr_time_t relative_time,
-                      apr_pool_t *shutdown_pool)
+static void motorz_register_timer(motorz_conn_t *scon,
+                                  motorz_timer_cb cb,
+                                  apr_time_t relative_time)
 {
-    motorz_timer_t *elem = NULL;
+    motorz_timer_t *elem;
     apr_time_t t = apr_time_now() + relative_time;
+    motorz_core_t *mz = scon->mz;

-    apr_thread_mutex_lock(mz->mtx);
-
-    elem = (motorz_timer_t *) apr_pcalloc(shutdown_pool,
sizeof(motorz_timer_t));
-
+    elem = &scon->timer;
     elem->expires = t;
     elem->cb = cb;
-    elem->baton = baton;
-    elem->pool = shutdown_pool;
+    elem->baton = scon;
+    elem->pool = scon->pool;
     elem->mz = mz;
-    apr_pool_cleanup_register(elem->pool, elem,
motorz_timer_pool_cleanup, apr_pool_cleanup_null);
+
+    apr_thread_mutex_lock(mz->mtx);
     apr_skiplist_insert(mz->timer_ring, (void *)elem);
     apr_thread_mutex_unlock(mz->mtx);
 }
@@ -351,13 +362,11 @@ static apr_status_t motorz_io_process(motorz_conn_
                  * event thread poll for writeability.
                  */

-                motorz_register_timer(scon->mz,
+                motorz_register_timer(scon,
                                       motorz_io_timeout_cb,
-                                      scon,
-                                      scon->c->base_server !=
-                                      NULL ? scon->c->base_server->
-                                      timeout : ap_server_conf->timeout,
-                                      scon->pool);
+                                      scon->c->base_server != NULL
+                                      ? scon->c->base_server->timeout
+                                      : ap_server_conf->timeout);

                 scon->pfd.reqevents = (
                                        scon->cs.sense ==
CONN_SENSE_WANT_READ ? APR_POLLIN :
@@ -391,13 +400,11 @@ static apr_status_t motorz_io_process(motorz_conn_
         }

         if (scon->cs.state == CONN_STATE_CHECK_REQUEST_LINE_READABLE) {
-            motorz_register_timer(scon->mz,
+            motorz_register_timer(scon,
                                   motorz_io_timeout_cb,
-                                  scon,
-                                  scon->c->base_server !=
-                                  NULL ? scon->c->base_server->
-                                  timeout : ap_server_conf->timeout,
-                                  scon->pool);
+                                  scon->c->base_server != NULL
+                                  ? scon->c->base_server->keep_alive_timeout
+                                  : ap_server_conf->keep_alive_timeout);

             scon->pfd.reqevents = (
                                    scon->cs.sense ==
CONN_SENSE_WANT_WRITE ? APR_POLLOUT :
@@ -538,6 +545,7 @@ static void clean_child_exit(int code)
     exit(code);
 }

+#if 0 /* unused for now */
 static apr_status_t accept_mutex_on(void)
 {
     motorz_core_t *mz = motorz_core_get();
@@ -580,6 +588,7 @@ static apr_status_t accept_mutex_off(void)
     }
     return APR_SUCCESS;
 }
+#endif

 /* On some architectures it's safe to do unserialized accept()s in the single
  * Listen case.  But it's never safe to do it in the case where there's
@@ -985,16 +994,10 @@ static void child_main(motorz_core_t *mz, int chil
             apr_thread_mutex_lock(mz->mtx);

             /* now iterate any timers and push to worker pool */
-            while (te) {
-                if (te->expires < tnow) {
-                    apr_skiplist_pop(mz->timer_ring, NULL);
-                    apr_thread_pool_push(mz->workers,
-                                         motorz_timer_invoke,
-                                         te,
-
APR_THREAD_TASK_PRIORITY_NORMAL, NULL);
-                } else {
-                    break;
-                }
+            while (te && te->expires < tnow) {
+                apr_skiplist_pop(mz->timer_ring, NULL);
+                motorz_timer_event_process(mz, te);
+
                 te = apr_skiplist_peek(mz->timer_ring);
             }

Index: server/mpm/motorz/motorz.h
===================================================================
--- server/mpm/motorz/motorz.h    (revision 1665385)
+++ server/mpm/motorz/motorz.h    (working copy)
@@ -189,4 +189,6 @@ struct motorz_conn_t
     apr_pollfd_t pfd;
     /** public parts of the connection state */
     conn_state_t cs;
+    /** timer associated with the connection */
+    motorz_timer_t timer;
 };
?

This also avoids allocating the timers on scon->pool and saves the
pool_cleanup_register()/kill() whenever a timer is registered/killed
(motorz_conn_pool_cleanup() is now registered once at creation time
and will determine itself whether or not it needs to deregister its
timer, based on expires [=!]= 0).