You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2008/10/06 16:28:21 UTC

svn commit: r702160 - /tomcat/connectors/trunk/jk/native/common/jk_shm.c

Author: mturk
Date: Mon Oct  6 07:28:20 2008
New Revision: 702160

URL: http://svn.apache.org/viewvc?rev=702160&view=rev
Log:
Implement global shared memory lock for IIS. With IIS 6+ we don't have a single process any more

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_shm.c

Modified: tomcat/connectors/trunk/jk/native/common/jk_shm.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_shm.c?rev=702160&r1=702159&r2=702160&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_shm.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_shm.c Mon Oct  6 07:28:20 2008
@@ -81,6 +81,7 @@
 static time_t jk_workers_access_time = 0;
 #if defined (WIN32)
 static HANDLE jk_shm_map = NULL;
+static HANDLE jk_shm_hlock = NULL;
 #endif
 
 /* Calculate needed shm size */
@@ -150,6 +151,7 @@
 {
     int rc;
     int attached = 0;
+    char lkname[MAX_PATH];
     JK_TRACE_ENTER(l);
     if (jk_shmem.hdr) {
         if (JK_IS_DEBUG_LEVEL(l))
@@ -178,6 +180,19 @@
             JK_TRACE_EXIT(l);
             return -1;
         }
+        sprintf(lkname, "Global\\%s_MUTEX", fname);
+        if (attached) {
+            jk_shm_hlock = OpenMutex(MUTEX_ALL_ACCESS, FALSE, lkname);
+        }
+        else {
+            jk_shm_hlock = CreateMutex(NULL, FALSE, lkname);            
+        }
+        if (jk_shm_hlock == NULL || jk_shm_hlock == INVALID_HANDLE_VALUE) {
+            CloseHandle(jk_shm_map);
+            jk_shm_map = NULL;
+            JK_TRACE_EXIT(l);
+            return -1;
+        }
         jk_shmem.hdr = (jk_shm_header_t *)MapViewOfFile(jk_shm_map,
                                                         FILE_MAP_ALL_ACCESS,
                                                         0,
@@ -193,6 +208,10 @@
             CloseHandle(jk_shm_map);
             jk_shm_map = NULL;
         }
+        if (jk_shm_hlock) {
+            CloseHandle(jk_shm_hlock);
+            jk_shm_hlock = NULL;
+        }
 #endif
         JK_TRACE_EXIT(l);
         return -1;
@@ -270,6 +289,10 @@
     if (jk_shmem.hdr) {
         int rc;
 #if defined (WIN32)
+        if (jk_shm_hlock) {
+            CloseHandle(jk_shm_hlock);
+            jk_shm_hlock = NULL;
+        }
         if (jk_shm_map) {
             --jk_shmem.hdr->h.data.childs;
             UnmapViewOfFile(jk_shmem.hdr);
@@ -707,9 +730,19 @@
 {
     int rc;
     JK_ENTER_CS(&(jk_shmem.cs), rc);
+#if defined (WIN32)
+    if (rc == JK_TRUE && jk_shm_hlock != NULL) {
+        DWORD rv = WaitForSingleObject(jk_shm_hlock, INFINITE);
+        if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED)
+            rc = JK_TRUE;
+        else
+            rc = JK_FALSE;         
+    }
+#else    
     if (rc == JK_TRUE && jk_shmem.fd_lock != -1) {
         JK_ENTER_LOCK(jk_shmem.fd_lock, rc);
     }
+#endif
     return rc;
 }
 
@@ -717,9 +750,16 @@
 {
     int rc;
     JK_LEAVE_CS(&(jk_shmem.cs), rc);
+#if defined (WIN32)
+    if (rc == JK_TRUE && jk_shm_hlock != NULL) {
+        if (!ReleaseMutex(jk_shm_hlock))
+            rc = JK_FALSE;         
+    }
+#else    
     if (rc == JK_TRUE && jk_shmem.fd_lock != -1) {
         JK_LEAVE_LOCK(jk_shmem.fd_lock, rc);
     }
+#endif
     return rc;
 }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r702160 - /tomcat/connectors/trunk/jk/native/common/jk_shm.c

Posted by Mladen Turk <mt...@apache.org>.
Rainer Jung wrote:
> mturk@apache.org schrieb:
>> Author: mturk
>> Date: Mon Oct  6 07:28:20 2008
>> New Revision: 702160
>>
>> URL: http://svn.apache.org/viewvc?rev=702160&view=rev
>> Log:
>> Implement global shared memory lock for IIS. With IIS 6+ we don't have a single process any more
> 
> I also noticed, that the new feature I added some months ago, namely
> automatic sizing of the shm segment will fail, if there are multiple
> processes that allocate wofrkers duplicate from the shm.
> 
> For Apache, only the parent will allocate from shm, but for IIS with
> application pools, each pool will allocate independently from shm.
> 
> As long as the workers.properties only exist globally, each pool will
> have the same workers and thus the size of the shm needs to be
> multiplied with the number of pools. Is this something we can retrieve
> easily during initialization?
> 

I fixed that.
See the r699569. The shared memory name now has INSTANCE_ID appended.

Regards
-- 
^(TM)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r702160 - /tomcat/connectors/trunk/jk/native/common/jk_shm.c

Posted by Rainer Jung <ra...@kippdata.de>.
mturk@apache.org schrieb:
> Author: mturk
> Date: Mon Oct  6 07:28:20 2008
> New Revision: 702160
> 
> URL: http://svn.apache.org/viewvc?rev=702160&view=rev
> Log:
> Implement global shared memory lock for IIS. With IIS 6+ we don't have a single process any more

I also noticed, that the new feature I added some months ago, namely
automatic sizing of the shm segment will fail, if there are multiple
processes that allocate wofrkers duplicate from the shm.

For Apache, only the parent will allocate from shm, but for IIS with
application pools, each pool will allocate independently from shm.

As long as the workers.properties only exist globally, each pool will
have the same workers and thus the size of the shm needs to be
multiplied with the number of pools. Is this something we can retrieve
easily during initialization?

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r702160 - /tomcat/connectors/trunk/jk/native/common/jk_shm.c

Posted by Mladen Turk <mt...@apache.org>.
Rainer Jung wrote:
> mturk@apache.org schrieb:
>> Author: mturk
>> Date: Mon Oct  6 07:28:20 2008
>> New Revision: 702160
>>
>> URL: http://svn.apache.org/viewvc?rev=702160&view=rev
>> Log:
>> Implement global shared memory lock for IIS. With IIS 6+ we don't have a single process any more
> 
> I was talking to someone having exactly a shared memory corruption
> problem for IIS 6 with application pools (multiple processes) yesterday.
> So this is great.
> 
> The same holds true for the log file. Could we use the same construction
> for the log file locking, or would that be bad? The user involved has
> corrupt log lines every now and then, although log level is only info,
> so they don't have a huge log volume. So I expect the multiple processes
> currupt lines when incidentally logging in parallel.
> 
> Is there an easy way to distinguish the application pools (like a name
> in the registry or so)? We could then add the application pool name to
> the log lines. Of course we already have the pid there, but users can't
> easily find out which pid belongs to which application pool.
> 

It's hard (or even impossible without using IIS7 API directy) to
figure out the number of pools and processes.
Think that a simple global mutex for each log file would do the
trick. We are using stream files so there might be delay between
fputs and flush. With mutex this would be done as atomic operation.


Regards
-- 
^(TM)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r702160 - /tomcat/connectors/trunk/jk/native/common/jk_shm.c

Posted by Rainer Jung <ra...@kippdata.de>.
mturk@apache.org schrieb:
> Author: mturk
> Date: Mon Oct  6 07:28:20 2008
> New Revision: 702160
> 
> URL: http://svn.apache.org/viewvc?rev=702160&view=rev
> Log:
> Implement global shared memory lock for IIS. With IIS 6+ we don't have a single process any more

I was talking to someone having exactly a shared memory corruption
problem for IIS 6 with application pools (multiple processes) yesterday.
So this is great.

The same holds true for the log file. Could we use the same construction
for the log file locking, or would that be bad? The user involved has
corrupt log lines every now and then, although log level is only info,
so they don't have a huge log volume. So I expect the multiple processes
currupt lines when incidentally logging in parallel.

Is there an easy way to distinguish the application pools (like a name
in the registry or so)? We could then add the application pool name to
the log lines. Of course we already have the pid there, but users can't
easily find out which pid belongs to which application pool.

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org