You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jon Travis <jt...@covalent.net> on 2000/12/01 23:29:22 UTC

MPM query interface

The following patch is an interface which modules can use to query specifics
about the MPM, such as whether or not it does forking, threading, max
daemons, etc.  It currently uses an int pointer for the result.  I think this
should probably be void *, but I can't come up with any good examples of 
queries right now that would return that type information.  It also gets
rid of the get_max_daemons() call.  I didn't convert MPMs for platforms I
can't build on.

For those talking in the backroom one of the days @ ApacheCon, this is from
that meeting.

Commit or trash at your leisure.

-- Jon


Index: src/include/ap_mpm.h
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/include/ap_mpm.h,v
retrieving revision 1.20
diff -u -r1.20 ap_mpm.h
--- src/include/ap_mpm.h	2000/11/26 04:47:27	1.20
+++ src/include/ap_mpm.h	2000/12/01 22:12:53
@@ -164,4 +164,18 @@
     apr_pool_t *p);
 
 
+#define AP_MPMQ_MAX_DAEMONS 1    /* Max # of daemons     */
+#define AP_MPMQ_IS_THREADED 2    /* MPM can do threading */
+#define AP_MPMQ_IS_FORKED   3    /* MPM can do forking   */
+
+/**
+ * Query a property of the current MPM.  
+ * @param query_code One of APM_MPMQ_*
+ * @param result A location to place the result of the query
+ * @return APR_SUCCESS or APR_ENOTIMPL
+ * @deffunc int ap_mpm_query(int query_code, int *result)
+ */
+
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
+
 #endif
Index: src/main/mpm_common.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/main/mpm_common.c,v
retrieving revision 1.35
diff -u -r1.35 mpm_common.c
--- src/main/mpm_common.c	2000/11/26 04:47:30	1.35
+++ src/main/mpm_common.c	2000/12/01 22:14:03
@@ -76,6 +76,7 @@
 #include "http_log.h"
 #include "mpm.h"
 #include "mpm_common.h"
+#include "ap_mpm.h"
 
 #ifdef MPM_NEEDS_RECLAIM_CHILD_PROCESSES
 void ap_reclaim_child_processes(int terminate)
@@ -85,8 +86,9 @@
     apr_status_t waitret;
     int tries;
     int not_dead_yet;
-    int max_daemons = ap_get_max_daemons();
+    int max_daemons;
 
+    ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons);
     MPM_SYNC_CHILD_TABLE();
 
     for (tries = terminate ? 4 : 1; tries <= 9; ++tries) {
Index: src/modules/mpm/dexter/dexter.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/modules/mpm/dexter/dexter.c,v
retrieving revision 1.130
diff -u -r1.130 dexter.c
--- src/modules/mpm/dexter/dexter.c	2000/11/10 19:01:31	1.130
+++ src/modules/mpm/dexter/dexter.c	2000/12/01 22:14:13
@@ -173,9 +173,20 @@
 static const char *lock_fname;
 static pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 /* a clean exit from a child with proper cleanup */
Index: src/modules/mpm/mpmt_pthread/mpmt_pthread.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v
retrieving revision 1.125
diff -u -r1.125 mpmt_pthread.c
--- src/modules/mpm/mpmt_pthread/mpmt_pthread.c	2000/11/10 19:01:31	1.125
+++ src/modules/mpm/mpmt_pthread/mpmt_pthread.c	2000/12/01 22:14:17
@@ -168,9 +168,20 @@
 #define SAFE_ACCEPT(stmt) (stmt)
 #endif
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 /* a clean exit from a child with proper cleanup */ 
Index: src/modules/mpm/mpmt_pthread/scoreboard.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/modules/mpm/mpmt_pthread/scoreboard.c,v
retrieving revision 1.42
diff -u -r1.42 scoreboard.c
--- src/modules/mpm/mpmt_pthread/scoreboard.c	2000/11/10 21:51:09	1.42
+++ src/modules/mpm/mpmt_pthread/scoreboard.c	2000/12/01 22:14:17
@@ -69,6 +69,7 @@
 #include "mpm_status.h"
 #include "mpm.h"
 #include "scoreboard.h"
+#include "ap_mpm.h"
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
@@ -204,8 +205,10 @@
 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
 {
     int i;
-    int max_daemons_limit = ap_get_max_daemons();
+    int max_daemons_limit;
 
+    ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
+
     for (i = 0; i < max_daemons_limit; ++i)
 	if (ap_scoreboard_image->parent[i].pid == pid->pid)
 	    return i;
@@ -326,8 +329,9 @@
     int i;
     apr_array_header_t *connection_list;
     long *array_slot;
-    int max_daemons_limit = ap_get_max_daemons();
+    int max_daemons_limit;
 
+    ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
     connection_list = apr_make_array(p, 0, sizeof(long));
     /* We assume that there is a connection iff it has an entry in the status
      * table. Connections without any status sound problematic to me, so this
@@ -396,9 +400,10 @@
     int i, j;
     apr_array_header_t *server_status;
     ap_status_table_row_t *array_slot;
-    int max_daemons_limit = ap_get_max_daemons();
+    int max_daemons_limit;
     status_table_entry *ss;
 
+    ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit);
     server_status = apr_make_array(p, 0, sizeof(ap_status_table_row_t));
 
     /* Go ahead and return what's in the connection status table even if we
Index: src/modules/mpm/perchild/perchild.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/modules/mpm/perchild/perchild.c,v
retrieving revision 1.25
diff -u -r1.25 perchild.c
--- src/modules/mpm/perchild/perchild.c	2000/11/10 19:01:32	1.25
+++ src/modules/mpm/perchild/perchild.c	2000/12/01 22:14:18
@@ -208,9 +208,20 @@
 static const char *lock_fname;
 static pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 1;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 /* a clean exit from a child with proper cleanup */
Index: src/modules/mpm/prefork/prefork.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/modules/mpm/prefork/prefork.c,v
retrieving revision 1.137
diff -u -r1.137 prefork.c
--- src/modules/mpm/prefork/prefork.c	2000/12/01 17:41:26	1.137
+++ src/modules/mpm/prefork/prefork.c	2000/12/01 22:14:19
@@ -399,9 +399,20 @@
     return (ap_scoreboard_image ? 1 : 0);
 }
 
-AP_DECLARE(int) ap_get_max_daemons(void)
+AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result)
 {
-    return ap_max_daemons_limit;
+    switch(query_code){
+        case AP_MPMQ_MAX_DAEMONS:
+            *result = ap_max_daemons_limit;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_THREADED:
+            *result = 0;
+            return APR_SUCCESS;
+        case AP_MPMQ_IS_FORKED:
+            *result = 1;
+            return APR_SUCCESS;
+    }
+    return APR_ENOTIMPL;
 }
 
 static apr_inline void put_scoreboard_info(int child_num,
Index: src/include/httpd.h
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/include/httpd.h,v
retrieving revision 1.120
diff -u -r1.120 httpd.h
--- src/include/httpd.h	2000/11/29 17:32:44	1.120
+++ src/include/httpd.h	2000/12/01 22:26:43
@@ -1543,12 +1543,6 @@
  * @deffunc void ap_chdir_file(const char *file)
  */
 AP_DECLARE(void) ap_chdir_file(const char *file);
-/**
- * Get the maximum number of daemons processes for this version of Apache
- * @return The maximum number of daemon processes
- * @deffunc int ap_get_max_daemons(void)
- */
-AP_DECLARE(int) ap_get_max_daemons(void);
 
 #ifdef _OSD_POSIX
 extern const char *os_set_account(apr_pool_t *p, const char *account);

RE: MPM query interface

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
> From: Jon Travis [mailto:jtravis@covalent.net]
> Sent: Friday, December 01, 2000 4:29 PM
> 
> The following patch is an interface which modules can use to query 
> specifics about the MPM, such as whether or not it does forking, 
> threading, max daemons, etc.  It currently uses an int pointer for 
> the result.  I think this should probably be void *, but I can't 
> come up with any good examples of queries right now that would return 
> that type information.  It also gets rid of the get_max_daemons() call.
> I didn't convert MPMs for platforms I can't build on.

+1 on concept here ... I'd be happy to follow for Win32.

> For those talking in the backroom one of the days @ 
> ApacheCon, this is from that meeting.

Glad someone remembered :-)