You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by pq...@apache.org on 2012/08/26 11:32:43 UTC

svn commit: r1377398 - in /httpd/mod_fcgid/trunk/modules/fcgid: fcgid_bridge.c fcgid_pm.h fcgid_pm_main.c fcgid_pm_unix.c fcgid_pm_win.c

Author: pqf
Date: Sun Aug 26 09:32:43 2012
New Revision: 1377398

URL: http://svn.apache.org/viewvc?rev=1377398&view=rev
Log:
New protocol to avoid too much sleep, improve performance while stress testing
1. procmgr_send_spawn_cmd() now return a status code from PM, so process handler now know the spawn request is denyed or not.
2. if a new process is created, no sleep is needed.
3. if no process is created, sleep a while

PR: 53693
Submitted by: Ryan Pan <panqingfeng gmail>

Modified:
    httpd/mod_fcgid/trunk/modules/fcgid/fcgid_bridge.c
    httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm.h
    httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_main.c
    httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_unix.c
    httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_win.c

Modified: httpd/mod_fcgid/trunk/modules/fcgid/fcgid_bridge.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/modules/fcgid/fcgid_bridge.c?rev=1377398&r1=1377397&r2=1377398&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/modules/fcgid/fcgid_bridge.c (original)
+++ httpd/mod_fcgid/trunk/modules/fcgid/fcgid_bridge.c Sun Aug 26 09:32:43 2012
@@ -447,19 +447,19 @@ handle_request(request_rec * r, int role
             if (bucket_ctx->procnode)
                 break;
 
-            /* Avoid sleeping the very first time through if there are no
-               busy processes; the problem is just that we haven't spawned
-               anything yet, so waiting is pointless */
-            if (i > 0 || j > 0 || count_busy_processes(r, &fcgi_request)) {
+            /* Send a spawn request if I can't get a process slot */
+            /* procmgr_send_spawn_cmd() return APR_SUCCESS if a process is created */
+            if( procmgr_send_spawn_cmd(&fcgi_request, r)==APR_SUCCESS ) {
+                bucket_ctx->procnode = apply_free_procnode(r, &fcgi_request);
+                if (bucket_ctx->procnode)
+                    break;
+            }
+            else {
                 apr_sleep(apr_time_from_sec(1));
-
                 bucket_ctx->procnode = apply_free_procnode(r, &fcgi_request);
                 if (bucket_ctx->procnode)
                     break;
             }
-
-            /* Send a spawn request if I can't get a process slot */
-            procmgr_send_spawn_cmd(&fcgi_request, r);
         }
 
         /* Connect to the fastcgi server */

Modified: httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm.h
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm.h?rev=1377398&r1=1377397&r2=1377398&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm.h (original)
+++ httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm.h Sun Aug 26 09:32:43 2012
@@ -45,7 +45,10 @@ apr_status_t procmgr_send_spawn_cmd(fcgi
                                     request_rec * r);
 apr_status_t procmgr_fetch_cmd(fcgid_command * command,
                               server_rec * main_server);
-apr_status_t procmgr_finish_notify(server_rec * main_server);
+
+#define PROCMGR_PROC_CREATED 0
+#define PROCMGR_PROC_NOT_CREATED 1
+apr_status_t procmgr_finish_notify(server_rec * main_server, char proc_created);
 
 apr_status_t procmgr_child_init(server_rec * main_server,
                                 apr_pool_t * pchild);

Modified: httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_main.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_main.c?rev=1377398&r1=1377397&r2=1377398&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_main.c (original)
+++ httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_main.c Sun Aug 26 09:32:43 2012
@@ -527,7 +527,7 @@ static void default_proc_env(apr_table_t
 
 /* End of common to util_script.c */
 
-static void
+static apr_status_t
 fastcgi_spawn(fcgid_command * command, server_rec * main_server,
               apr_pool_t * configpool)
 {
@@ -547,7 +547,7 @@ fastcgi_spawn(fcgid_command * command, s
         proctable_pm_unlock(main_server);
         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
                      "mod_fcgid: too much processes, please increase FCGID_MAX_APPLICATION");
-        return;
+        return APR_CHILD_NOTDONE;
     }
     procnode = &proctable_array[free_list_header->next_index];
     free_list_header->next_index = procnode->next_index;
@@ -589,7 +589,7 @@ fastcgi_spawn(fcgid_command * command, s
 
         ap_log_error(APLOG_MARK, APLOG_WARNING, rv, main_server,
                      "mod_fcgid: can't create pool for process");
-        return;
+        return APR_CHILD_NOTDONE;
     }
     /* Set up longer, system defaults before falling into parsing fixed-limit
      * request-by-request variables, so if any are overriden, they preempt
@@ -614,7 +614,7 @@ fastcgi_spawn(fcgid_command * command, s
         apr_pool_destroy(procnode->proc_pool);
         link_node_to_list(main_server, free_list_header,
                           procnode, proctable_array);
-        return;
+        return APR_CHILD_NOTDONE;
     }
     else {
         /* The job done */
@@ -628,6 +628,7 @@ fastcgi_spawn(fcgid_command * command, s
                      procnode->proc_id.pid);
         register_spawn(main_server, procnode);
     }
+    return APR_SUCCESS;
 }
 
 apr_status_t pm_main(server_rec * main_server, apr_pool_t * configpool)
@@ -635,15 +636,17 @@ apr_status_t pm_main(server_rec * main_s
     fcgid_command command;
 
     while (1) {
+        char proc_created = PROCMGR_PROC_NOT_CREATED;
         if (procmgr_must_exit())
             break;
 
         /* Wait for command */
         if (procmgr_fetch_cmd(&command, main_server) == APR_SUCCESS) {
             if (is_spawn_allowed(main_server, &command))
-                fastcgi_spawn(&command, main_server, configpool);
+                if( fastcgi_spawn(&command, main_server, configpool)==APR_SUCCESS )
+                    proc_created = PROCMGR_PROC_CREATED;
 
-            procmgr_finish_notify(main_server);
+            procmgr_finish_notify(main_server, proc_created);
         }
 
         /* Move matched node to error list */

Modified: httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_unix.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_unix.c?rev=1377398&r1=1377397&r2=1377398&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_unix.c (original)
+++ httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_unix.c Sun Aug 26 09:32:43 2012
@@ -460,9 +460,10 @@ void procmgr_init_spawn_cmd(fcgid_comman
 apr_status_t procmgr_send_spawn_cmd(fcgid_command * command,
                                     request_rec * r)
 {
-    apr_status_t rv;
+    apr_status_t rv,result;
     char notifybyte;
     apr_size_t nbytes = sizeof(*command);
+    result = APR_SUCCESS;
 
     /* Get the global mutex before posting the request */
     if ((rv = apr_global_mutex_lock(g_pipelock)) != APR_SUCCESS) {
@@ -477,6 +478,7 @@ apr_status_t procmgr_send_spawn_cmd(fcgi
         /* Just print some error log and fall through */
         ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
                       "mod_fcgid: can't write spawn command");
+        result = rv;
     } else {
         /* Wait the finish notify while send the request successfully */
         nbytes = sizeof(notifybyte);
@@ -485,7 +487,9 @@ apr_status_t procmgr_send_spawn_cmd(fcgi
                            &nbytes)) != APR_SUCCESS) {
             ap_log_rerror(APLOG_MARK, APLOG_WARNING, rv, r,
                           "mod_fcgid: can't get notify from process manager");
-        }
+            result = rv;
+        } else if( nbytes!=PROCMGR_PROC_CREATED )
+            result = APR_CHILD_NOTDONE;
     }
 
     /* Release the lock */
@@ -495,17 +499,16 @@ apr_status_t procmgr_send_spawn_cmd(fcgi
         exit(0);
     }
 
-    return APR_SUCCESS;
+    return result;
 }
 
-apr_status_t procmgr_finish_notify(server_rec * main_server)
+apr_status_t procmgr_finish_notify(server_rec * main_server, char proc_created)
 {
     apr_status_t rv;
-    char notifybyte = 'p';
-    apr_size_t nbytes = sizeof(notifybyte);
+    apr_size_t nbytes = sizeof(proc_created);
 
     if ((rv =
-         apr_file_write(g_pm_write_pipe, &notifybyte,
+         apr_file_write(g_pm_write_pipe, &proc_created,
                         &nbytes)) != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_WARNING, rv, main_server,
                      "mod_fcgid: can't send notify from process manager");

Modified: httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_win.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_win.c?rev=1377398&r1=1377397&r2=1377398&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_win.c (original)
+++ httpd/mod_fcgid/trunk/modules/fcgid/fcgid_pm_win.c Sun Aug 26 09:32:43 2012
@@ -159,6 +159,7 @@ void procmgr_init_spawn_cmd(fcgid_comman
 apr_status_t procmgr_send_spawn_cmd(fcgid_command * command,
                                     request_rec * r)
 {
+     char *notifybyte = NULL;
     if (g_thread && g_msgqueue && !g_must_exit
         && g_reqlock && g_notifyqueue) {
         apr_status_t rv;
@@ -189,8 +190,6 @@ apr_status_t procmgr_send_spawn_cmd(fcgi
             return rv;
         } else {
             /* Wait the respond from process manager */
-            char *notifybyte = NULL;
-
             if ((rv =
                  apr_queue_pop(g_notifyqueue,
                                (void **)&notifybyte)) != APR_SUCCESS) {
@@ -210,13 +209,22 @@ apr_status_t procmgr_send_spawn_cmd(fcgi
         }
     }
 
-    return APR_SUCCESS;
+    if( notifybyte && *notifybyte==PROCMGR_PROC_CREATED )
+        return APR_SUCCESS;
+    else
+        return APR_CHILD_NOTDONE;
 }
 
-apr_status_t procmgr_finish_notify(server_rec * main_server)
+static char g_proc_created = PROCMGR_PROC_CREATED;
+static char g_proc_not_created = PROCMGR_PROC_NOT_CREATED;
+apr_status_t procmgr_finish_notify(server_rec * main_server, char proc_created)
 {
     apr_status_t rv;
     char *notify = NULL;
+    if( proc_created==PROCMGR_PROC_CREATED )
+        notify = &g_proc_created;
+    else
+        notify = &g_proc_not_created;
 
     if ((rv = apr_queue_push(g_notifyqueue, notify)) != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,