You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2016/11/30 23:23:32 UTC

svn commit: r1772133 - in /tcl/rivet/trunk: ChangeLog doc/xml/internals.xml doc/xml/lazybridge.xml rivet/init.tcl src/mod_rivet_ng/rivetCore.c src/mod_rivet_ng/rivet_lazy_mpm.c src/mod_rivet_ng/worker_prefork_common.c

Author: mxmanghi
Date: Wed Nov 30 23:23:31 2016
New Revision: 1772133

URL: http://svn.apache.org/viewvc?rev=1772133&view=rev
Log:
    * src/mod_rivet_ng/rivet_lazy_mpm.c:
    * src/mod_rivet_ng/worker_prefork_mpm.c: setting
    the running_conf pointer in the thread private
    data enables ::rivet::inspect to return 
    meaningful data even outside of request processing (in
    the forms that make sense)
    * src/mod_rivet_ng/rivetCore.c: more accurate
    determination of the rivet_server_rec makes
    possible to determine the pointer also
    outside a request processing


Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/doc/xml/internals.xml
    tcl/rivet/trunk/doc/xml/lazybridge.xml
    tcl/rivet/trunk/rivet/init.tcl
    tcl/rivet/trunk/src/mod_rivet_ng/rivetCore.c
    tcl/rivet/trunk/src/mod_rivet_ng/rivet_lazy_mpm.c
    tcl/rivet/trunk/src/mod_rivet_ng/worker_prefork_common.c

Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Wed Nov 30 23:23:31 2016
@@ -1,3 +1,15 @@
+2016-11-30 Massimo Manghi <mx...@apache.org>
+    * src/mod_rivet_ng/rivet_lazy_mpm.c:
+    * src/mod_rivet_ng/worker_prefork_mpm.c: setting
+    the running_conf pointer in the thread private
+    data enables ::rivet::inspect to return 
+    meaningful data even outside of request processing (in
+    the forms that make sense)
+    * src/mod_rivet_ng/rivetCore.c: more accurate
+    determination of the rivet_server_rec makes
+    possible to determine the pointer also
+    outside a request processing
+
 2016-11-28 Massimo Manghi <mx...@apache.org>
     * src/mod_rivet_ng/: new configuration directives
     RequestHandler (request handling procedure), ImportRivetNS

Modified: tcl/rivet/trunk/doc/xml/internals.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/internals.xml?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/internals.xml (original)
+++ tcl/rivet/trunk/doc/xml/internals.xml Wed Nov 30 23:23:31 2016
@@ -46,13 +46,14 @@
     		<listitem>rivet_worker_mpm.c: a threaded bridge creating a pool of threads
     		each running Tcl interpreters and communicating with the worker MPM threads
     		through a thread safe queue. This bridge is needed by the worker MPM.</listitem>
+    		<listitem>rivet_lazy_mpm.c: a threaded bridge where Tcl threads are
+    		started <quote>on demand</quote>. The bridge creates no threads and Tcl interpreters
+    		at start up and only when requests come in Tcl execution threads are created.
+    		This bridge is explained in detail in the <xref linkend="lazybridge">next section</xref>.     		
+    		Since the resource demand at startup is minimal this bridge should work well for 
+    		development machines that go through frequent web server restarts or desktop machines
+    		in use also for other tasks.</listitem>
     	</itemizedlist>
-    	<para>
-    		A third bridge for threaded MPMs (rivet_lazy_mpm.c) is under development and it aims at
-    		a more conservative resource consumption that suits well the need of web sites having
-    		low to middle workload and many virtual hosts having a roughly uniform workload distribution.
-    		This bridge should work well also for development web servers.
-    	</para>
     </section>
     <section>
     	<title>mod_rivet MPM Bridge callbacks</title> 
@@ -66,7 +67,11 @@
     		statements that implied useless complexity, error prone programming and performance costs. 
     		New bridges could be imagined also to implement different models of workload
     		distribution and resource management (like the resources demanded by the Tcl interpreters). 
-			We designed mod_rivet in order to call functions defined in the rivet_bridge_table structure    		
+			We designed an interface between the core of mod_rivet and its MPM bridges 
+			based on a set of functions defined in the rivet_bridge_table structure. 
+			Many of these functions need not to be defined if the bridge model
+			they implement does not require it. Two of them (mpm_request, mpm_thread_interp)
+			must be implemented and defined 		
     	</para>
     	<programlisting>typedef struct _mpm_bridge_table {
     RivetBridge_ServerInit    *mpm_server_init;
@@ -97,7 +102,13 @@
 					purpose of a content generator module (like mod_rivet) is to respond
 					to requests creating content, thus whatever it is
 					a content generating function must exist (during the early stages of
-					development you can create a simple test function for that)
+					development you can create a simple test function for that). In a
+					threaded MPM this function typically prepares the request processing 
+					stuffing somewhere the pointer to the request_rec structure 
+					passed by the web server and then it calls some method to communicate
+					these data to the Tcl execution thread waiting for result to be
+					returned. The <quote>prefork</quote> is an exception since there
+					are no multiple threads and the bridge calls directly Rivet_SendContent
 				</listitem>
 				<listitem>
 					<emphasis>mpm_finalize</emphasis>: pointer to a finalization
@@ -108,7 +119,8 @@
 					in the <emphasis>worker</emphasis> MPM bridge notifies
 					a supervisor thread demanding the whole pool of threads running Tcl 
 					interpreters to orderly exit. This pointer can be NULL if the bridge 
-					has no special need when a child process must exit.
+					has no special need when a child process must exit (unlikely if you have
+					multiple threads running)
 				</listitem>
 				<listitem>
 					<emphasis>mpm_exit_handler</emphasis>: mod_rivet replaces
@@ -153,10 +165,10 @@
       <para>
 			The <structname>RivetChan</structname> system was created in
 			order to have an actual Tcl channel that we could redirect
-			standard output to.  This lets us use, for instance, the
+			standard output to.  This enables us use, for instance, the
 			regular <command>puts</command> command in .rvt pages.  It
 			works by creating a channel that buffers output, and, at
-			predetermined times, passes it on to Apache's IO system.
+			predetermined times, passes it on to Apache's I/O system.
 			Tcl's regular standard output is replaced with an instance of
 			this channel type, so that, by default, output will go to the
 			web page. 

Modified: tcl/rivet/trunk/doc/xml/lazybridge.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/lazybridge.xml?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/lazybridge.xml (original)
+++ tcl/rivet/trunk/doc/xml/lazybridge.xml Wed Nov 30 23:23:31 2016
@@ -1,17 +1,31 @@
 <section id="lazybridge">
     <title>Example: the <quote>Lazy</quote> bridge</title>
 	<section>
-	<title>The rationale of threaded bridges</title>
-    <para>
-    	
-    	The 'bridge' concept was introduced to cope with the ability of 
-    	the Apache HTTP web server to adopt different multiprocessing 
-    	models loading one of the available MPMs (Multi Processing Modules). 
-		A bridge primary task is to adapt mod_rivet internal calls so that it fits
-		the running multiprocessing model, but separating mod_rivet core 
-		function from the MPM machinery worked also a solution for
-		a flexible and extensible approach to workload and resource management. 
-   </para>
+		<title>The rationale of threaded bridges</title>
+    	<para>    	
+	    	The 'bridge' concept was introduced to cope with the ability of 
+	    	the Apache HTTP web server to adopt different multiprocessing 
+	    	models by loading one of the available MPMs (Multi Processing Modules). 
+			A bridge's task is to let mod_rivet fit the selected multiprocessing
+			model in the first place. Still separating mod_rivet core
+			functions from the MPM machinery provided also a solution for
+			implementing a flexible and extensible design that enables 
+			a programmer to develop alternative approaches to workload and 
+			resource management. 
+   	</para>
+   	<para>
+   		The Apache HTTP web server demands its module to
+   		run with any MPM irrespective of its internal architecture and its
+   		a general design constrain to make no assumptions about the MPM. 
+   		Unfortunately for Tcl is a relevant fact to be running as only execution
+   		thread within a process (like with the 'prefork' MPM) 
+   		or within one of many execution threads. First of all Tcl is itself 
+   		threaded (unless threads are disabled at compile time) and many
+   		of the basic Tcl data structures (namely Tcl_Obj) cannot be safely 
+   		shared among threads. This demands that Tcl interpreters run 
+   		on separated threads communicating with the HTTP web server 
+   		through suitable methods.
+   	</para>
 	</section>
 	<section>
 	 <title>Lazy bridge data structures</title>

Modified: tcl/rivet/trunk/rivet/init.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/init.tcl?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/rivet/init.tcl (original)
+++ tcl/rivet/trunk/rivet/init.tcl Wed Nov 30 23:23:31 2016
@@ -82,7 +82,7 @@ proc ::Rivet::init {} {
     if {[::rivet::inspect ImportRivetNS] == 1} {
         uplevel #0 { namespace import ::rivet::* }
     }
-    unset -nocomplain ::module_conf
+    #unset -nocomplain ::module_conf
 }
 
 ###

Modified: tcl/rivet/trunk/src/mod_rivet_ng/rivetCore.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet_ng/rivetCore.c?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet_ng/rivetCore.c (original)
+++ tcl/rivet/trunk/src/mod_rivet_ng/rivetCore.c Wed Nov 30 23:23:31 2016
@@ -1607,7 +1607,7 @@ TCL_CMD_HEADER( Rivet_InspectCmd )
             {
                 rsc = RIVET_SERVER_CONF(module_globals->server->module_config);
             } else if (private->r == NULL) {
-                rsc = RIVET_SERVER_CONF(module_globals->server->module_config);
+                rsc = private->running_conf;
             } else {
                 rsc = Rivet_GetConf(private->r); 
             }

Modified: tcl/rivet/trunk/src/mod_rivet_ng/rivet_lazy_mpm.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet_ng/rivet_lazy_mpm.c?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet_ng/rivet_lazy_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet_ng/rivet_lazy_mpm.c Wed Nov 30 23:23:31 2016
@@ -64,7 +64,7 @@ typedef struct lazy_tcl_worker {
     rivet_server_conf*  conf;               /* rivet_server_conf* record            */
 } lazy_tcl_worker;
 
-/* virtual host descriptor */
+/* virtual host thread queue descriptor */
 
 typedef struct vhost_iface {
     int                 idle_threads_cnt;   /* idle threads for the virtual hosts       */
@@ -148,6 +148,12 @@ static void* APR_THREAD_FUNC request_pro
 
     private = Rivet_ExecutionThreadInit();
 
+    /* at thread initialization the running conf is determined by the context
+     * of exectution. The lazy bridge threads are associated to a single virtual.
+     * host. We let the interpreter inizialization run with its configuration
+     * stored in the running_conf field */ 
+
+    private->running_conf = rsc;
     private->ext = apr_pcalloc(private->pool,sizeof(mpm_bridge_specific));
     private->ext->keep_going = 1;
     private->ext->interp = Rivet_NewVHostInterp(private->pool,w->server);

Modified: tcl/rivet/trunk/src/mod_rivet_ng/worker_prefork_common.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet_ng/worker_prefork_common.c?rev=1772133&r1=1772132&r2=1772133&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet_ng/worker_prefork_common.c (original)
+++ tcl/rivet/trunk/src/mod_rivet_ng/worker_prefork_common.c Wed Nov 30 23:23:31 2016
@@ -179,6 +179,14 @@ rivet_thread_private* Rivet_VirtualHosts
 
         private->ext->interps[myrsc->idx] = rivet_interp;
 
+        /* Let's fetch the virtual host configuration and stuff 
+         * its pointer in the running_conf field of the private data.
+         * Commands running in the initialization context know how to get 
+         * the configuation from it (e.g. ::rivet::inspect)
+         */
+
+        private->running_conf = myrsc;
+
         /* Basic Rivet packages and libraries are loaded here */
 
         if ((rivet_interp->flags & RIVET_INTERP_INITIALIZED) == 0)



---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org