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 2014/08/13 02:08:24 UTC
svn commit: r1617629 - in /tcl/rivet/trunk: Makefile.in
src/experimental/mod_rivet.c src/experimental/mod_rivet.h
src/experimental/rivet_prefork_mpm.c src/experimental/rivet_worker_mpm.c
Author: mxmanghi
Date: Wed Aug 13 00:08:24 2014
New Revision: 1617629
URL: http://svn.apache.org/r1617629
Log:
improved tasks distribution among modules in src/experimental
Modified:
tcl/rivet/trunk/Makefile.in
tcl/rivet/trunk/src/experimental/mod_rivet.c
tcl/rivet/trunk/src/experimental/mod_rivet.h
tcl/rivet/trunk/src/experimental/rivet_prefork_mpm.c
tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c
Modified: tcl/rivet/trunk/Makefile.in
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/Makefile.in?rev=1617629&r1=1617628&r2=1617629&view=diff
==============================================================================
--- tcl/rivet/trunk/Makefile.in (original)
+++ tcl/rivet/trunk/Makefile.in Wed Aug 13 00:08:24 2014
@@ -17,7 +17,7 @@
#
# top-level Makefile.am for Apache Rivet: gets turned into a Makefile.in by automake
#
-# $Id: Makefile.am 1616967 2014-08-09 15:29:07Z mxmanghi $
+# $Id: Makefile.am 1517859 2013-08-27 16:08:31Z mxmanghi $
#
# 2007/12/25: Added target uninistall-local that removes the tcl stuff (mxmanghi)
# 2010/06/22: target instal-data-local searches for pkgIndex.tcl files and deletes them
Modified: tcl/rivet/trunk/src/experimental/mod_rivet.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/mod_rivet.c?rev=1617629&r1=1617628&r2=1617629&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/experimental/mod_rivet.c Wed Aug 13 00:08:24 2014
@@ -140,9 +140,9 @@ Rivet_SendContent(rivet_thread_private *
r->allowed |= (1 << M_POST);
r->allowed |= (1 << M_PUT);
r->allowed |= (1 << M_DELETE);
- if (r->method_number != M_GET &&
- r->method_number != M_POST &&
- r->method_number != M_PUT &&
+ if (r->method_number != M_GET &&
+ r->method_number != M_POST &&
+ r->method_number != M_PUT &&
r->method_number != M_DELETE) {
retval = DECLINED;
@@ -194,6 +194,7 @@ Rivet_SendContent(rivet_thread_private *
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server,
MODNAME ": Could not create request namespace (%s)\n" ,
Tcl_GetStringResult(interp));
+
retval = HTTP_INTERNAL_SERVER_ERROR;
goto sendcleanup;
}
@@ -587,11 +588,15 @@ Rivet_ParseExecFile(rivet_thread_private
if (rivet_interp->cache_free) {
rivet_interp->objCacheList[--rivet_interp->cache_free] =
- (char*) malloc ((strlen(hashKey)+1) * sizeof(char));
+ (char*) apr_pcalloc (rivet_interp->pool,(strlen(hashKey)+1)*sizeof(char));
strcpy(rivet_interp->objCacheList[rivet_interp->cache_free], hashKey);
} else if (rivet_interp->cache_size) { /* If it's zero, we just skip this. */
+/*
+ instead of removing the last entry in the cache (for what purpose after all??)
+ we signal the cache full condition
+
Tcl_HashEntry *delEntry;
delEntry = Tcl_FindHashEntry(
rivet_interp->objCache,
@@ -604,7 +609,14 @@ Rivet_ParseExecFile(rivet_thread_private
rivet_interp->objCacheList[0] = (char*) malloc ((strlen(hashKey)+1) * sizeof(char));
strcpy (rivet_interp->objCacheList[0], hashKey);
+*/
+ if ((rivet_interp->flags & RIVET_CACHE_FULL) == 0)
+ {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_EGENERAL, private->r->server,
+ MODNAME ": Cache full");
+ rivet_interp->flags |= RIVET_CACHE_FULL;
+ }
}
} else {
/* We found a compiled version of this page. */
@@ -911,21 +923,20 @@ Rivet_ServerInit (apr_pool_t *pPool, apr
module_globals->threads_count = (apr_uint32_t *) apr_palloc(pPool,sizeof(apr_uint32_t));
apr_atomic_set32(module_globals->threads_count,0);
- module_globals->server_shutdown = 0;
-
- apr_threadkey_private_create (&rivet_thread_key,NULL, pPool);
-
module_globals->rivet_panic_pool = pPool;
module_globals->rivet_panic_server_rec = s;
- //module_globals->server = s;
module_globals->rivet_panic_request_rec = NULL;
module_globals->vhosts_count = 0;
+ module_globals->server_shutdown = 0;
+ module_globals->exiting = NULL;
+ //module_globals->server = s;
+
(*module_globals->mpm_server_init)(pPool,pLog,pTemp,s);
}
else
{
- /* If we don't find the mpm handler module we give up */
+ /* If we don't find the mpm handler module we give up and exit */
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s,
MODNAME " Error loading MPM manager: %s",
@@ -936,10 +947,63 @@ Rivet_ServerInit (apr_pool_t *pPool, apr
return OK;
}
-static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *s)
+static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
{
- (*module_globals->mpm_child_init)(pChild,s);
- apr_pool_cleanup_register (pChild, s, module_globals->mpm_finalize, module_globals->mpm_finalize);
+ int idx;
+ rivet_server_conf* root_server_conf;
+ server_rec* s;
+
+ apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pChild);
+
+ /* Creating the module global pool */
+
+ apr_thread_mutex_lock(module_globals->pool_mutex);
+ if (apr_pool_create(&module_globals->pool, NULL) != APR_SUCCESS)
+ {
+ ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server,
+ MODNAME ": could not initialize mod_rivet private pool");
+ exit(1);
+ }
+ apr_thread_mutex_unlock(module_globals->pool_mutex);
+
+ /* Once we have established a pool with the same lifetime of the child process we
+ * process all the configured server records assigning an integer as unique key
+ * to each of them
+ */
+
+ root_server_conf = RIVET_SERVER_CONF( server->module_config );
+ idx = 0;
+ for (s = server; s != NULL; s = s->next)
+ {
+ rivet_server_conf* myrsc;
+
+ myrsc = RIVET_SERVER_CONF( s->module_config );
+
+ /* We only have a different rivet_server_conf if MergeConfig
+ * was called. We really need a separate one for each server,
+ * so we go ahead and create one here, if necessary. */
+
+ if (s != server && myrsc == root_server_conf) {
+ myrsc = RIVET_NEW_CONF(pChild);
+ ap_set_module_config(s->module_config, &rivet_module, myrsc);
+ Rivet_CopyConfig( root_server_conf, myrsc );
+ }
+
+ myrsc->idx = idx++;
+ }
+ module_globals->vhosts_count = idx;
+
+ /* Another crucial point: we are storing here in the globals a reference to the
+ * root server_rec object from which threads are supposed to derive
+ * all the other chain of virtual hosts server records
+ */
+
+ module_globals->server = server;
+
+ /* Calling the brigde child process initialization */
+
+ (*module_globals->mpm_child_init)(pChild,server);
+ apr_pool_cleanup_register (pChild, server, module_globals->mpm_finalize, module_globals->mpm_finalize);
}
static int Rivet_Handler (request_rec *r)
Modified: tcl/rivet/trunk/src/experimental/mod_rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/mod_rivet.h?rev=1617629&r1=1617628&r2=1617629&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/experimental/mod_rivet.h Wed Aug 13 00:08:24 2014
@@ -161,13 +161,18 @@ typedef struct _mod_rivet_globals {
server_rec* rivet_panic_server_rec;
} mod_rivet_globals;
+/* thread private interpreter error flags */
+
+#define RIVET_CACHE_FULL 1
typedef struct _vhost_interp {
Tcl_Interp* interp;
int cache_size;
int cache_free;
- char** objCacheList; /* Array of cached objects (for priority handling) */
Tcl_HashTable* objCache; /* Objects cache - the key is the script name */
+ char** objCacheList; /* Array of cached objects (for priority handling) */
+ apr_pool_t* pool; /* interpreters cache private memory pool */
+ unsigned int flags;
} vhost_interp;
Modified: tcl/rivet/trunk/src/experimental/rivet_prefork_mpm.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/rivet_prefork_mpm.c?rev=1617629&r1=1617628&r2=1617629&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/rivet_prefork_mpm.c (original)
+++ tcl/rivet/trunk/src/experimental/rivet_prefork_mpm.c Wed Aug 13 00:08:24 2014
@@ -315,17 +315,8 @@ void Rivet_MPM_ChildInit (apr_pool_t* po
{
rivet_thread_private* private;
- apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pool);
- //apr_threadkey_private_create (&rivet_thread_key,NULL, pool);
-
- apr_thread_mutex_lock(module_globals->pool_mutex);
- if (apr_pool_create(&module_globals->pool, pool) != APR_SUCCESS)
- {
- ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server,
- MODNAME ": could not initialize mod_rivet private pool");
- exit(1);
- }
- apr_thread_mutex_unlock(module_globals->pool_mutex);
+ // TODO TODO TODO TODO
+ // apr_threadkey_private_create (&rivet_thread_key, processor_cleanup, pool);
if (apr_threadkey_private_get ((void **)&private,rivet_thread_key) != APR_SUCCESS)
{
Modified: tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c?rev=1617629&r1=1617628&r2=1617629&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c (original)
+++ tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c Wed Aug 13 00:08:24 2014
@@ -19,8 +19,9 @@
under the License.
*/
-/* Id: */
+/* $Id: */
+#include <tcl.h>
#include <apr_strings.h>
#include "mod_rivet.h"
@@ -38,16 +39,30 @@ void Rivet_PerInterpInit(Tcl_Interp* in
static void processor_cleanup (void *data)
{
rivet_thread_private* private = (rivet_thread_private *) data;
- //rivet_server_conf* rsc;
+ Tcl_HashSearch* searchCtx;
+ Tcl_HashEntry* entry;
+ int i;
- //Tcl_UnregisterChannel(private->interp,*private->channel);
- //rsc = RIVET_SERVER_CONF( module_globals->server->module_config );
- //Tcl_DeleteHashTable(rsc->objCache);
- //Tcl_DeleteInterp(private->interp);
-
ap_log_error(APLOG_MARK, APLOG_INFO, 0, module_globals->server,
"Thread exiting after %d requests served", private->req_cnt);
+
+ for (i = 0; i < module_globals->vhosts_count; i++)
+ {
+ searchCtx = apr_pcalloc(private->pool,sizeof(Tcl_HashSearch));
+ entry = Tcl_FirstHashEntry(private->interps[i]->objCache,searchCtx);
+ while (entry)
+ {
+ Tcl_DecrRefCount(Tcl_GetHashValue(entry));
+ Tcl_DeleteHashEntry(entry);
+
+ entry = Tcl_NextHashEntry(searchCtx);
+ }
+
+ Tcl_UnregisterChannel(private->interps[i]->interp,*private->channel);
+ Tcl_DeleteInterp(private->interps[i]->interp);
+ }
+
apr_pool_destroy(private->pool);
}
@@ -75,22 +90,33 @@ static vhost_interp* Rivet_NewVHostInter
}
}
- if (interp_obj->cache_size != 0) {
+ if (interp_obj->cache_size > 0) {
interp_obj->cache_free = interp_obj->cache_size;
}
+ // we now create memory from the cache pool as subpool of the thread private pool
+
+ if (apr_pool_create(&interp_obj->pool, pool) != APR_SUCCESS)
+ {
+ ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, module_globals->server,
+ MODNAME ": could not initialize thread private pool");
+ return NULL;
+ }
+
// Initialize cache structures
if (interp_obj->cache_size) {
- interp_obj->objCacheList = apr_pcalloc(pool, (signed)(interp_obj->cache_size*sizeof(char *)));
- interp_obj->objCache = apr_pcalloc(pool, sizeof(Tcl_HashTable));
+ interp_obj->objCacheList = apr_pcalloc(interp_obj->pool, (signed)(interp_obj->cache_size*sizeof(char *)));
+ interp_obj->objCache = apr_pcalloc(interp_obj->pool, sizeof(Tcl_HashTable));
Tcl_InitHashTable(interp_obj->objCache, TCL_STRING_KEYS);
}
+ interp_obj->flags = 0;
+
return interp_obj;
}
-static void Rivet_VirtualHostsInterps (rivet_thread_private* private)
+static rivet_thread_private* Rivet_VirtualHostsInterps (rivet_thread_private* private)
{
server_rec* s;
server_rec* root_server = module_globals->server;
@@ -103,6 +129,10 @@ static void Rivet_VirtualHostsInterps (r
root_server_conf = RIVET_SERVER_CONF( root_server->module_config );
parentfunction = root_server_conf->rivet_child_init_script;
root_interp = Rivet_NewVHostInterp(private->pool);
+ if (root_interp == NULL)
+ {
+ return NULL;
+ }
for (s = root_server; s != NULL; s = s->next)
{
@@ -159,7 +189,7 @@ static void Rivet_VirtualHostsInterps (r
Tcl_Release (interp);
}
}
-
+ return private;
}
static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
@@ -169,7 +199,6 @@ static void* APR_THREAD_FUNC request_pro
//apr_threadkey_t* thread_key = (apr_threadkey_t *) data;
rivet_server_conf *rsc;
server_rec* server;
- int i;
apr_thread_mutex_lock(module_globals->job_mutex);
server = module_globals->server;
@@ -186,7 +215,6 @@ static void* APR_THREAD_FUNC request_pro
{
apr_thread_mutex_lock(module_globals->pool_mutex);
private = apr_palloc (module_globals->pool,sizeof(*private));
- private->channel = apr_pcalloc (module_globals->pool,sizeof(Tcl_Channel));
apr_thread_mutex_unlock(module_globals->pool_mutex);
private->req_cnt = 0;
@@ -207,6 +235,7 @@ static void* APR_THREAD_FUNC request_pro
* Data referenced in this database must be freed by the thread before exit
*/
+ private->channel = apr_pcalloc (private->pool,sizeof(Tcl_Channel));
private->interps = apr_pcalloc(private->pool,module_globals->vhosts_count*sizeof(vhost_interp));
apr_threadkey_private_set (private,rivet_thread_key);
@@ -251,7 +280,15 @@ static void* APR_THREAD_FUNC request_pro
* configuration and to the rivet global script
*/
- Rivet_VirtualHostsInterps (private);
+ if (Rivet_VirtualHostsInterps (private) == NULL)
+ {
+ apr_thread_mutex_lock(module_globals->job_mutex);
+ *(apr_thread_t **) apr_array_push(module_globals->exiting) = thd;
+ apr_thread_cond_signal(module_globals->job_cond);
+ apr_thread_mutex_unlock(module_globals->job_mutex);
+ apr_thread_exit(thd,APR_SUCCESS);
+ return NULL;
+ }
if (rsc->rivet_global_init_script != NULL) {
Tcl_Interp* interp = private->interps[0]->interp;
@@ -339,18 +376,6 @@ static void* APR_THREAD_FUNC request_pro
ap_log_error(APLOG_MARK, APLOG_INFO, 0, module_globals->server, "processor thread orlderly exit");
- /* thread private stuff clean up*/
-
- for (i = 0; i < module_globals->vhosts_count; i++)
- {
- Tcl_UnregisterChannel(private->interps[i]->interp,*private->channel);
- Tcl_DeleteHashTable(private->interps[i]->objCache);
- Tcl_DeleteInterp(private->interps[i]->interp);
-
- /* must free the cache here */
-
- }
-
apr_thread_mutex_lock(module_globals->job_mutex);
*(apr_thread_t **) apr_array_push(module_globals->exiting) = thd;
@@ -361,6 +386,8 @@ static void* APR_THREAD_FUNC request_pro
apr_atomic_dec32(module_globals->threads_count);
+ /* this call triggers thread private stuff clean up by calling processor_cleanup */
+
apr_thread_exit(thd,APR_SUCCESS);
return NULL;
}
@@ -498,62 +525,15 @@ int Rivet_MPM_ServerInit (apr_pool_t *pP
void Rivet_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
{
apr_status_t rv;
- int idx;
- server_rec* s;
- rivet_server_conf* root_server_conf;
+ apr_threadkey_private_create (&rivet_thread_key, processor_cleanup, pool);
apr_thread_mutex_create(&module_globals->job_mutex, APR_THREAD_MUTEX_UNNESTED, pool);
apr_thread_cond_create(&module_globals->job_cond, pool);
- apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pool);
- apr_threadkey_private_create (&rivet_thread_key, processor_cleanup, pool);
+
apr_threadkey_private_create (&handler_thread_key, NULL, pool);
module_globals->exiting = apr_array_make(pool,100,sizeof(apr_thread_t*));
- /* Another crucial point: we are storing here in the globals a reference to the
- * root server_rec object from which threads are supposed to derive
- * all the other chain of virtual hosts server records
- */
-
- module_globals->server = server;
-
- apr_thread_mutex_lock(module_globals->pool_mutex);
- if (apr_pool_create(&module_globals->pool, NULL) != APR_SUCCESS)
- {
- ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server,
- MODNAME ": could not initialize mod_rivet private pool");
- exit(1);
- }
- apr_thread_mutex_unlock(module_globals->pool_mutex);
-
- /* Once we have established a pool with the same lifetime of the child process we
- * process all the server records in configuration assigning an integer as unique key
- * to each of them
- */
-
- idx = 0;
- root_server_conf = RIVET_SERVER_CONF( server->module_config );
- for (s = server; s != NULL; s = s->next)
- {
- rivet_server_conf* myrsc;
-
- myrsc = RIVET_SERVER_CONF( s->module_config );
-
- /* We only have a different rivet_server_conf if MergeConfig
- * was called. We really need a separate one for each server,
- * so we go ahead and create one here, if necessary. */
-
- if (s != server && myrsc == root_server_conf) {
- myrsc = RIVET_NEW_CONF(pool);
- ap_set_module_config(s->module_config, &rivet_module, myrsc);
- Rivet_CopyConfig( root_server_conf, myrsc );
- }
-
- myrsc->idx = idx++;
- }
-
- module_globals->vhosts_count = idx;
-
if (apr_queue_create(&module_globals->queue, MOD_RIVET_QUEUE_SIZE, module_globals->pool) != APR_SUCCESS)
{
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server,
---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org