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 gr...@apache.org on 2006/04/12 14:03:10 UTC

svn commit: r393442 - in /httpd/mod_python/branches/3.2.x: Doc/appendixc.tex Doc/modpython2.tex configure configure.in src/include/mod_python.h src/include/mod_python.h.in src/mod_python.c test/htdocs/tests.py test/test.py

Author: grahamd
Date: Wed Apr 12 05:03:09 2006
New Revision: 393442

URL: http://svn.apache.org/viewcvs?rev=393442&view=rev
Log:
Backported MODPYTHON-131 and MODPYTHON-145 from trunk to branches/3.2.x.

Modified:
    httpd/mod_python/branches/3.2.x/Doc/appendixc.tex
    httpd/mod_python/branches/3.2.x/Doc/modpython2.tex
    httpd/mod_python/branches/3.2.x/configure
    httpd/mod_python/branches/3.2.x/configure.in
    httpd/mod_python/branches/3.2.x/src/include/mod_python.h
    httpd/mod_python/branches/3.2.x/src/include/mod_python.h.in
    httpd/mod_python/branches/3.2.x/src/mod_python.c
    httpd/mod_python/branches/3.2.x/test/htdocs/tests.py
    httpd/mod_python/branches/3.2.x/test/test.py

Modified: httpd/mod_python/branches/3.2.x/Doc/appendixc.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/Doc/appendixc.tex?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/Doc/appendixc.tex (original)
+++ httpd/mod_python/branches/3.2.x/Doc/appendixc.tex Wed Apr 12 05:03:09 2006
@@ -20,6 +20,15 @@
       of Python options set at global scope within the Apache configuration.
       That is, outside of the context of any VirtualHost, Location, Directory
       or Files directives.
+    \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 run time with
+      \code{PythonOption mod_python.mutex_locks value}.
   \end{itemize}
 
   Improvements

Modified: httpd/mod_python/branches/3.2.x/Doc/modpython2.tex
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/Doc/modpython2.tex?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/Doc/modpython2.tex (original)
+++ httpd/mod_python/branches/3.2.x/Doc/modpython2.tex Wed Apr 12 05:03:09 2006
@@ -101,8 +101,26 @@
   %$ keep emacs happy
 
 \item
+  \index{./configure!\longprogramopt{with-mutex-dir}}
+  %\indexii{./configure}{\longprogramopt{with-mutex-dir}}
+  Sets the directory for the apache mutex locks. The default is
+  \filenq{/tmp}. The directory must exist and be writable by the
+  owner of the apache process.
+
+  Use \longprogramopt{with-mutex-dir} option, e.g:
+
+  \begin{verbatim}
+    $ ./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}.
+
+  \emph{Back ported from 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
@@ -115,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
@@ -224,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
@@ -241,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{Back ported from 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{Back ported from version 3.3.0}
+
+\end{description}
 
 \section{Testing\label{inst-testing}}
 

Modified: httpd/mod_python/branches/3.2.x/configure
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/configure?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/configure (original)
+++ httpd/mod_python/branches/3.2.x/configure Wed Apr 12 05:03:09 2006
@@ -272,7 +272,7 @@
 PACKAGE_BUGREPORT=
 
 ac_unique_file="src/mod_python.c"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT AR INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA SET_MAKE APXS DSO ALL LIBEXECDIR SOLARIS_HACKS HTTPD AP_SRC AP_SRC_OWN AP_SRC_GRP STATIC PYTHON_BIN PY_STD_LIB INCLUDES TEST_SERVER_ROOT MOD_PYTHON_SO MP_VERSION PYTHON_SRC MAX_LOCKS LEX LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT AR INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA SET_MAKE APXS DSO ALL LIBEXECDIR SOLARIS_HACKS HTTPD AP_SRC AP_SRC_OWN AP_SRC_GRP STATIC PYTHON_BIN PY_STD_LIB INCLUDES TEST_SERVER_ROOT MOD_PYTHON_SO MP_VERSION PYTHON_SRC MUTEX_DIR MAX_LOCKS LEX LIBOBJS LTLIBOBJS'
 ac_subst_files=''
 
 # Initialize some variables set by options.
@@ -803,6 +803,7 @@
 --with-apache=DIR 	Path to Apache sources
 --with-python=PATH	Path to specific Python binary
 --with-python-src=DIR	Path to python sources - required if you want to generate the documenation
+--with-mutex-dir=DIR	Mutex directory
 --with-max-locks=INTEGER	Maximum number of locks
 --with-flex=PATH	Path to specific flex binary.
 	Flex Version 2.5.31 or greater is required to regenerate psp_parser.c
@@ -3059,6 +3060,31 @@
   PYTHON_SRC=""
 fi
 
+# configure the MUTEX_DIR for location of mutex locks
+
+echo "$as_me:$LINENO: checking for --with-mutex-dir" >&5
+echo $ECHO_N "checking for --with-mutex-dir... $ECHO_C" >&6
+
+# Check whether --with-mutex-dir or --without-mutex-dir was given.
+if test "${with_mutex_dir+set}" = set; then
+  withval="$with_mutex_dir"
+
+  MUTEX_DIR="$withval"
+  echo "$as_me:$LINENO: result: $MUTEX_DIR" >&5
+echo "${ECHO_T}$MUTEX_DIR" >&6
+
+else
+  echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi;
+
+if test -z "$MUTEX_DIR"; then
+  MUTEX_DIR="/tmp"
+fi
+# TODO - check if MUTEX_DIR is an absolute path
+echo "$as_me:$LINENO: result: Using MUTEX_DIR $MUTEX_DIR" >&5
+echo "${ECHO_T}Using MUTEX_DIR $MUTEX_DIR" >&6
+
 # configure the MAX_LOCKS for number of mutex locks
 
 echo "$as_me:$LINENO: checking for --with-max-locks" >&5
@@ -3858,6 +3884,7 @@
 s,@MOD_PYTHON_SO@,$MOD_PYTHON_SO,;t t
 s,@MP_VERSION@,$MP_VERSION,;t t
 s,@PYTHON_SRC@,$PYTHON_SRC,;t t
+s,@MUTEX_DIR@,$MUTEX_DIR,;t t
 s,@MAX_LOCKS@,$MAX_LOCKS,;t t
 s,@LEX@,$LEX,;t t
 s,@LIBOBJS@,$LIBOBJS,;t t

Modified: httpd/mod_python/branches/3.2.x/configure.in
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/configure.in?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/configure.in (original)
+++ httpd/mod_python/branches/3.2.x/configure.in Wed Apr 12 05:03:09 2006
@@ -303,6 +303,22 @@
   PYTHON_SRC=""
 fi
 
+# configure the MUTEX_DIR for location of mutex locks
+AC_SUBST(MUTEX_DIR)
+AC_MSG_CHECKING(for --with-mutex-dir)
+AC_ARG_WITH(mutex-dir, [--with-mutex-dir=DIR	Mutex directory],
+[
+  MUTEX_DIR="$withval"
+  AC_MSG_RESULT($MUTEX_DIR)
+],
+AC_MSG_RESULT(no))
+
+if test -z "$MUTEX_DIR"; then
+  MUTEX_DIR="/tmp"
+fi
+# TODO - check if MUTEX_DIR is an absolute path 
+AC_MSG_RESULT([Using MUTEX_DIR $MUTEX_DIR])
+
 # configure the MAX_LOCKS for number of mutex locks
 AC_SUBST(MAX_LOCKS)
 AC_MSG_CHECKING(for --with-max-locks)

Modified: httpd/mod_python/branches/3.2.x/src/include/mod_python.h
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/src/include/mod_python.h?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/src/include/mod_python.h (original)
+++ httpd/mod_python/branches/3.2.x/src/include/mod_python.h Wed Apr 12 05:03:09 2006
@@ -106,11 +106,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/branches/3.2.x/src/include/mod_python.h.in
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/src/include/mod_python.h.in?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/src/include/mod_python.h.in (original)
+++ httpd/mod_python/branches/3.2.x/src/include/mod_python.h.in Wed Apr 12 05:03:09 2006
@@ -106,11 +106,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 @MAX_LOCKS@ 
+
+/* MUTEX_DIR can be set as a configure option
+ * ./configure --with-mutex-dir=/path/to/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/branches/3.2.x/src/mod_python.c
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/src/mod_python.c?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/src/mod_python.c (original)
+++ httpd/mod_python/branches/3.2.x/src/mod_python.c Wed Apr 12 05:03:09 2006
@@ -330,8 +330,14 @@
     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);
 
-    /* figre out maximum possible concurrent connections */
+    /* figure out maximum possible concurrent connections */
     /* MAX_DAEMON_USED seems to account for MaxClients, as opposed to
        MAX_DAEMONS, which is ServerLimit
     */
@@ -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, "/tmp/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, "/tmp/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

Modified: httpd/mod_python/branches/3.2.x/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/test/htdocs/tests.py?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/test/htdocs/tests.py (original)
+++ httpd/mod_python/branches/3.2.x/test/htdocs/tests.py Wed Apr 12 05:03:09 2006
@@ -944,6 +944,12 @@
         
 def PythonOption_items(req):
     options = req.get_options().items()
+    
+    # The tests may using PythonOption mod_python.* in the test configuration
+    # We need to remove those particular options so they don't interfer
+    # with this test result.
+    options = [ o for o in options if not o[0].startswith('mod_python') ]
+    
     options.sort()
     req.write(str(options))
     return apache.OK

Modified: httpd/mod_python/branches/3.2.x/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/branches/3.2.x/test/test.py?rev=393442&r1=393441&r2=393442&view=diff
==============================================================================
--- httpd/mod_python/branches/3.2.x/test/test.py (original)
+++ httpd/mod_python/branches/3.2.x/test/test.py Wed Apr 12 05:03:09 2006
@@ -318,6 +318,7 @@
             PidFile("logs/httpd.pid"),
             ServerName("127.0.0.1"),
             Listen(PORT),
+            PythonOption('mod_python.mutex_directory %s' % TMP_DIR),
             PythonOption('PythonOptionTest sample_value'),
             DocumentRoot(DOCUMENT_ROOT),
             LoadModule("python_module %s" % quoteIfSpace(MOD_PYTHON_SO)))
@@ -1439,6 +1440,7 @@
                                   SetHandler("mod_python"),
                                   PythonHandler("tests"),
                                   PythonOption('PythonOptionTest ""'),
+                                  PythonOption('mod_python.mutex_directory ""'),
                                   PythonOption("testing 123"),
                                   PythonDebug("On")))
         return str(c)