You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by jg...@apache.org on 2006/03/11 21:35:32 UTC

svn commit: r385154 - in /httpd/mod_python/trunk: Doc/appendixc.tex Doc/modpython2.tex src/include/mod_python.h src/include/mod_python.h.in src/mod_python.c

Author: jgallacher
Date: Sat Mar 11 12:35:31 2006
New Revision: 385154

URL: http://svn.apache.org/viewcvs?rev=385154&view=rev
Log:
Added support for configuring the mutex directory and number of locks
at apache startup using PythonOption directives. The unit tests still need
to be refactored to take advantage of this new capability.
Ref MODPYTHON-131, MODPYTHON-145

Modified:
    httpd/mod_python/trunk/Doc/appendixc.tex
    httpd/mod_python/trunk/Doc/modpython2.tex
    httpd/mod_python/trunk/src/include/mod_python.h
    httpd/mod_python/trunk/src/include/mod_python.h.in
    httpd/mod_python/trunk/src/mod_python.c

Modified: httpd/mod_python/trunk/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/appendixc.tex?rev=385154&r1=385153&r2=385154&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/appendixc.tex (original)
+++ httpd/mod_python/trunk/Doc/appendixc.tex Sat Mar 11 12:35:31 2006
@@ -40,6 +40,15 @@
     \item
       (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-78]{MODPYTHON-78})
       Added support for Apache 2.2
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-131]{MODPYTHON-131})
+      The directory used for mutex locks can now be specified at 
+      at compile time using \code{./configure --with-mutex-dir value}
+      or at run time with \code{PythonOption mod_python.mutex_directory value}.
+    \item
+      (\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-145]{MODPYTHON-145})
+      The number of mutex locks can now be specified at at run time with
+      \code{PythonOption mod_python.mutex_directory /some/directory}.
   \end{itemize}
 
   Improvements

Modified: httpd/mod_python/trunk/Doc/modpython2.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/Doc/modpython2.tex?rev=385154&r1=385153&r2=385154&view=diff
==============================================================================
--- httpd/mod_python/trunk/Doc/modpython2.tex (original)
+++ httpd/mod_python/trunk/Doc/modpython2.tex Sat Mar 11 12:35:31 2006
@@ -113,11 +113,14 @@
     $ ./configure --with-mutex-dir=/var/run/mod_python
   \end{verbatim}                      
 
+  The mutex directory can also be specified in using a 
+  \citetitle[dir-other-po.html]{PythonOption} directive. 
+  See \citetitle[inst-apacheconfig.html]{Configuring Apache}.
+
   New in version 3.3.0
 
 \item
   \index{./configure!\longprogramopt{with-max-locks}}
-  %\indexii{./configure}{\longprogramopt{with-max-locks}}
   Sets the maximum number of locks reserved by mod_python.
 
   The mutexes used for locking are a limited resource on some
@@ -130,6 +133,10 @@
     $ ./configure --with-max-locks=32
   \end{verbatim}                      
 
+  The number of locks can also be specified in using a 
+  \citetitle[dir-other-po.html]{PythonOption} directive. 
+  See \citetitle[inst-apacheconfig.html]{Configuring Apache}.
+
   New in version 3.2.0
 
 \item
@@ -239,9 +246,10 @@
 
 \subsection{Configuring Apache\label{inst-apacheconfig}}
 
-\begin{itemize}
+\begin{description}
+
+\item \strong{LoadModule} \indexii{LoadModule}{apache configuration}
 
-\item
   If you compiled mod_python as a DSO, you will need to tell Apache to
   load the module by adding the following line in the Apache
   configuration file, usually called \filenq{httpd.conf} or
@@ -256,7 +264,62 @@
   should report at the very end exactly where \program{mod_python.so}
   was placed and how the \code{LoadModule} directive should appear.
 
-\end{itemize}
+\item \strong{Mutex Directory} \indexii{mutex directory}{apache configuration}
+
+  The default directory for mutex lock files is \filenq{/tmp}. The
+  default value can be be specified at compile time using
+  \citetitle[inst-configure.html]{./configure ----with-mutex-dir}.
+
+  Alternatively this value can be overriden at apache startup using 
+  a \citetitle[dir-other-po.html]{PythonOption}.
+
+  \begin{verbatim}
+    PythonOption mod_python.mutex_directory "/tmp"
+  \end{verbatim}
+
+  This may only be used in the server configuration context.
+  It will be ignored if used in a directory, virtual host,
+  htaccess or location context. The most logical place for this 
+  directive in your apache configuration file is immediately
+  following the \strong{LoadModule} directive.
+
+ \emph{New in version 3.3.0}
+
+\item \strong{Mutex Locks} \indexii{apache configuration}{mutex locks}
+  
+  Mutexes are used in mod_python for session locking. The default
+  value is 8.
+
+  On some systems the locking mechanism chosen uses valuable
+  system resources. Notably on RH 8 sysv ipc is used, which 
+  by default provides only 128 semaphores system-wide.
+  On many other systems flock is used which may result in a relatively
+  large number of open files.
+
+  The optimal number of necessary locks is not clear. 
+  Increasing the maximum number of locks may increase performance
+  when using session locking.  A reasonable number for 
+  higher performance might be 32.
+
+  The maximum number of locks can be specified at compile time
+  using \citetitle[inst-configure.html]{./configure ----with-max-locks}.
+
+  Alternatively this value can be overriden at apache startup using 
+  a \citetitle[dir-other-po.html]{PythonOption}.
+
+  \begin{verbatim}
+    PythonOption mod_python.mutex_locks 8 
+  \end{verbatim}
+
+  This may only be used in the server configuration context.
+  It will be ignored if used in a directory, virtual host,
+  htaccess or location context. The most logical place for this 
+  directive in your apache configuration file is immediately
+  following the \strong{LoadModule} directive.
+
+  \emph{New in version 3.3.0}
+
+\end{description}
 
 \section{Testing\label{inst-testing}}
 

Modified: httpd/mod_python/trunk/src/include/mod_python.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mod_python.h?rev=385154&r1=385153&r2=385154&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h Sat Mar 11 12:35:31 2006
@@ -107,11 +107,15 @@
 #define SILENT 1
 #define NOTSILENT 0
 
-/* hopefully this will go away */
 /* MAX_LOCKS can now be set as a configure option
  * ./configure --with-max-locks=INTEGER
  */
 #define MAX_LOCKS 8 
+
+/* MUTEX_DIR can be set as a configure option
+ * ./configure --with-mutex-dir=/path/to/dir
+ */
+#define MUTEX_DIR "/tmp" 
 
 /* python 2.3 no longer defines LONG_LONG, it defines PY_LONG_LONG */
 #ifndef LONG_LONG

Modified: httpd/mod_python/trunk/src/include/mod_python.h.in
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/include/mod_python.h.in?rev=385154&r1=385153&r2=385154&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/include/mod_python.h.in (original)
+++ httpd/mod_python/trunk/src/include/mod_python.h.in Sat Mar 11 12:35:31 2006
@@ -115,7 +115,7 @@
 /* MUTEX_DIR can be set as a configure option
  * ./configure --with-mutex-dir=/path/to/dir
  */
-#define MUTEX_DIR @MUTEX_DIR@ 
+#define MUTEX_DIR "@MUTEX_DIR@" 
 
 /* python 2.3 no longer defines LONG_LONG, it defines PY_LONG_LONG */
 #ifndef LONG_LONG

Modified: httpd/mod_python/trunk/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/src/mod_python.c?rev=385154&r1=385153&r2=385154&view=diff
==============================================================================
--- httpd/mod_python/trunk/src/mod_python.c (original)
+++ httpd/mod_python/trunk/src/mod_python.c Sat Mar 11 12:35:31 2006
@@ -330,6 +330,12 @@
     int max_clients;
     int locks;
     int n;
+    char *val;
+    char *mutex_dir;
+    py_config *conf;
+    
+    conf = (py_config *) ap_get_module_config(s->module_config, 
+                                           &python_module);
 
     /* figure out maximum possible concurrent connections */
     /* MAX_DAEMON_USED seems to account for MaxClients, as opposed to
@@ -352,19 +358,31 @@
     max_clients = (((max_threads <= 0) ? 1 : max_threads) *
                    ((max_procs <= 0) ? 1 : max_procs));
 
-    /* XXX On some systems the locking mechanism chosen uses valuable
+    /* On some systems the locking mechanism chosen uses valuable
        system resources, notably on RH 8 it will use sysv ipc for
        which Linux by default provides only 128 semaphores
        system-wide, and on many other systems flock is used, which
-       results in a relatively large number of open files. So for now
-       we get by with MAX_LOCKS constant for lack of a better
-       solution.
+       results in a relatively large number of open files.
+
+       The maximum number of locks can be specified at
+       compile time using "./configure --with-max-locks value" or
+       at run time with "PythonOption mod_python.mutex_locks value".
+
+       If the PythonOption directive is used, it must be in a 
+       server config context, otherwise it will be ignored.
 
        The optimal number of necessary locks is not clear, perhaps a
        small number is more than sufficient - if someone took the
        time to run some research on this, that'd be most welcome!
     */
-    locks = (max_clients > MAX_LOCKS) ? MAX_LOCKS : max_clients; 
+    val = apr_table_get(conf->options, "mod_python.mutex_locks");
+    if (val) {
+        locks = atoi(val);
+    } else {
+        locks = MAX_LOCKS;
+    }
+
+    locks = (max_clients > locks) ? locks : max_clients; 
 
     ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
                  "mod_python: Creating %d session mutexes based "
@@ -376,14 +394,35 @@
     glb->nlocks = locks;
     glb->parent_pid = getpid();
 
+#if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
+    /* On some sytems a directory for the mutex lock files is required.
+       This mutex directory can be specifed at compile time using
+       "./configure --with-mutex-dir value" or at run time with
+       "PythonOption mod_python.mutex_directory value".
+     
+       If the PythonOption directive is used, it must be in a 
+       server config context, otherwise it will be ignored.
+
+       XXX Should we check if mutex_dir exists and has the correct
+       permissions?
+    */
+    mutex_dir = apr_table_get(conf->options, "mod_python.mutex_directory");
+    if (!mutex_dir)
+        mutex_dir = MUTEX_DIR;
+    
+    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+                 "mod_python: using mutex_directory %s ",
+                 mutex_dir);
+#endif
+
     for (n=0; n<locks; n++) {
         apr_status_t rc;
         apr_global_mutex_t **mutex = glb->g_locks;
 
 #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
         char fname[255];
-
-        snprintf(fname, 255, "MUTEX_DIR/mpmtx%d%d", glb->parent_pid, n);
+        /* XXX What happens if len(mutex_dir) > 255 - len(mpmtx%d%d)? */   
+        snprintf(fname, 255, "%s/mpmtx%d%d", mutex_dir, glb->parent_pid, n);
 #else
         char *fname = NULL;
 #endif
@@ -394,7 +433,7 @@
                          "mod_python: Failed to create global mutex %d of %d (%s).",
                          n, locks, (!fname) ? "<null>" : fname);
             if (n > 1) {
-                /* we were able to crate at least two, so lets just print a 
+                /* we were able to create at least two, so lets just print a 
                    warning/hint and proceed
                 */
                 ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
@@ -440,13 +479,27 @@
 {
     int n;
 
+#if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
+    /* Determine the directory to use for mutex lock files. 
+       See init_mutexes function for more details.
+    */
+    char *mutex_dir;
+    py_config *conf;
+
+    conf = (py_config *) ap_get_module_config(s->module_config, 
+                                           &python_module);
+    mutex_dir = apr_table_get(conf->options, "mod_python.mutex_directory");
+    if (!mutex_dir)
+        mutex_dir = MUTEX_DIR;
+#endif
+
     for (n=0; n< glb->nlocks; n++) {
         apr_status_t rc;
         apr_global_mutex_t **mutex = glb->g_locks;
 
 #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
         char fname[255];
-        snprintf(fname, 255, "MUTEX_DIR/mpmtx%d%d", glb->parent_pid, n);
+        snprintf(fname, 255, "%s/mpmtx%d%d", mutex_dir, glb->parent_pid, n);
 #else
         char *fname = NULL;
 #endif