mod_perl locking problem with Apache::Session
am 30.12.2007 06:53:07 von PerlGuy
Solved this once years ago and completely forgot the solution. Here's
the setup:
mod_perl2, Apache 2, Apache::Session::MySQL, ModPerl::Registry, and
Apache::DBI
Each script uses Apache::Session::MySQL to get a session and or write
back to the existing session. Apache::Session::Lock::MySQL issues
locks to the database with a GET_LOCK and RELEASE_LOCK statement.
Under normal circumstances there is no problem. However, if we double
click a "submit" button on a Web page or in some other way get two of
the Apache mod_perl processes to be making requests using the same
session at the same time, then we get into a lock condition. MySQL
database shows User Lock states for the processes that are stuck in a
lock:
SELECT GET_LOCK('Apache-Session-4a3a60b7ec332a2de29dd95081c4406a',
3600)
Essentially those apache processes are hosed since they keep a
consistent DB connection with Apache::DBI
The button must really be "double-clicked" quickly to get this
effect. The first time a process is started and it grabs the lock.
The process does not complete -- it's like it is interrupted. The
second one makes any updates to the database. Only solution I've come
up with so far is to modify the lock time in
Apache::Session::Lock::MySQL down to something like 10 seconds which
is still 10x longer than any script will ever take.
What's the solution?
Re: mod_perl locking problem with Apache::Session
am 07.01.2008 09:07:50 von PerlGuy
Chalk this one up as an FAQ:
If you're getting lots of locked Apache2 processes under mod_perl2 and
you just moved your code over from standard CGI's, you're probably
getting a few warnings about variables not remaining shared.
Essentially the problem is that closures are getting created by those
variables not remaining shared and if any of those variables are
related to a database connection then you get locked processes. Once
I made a few adjustments to my code to remove the variable warnings,
the locking issues went away too.
On Dec 29 2007, 9:53=A0pm, PerlGuy wrote:
> Solved this once years ago and completely forgot the solution. =A0Here's
> the setup:
>
> mod_perl2, Apache 2, Apache::Session::MySQL, ModPerl::Registry, and
> Apache::DBI
>
> Each script uses Apache::Session::MySQL to get a session and or write
> back to the existing session. =A0Apache::Session::Lock::MySQL issues
> locks to the database with a GET_LOCK and RELEASE_LOCK statement.
> Under normal circumstances there is no problem. =A0However, if we double
> click a "submit" button on a Web page or in some other way get two of
> the Apache mod_perl processes to be making requests using the same
> session at the same time, then we get into alockcondition. =A0MySQL
> database shows UserLockstates for the processes that are stuck in alock:
>
> SELECT GET_LOCK('Apache-Session-4a3a60b7ec332a2de29dd95081c4406a',
> 3600)
>
> Essentially those apache processes are hosed since they keep a
> consistent DB connection with Apache::DBI
>
> The button must really be "double-clicked" quickly to get this
> effect. =A0The first time a process is started and it grabs thelock.
> The process does not complete -- it's like it is interrupted. =A0The
> second one makes any updates to the database. =A0Only solution I've come
> up with so far is to modify thelocktime in
> Apache::Session::Lock::MySQL down to something like 10 seconds which
> is still 10x longer than any script will ever take.
>
> What's the solution?
Re: mod_perl locking problem with Apache::Session
am 07.01.2008 11:12:50 von lihao0129
On Jan 7, 3:07=A0am, PerlGuy wrote:
> Chalk this one up as an FAQ:
>
> If you're getting lots of locked Apache2 processes under mod_perl2 and
> you just moved your code over from standard CGI's, you're probably
> getting a few warnings about variables not remaining shared.
> Essentially the problem is that closures are getting created by those
> variables not remaining shared and if any of those variables are
> related to a database connection then you get locked processes. =A0Once
> I made a few adjustments to my code to remove the variable warnings,
> the locking issues went away too.
>
> On Dec 29 2007, 9:53=A0pm, PerlGuy wrote:
>
If you are using Apache::Session::MySQL, why not directly go to MySQL.
I believe that MySQL itself can handle lock/unlock things pretty well.
there is no much need to have to use a module to handle sessions,
especially with Database. The only real thing you need to do without
such modules is to generate session_ids by yourself. For me, I will
only consider using Apache::Session::File in Apache::Session::*
families.. My two cents
lihao(XC)