You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Reinwald Warapen <re...@directi.com> on 2011/01/14 15:56:35 UTC

Configuring Tomcat 6 to "Always Load" and "Always Save Sessions"

Hey,
Im am migrating my webapp from Resin to Tomcat 6. In Resin there is an 
option to "always save sessions" and "always load sessions" from the 
persistent store (mysql db). Ive configured my tomcat instance to use 
the JDBC for the persistence of sessions. 
(http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html ). But the 
sessions are stored only when Tomcat shutsdown/restarts or if the idle 
time has exceeded. There is no mention of how to "always save" and 
"always load sessions" from the db.

My requirement is such that I want to run two standalone instances of 
Tomcat (not using clustering) and for every request it loads the session 
from the database and saves it back.

Can you please tell me if this is possible in Tomcat . If yes, how.

Thanks

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


Re: Configuring Tomcat 6 to

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Agareppe,

On 11/6/13, 8:02 AM, Agareppe wrote:
> I create an extension of the tomcat PersistenceManager. It writes
> every session change into the database

What's wrong with the existing PersistenceManager + JDBCStore?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJSel0OAAoJEBzwKT+lPKRYeTIQAIi5wy6YhKUC3v7QRQG0Kj1J
VLRuBWGmDCMaFWRUp+EOgIlC72FlOqrZtHhGlYZvVZITqb7+vOiuynWx1rO72rqn
3CoawPpl6rJwYF0mKpT+8W/jJahZWEI50/A9DOavd0KZPSZ655iSFKULWb9q1i1o
wPDjggIJ5yd+Ls8wzKS8A8+8Oc0BdJT82LrkVmXnvWZ7qYT9ZI4svDpqhCIPmWMf
jJx0RAtXFG6AtdOjKOZlWEkoa2ekerGKAoSmfTeABjH+eMhexDLtL6jFdkXS/Wws
Ogvjh6g4IOewMzEMF6uZQXPonIgTqnYxiJ35FG/tP6Jbc37GQKtwPqwcrAG3g8x+
N/x/1oGN7nQsZqGV0iH3Jrx1ANkRZisvjActbtD7Km8MxHsVRpNuoFD1PaR+u47H
VraEkdS1h+6RHjLhDHwXNbxSYPd/IYDIOKTTWaTTuGMCednVw2SzaAo3usvf8lYa
woVU6W/rleruOwOeIo41AkWY5OHQD9OgqdqkeG1UtXhLZCfclYwlzTiEoZj2du5S
arGZL9liyB/mwsDTxcozhlYB85HXbS02bIISH91e/Wp/T3ys1WTpdPvJ8+m+DyFp
JBZudU2z4lISO7lG0bUmkZd42DtofMeT1yvK0o/g7Sg4iHFi03cEqei7/WpgFMhy
glsiAWD2AOi4OWsRNOyF
=Q8Tz
-----END PGP SIGNATURE-----

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


Re: Configuring Tomcat 6 to

Posted by Agareppe <ag...@gmail.com>.
I create an extension of the tomcat PersistenceManager.
It writes every session change into the database 
Of course that the request performance is not the same. 
But for the ppl that is looking for this could be useful,
Is not that much code
 
I haven't shared it in git, but if you  are still looking for 
this I'll share



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


Re: Configuring Tomcat 6 to "Always Load" and "Always Save Sessions"

Posted by Reinwald Warapen <re...@directi.com>.
Thanks Martin Grotzke for the answer.

"Its's not possible with PersistentManager. PersistentManagerBase
backups all sessions in batches (processMaxIdleSwaps(),
processMaxIdleBackups() are called by the background thread). You
might try to set maxIdleBackup and maxIdleSwap to 0. But even then
sessions are only stored by the background thread (running every 10
seconds by default IIRC) and not directly at the end of the request.
That was one of the reasons why PersistentManager was not an option
for me.
Therefore it's not suited for non-sticky sessions and as a failover
solution it's not reliable as sessions/session updates might get lost."



On 1/15/2011 8:52 PM, Reinwald Warapen wrote:
> Any idea why the session does not get persisted to the database 
> immediately (when setting maxIdleSwap='0'). Or is there any other 
> possible way to  "Always Load" and "Always Save Sessions" from the 
> database in Tomcat 6
>
> On 1/14/2011 9:07 PM, Reinwald Warapen wrote:
>> Thanks Mark for the quick response.
>>
>> I just tried what you mentioned setting maxIdleSwap='0'. But for some 
>> reason the session does not get persisted to the database 
>> immediately. It takes around 30 sec for it to happen . Any other 
>> setting I need to add inorder that it saves immediately so that i can 
>> safely use it in a non-sticky session environment.
>> Ive added a snippet of the server.xml for your reference :
>> <Manager className="org.apache.catalina.session.PersistentManager" 
>> maxIdleSwap='0'>
>> <Store className="org.apache.catalina.session.JDBCStore"
>>                                                                 
>> connectionURL="jdbc:mysql://172.16.142.163:3306/session2?user=user&amp;password=password" 
>>
>>                                                                 
>> driverName="com.mysql.jdbc.Driver"
>>                                                                 
>> sessionAppCol="app_name"
>>                                                                 
>> sessionDataCol="session_data"
>>                                                                 
>> sessionIdCol="session_id"
>>                                                                 
>> sessionLastAccessedCol="last_access"
>>                                                                 
>> sessionMaxInactiveCol="max_inactive"
>>                                                                 
>> sessionTable="tomcat_sessions"
>>                                                                 
>> sessionValidCol="valid_session" />
>>
>> </Manager>
>>
>> Thanks
>>
>>  On 1/14/2011 8:31 PM, Mark Thomas wrote:
>>> On 14/01/2011 14:56, Reinwald Warapen wrote:
>>>> Hey,
>>>> Im am migrating my webapp from Resin to Tomcat 6. In Resin there is an
>>>> option to "always save sessions" and "always load sessions" from the
>>>> persistent store (mysql db). Ive configured my tomcat instance to use
>>>> the JDBC for the persistence of sessions.
>>>> (http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html ). But 
>>>> the
>>>> sessions are stored only when Tomcat shutsdown/restarts or if the idle
>>>> time has exceeded. There is no mention of how to "always save" and
>>>> "always load sessions" from the db.
>>>>
>>>> My requirement is such that I want to run two standalone instances of
>>>> Tomcat (not using clustering) and for every request it loads the 
>>>> session
>>>> from the database and saves it back.
>>>>
>>>> Can you please tell me if this is possible in Tomcat . If yes, how.
>>> > From looking at the source code, setting maxIdleSwap to zero 
>>> should do
>>> the trick.
>>>
>>> Mark
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>
>


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


Re: Configuring Tomcat 6 to "Always Load" and "Always Save Sessions"

Posted by Reinwald Warapen <re...@directi.com>.
Any idea why the session does not get persisted to the database 
immediately (when setting maxIdleSwap='0'). Or is there any other 
possible way to  "Always Load" and "Always Save Sessions" from the 
database in Tomcat 6

On 1/14/2011 9:07 PM, Reinwald Warapen wrote:
> Thanks Mark for the quick response.
>
> I just tried what you mentioned setting maxIdleSwap='0'. But for some 
> reason the session does not get persisted to the database immediately. 
> It takes around 30 sec for it to happen . Any other setting I need to 
> add inorder that it saves immediately so that i can safely use it in a 
> non-sticky session environment.
> Ive added a snippet of the server.xml for your reference :
> <Manager className="org.apache.catalina.session.PersistentManager" 
> maxIdleSwap='0'>
> <Store className="org.apache.catalina.session.JDBCStore"
>                                                                 
> connectionURL="jdbc:mysql://172.16.142.163:3306/session2?user=user&amp;password=password"
>                                                                 
> driverName="com.mysql.jdbc.Driver"
>                                                                 
> sessionAppCol="app_name"
>                                                                 
> sessionDataCol="session_data"
>                                                                 
> sessionIdCol="session_id"
>                                                                 
> sessionLastAccessedCol="last_access"
>                                                                 
> sessionMaxInactiveCol="max_inactive"
>                                                                 
> sessionTable="tomcat_sessions"
>                                                                 
> sessionValidCol="valid_session" />
>
> </Manager>
>
> Thanks
>
>  On 1/14/2011 8:31 PM, Mark Thomas wrote:
>> On 14/01/2011 14:56, Reinwald Warapen wrote:
>>> Hey,
>>> Im am migrating my webapp from Resin to Tomcat 6. In Resin there is an
>>> option to "always save sessions" and "always load sessions" from the
>>> persistent store (mysql db). Ive configured my tomcat instance to use
>>> the JDBC for the persistence of sessions.
>>> (http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html ). But the
>>> sessions are stored only when Tomcat shutsdown/restarts or if the idle
>>> time has exceeded. There is no mention of how to "always save" and
>>> "always load sessions" from the db.
>>>
>>> My requirement is such that I want to run two standalone instances of
>>> Tomcat (not using clustering) and for every request it loads the 
>>> session
>>> from the database and saves it back.
>>>
>>> Can you please tell me if this is possible in Tomcat . If yes, how.
>> > From looking at the source code, setting maxIdleSwap to zero should do
>> the trick.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>


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


Re: Configuring Tomcat 6 to "Always Load" and "Always Save Sessions"

Posted by Reinwald Warapen <re...@directi.com>.
Thanks Mark for the quick response.

I just tried what you mentioned setting maxIdleSwap='0'. But for some 
reason the session does not get persisted to the database immediately. 
It takes around 30 sec for it to happen . Any other setting I need to 
add inorder that it saves immediately so that i can safely use it in a 
non-sticky session environment.
Ive added a snippet of the server.xml for your reference :
<Manager className="org.apache.catalina.session.PersistentManager" 
maxIdleSwap='0'>
<Store className="org.apache.catalina.session.JDBCStore"
                                                                 
connectionURL="jdbc:mysql://172.16.142.163:3306/session2?user=user&amp;password=password"
                                                                 
driverName="com.mysql.jdbc.Driver"
                                                                 
sessionAppCol="app_name"
                                                                 
sessionDataCol="session_data"
                                                                 
sessionIdCol="session_id"
                                                                 
sessionLastAccessedCol="last_access"
                                                                 
sessionMaxInactiveCol="max_inactive"
                                                                 
sessionTable="tomcat_sessions"
                                                                 
sessionValidCol="valid_session" />

</Manager>

Thanks

  On 1/14/2011 8:31 PM, Mark Thomas wrote:
> On 14/01/2011 14:56, Reinwald Warapen wrote:
>> Hey,
>> Im am migrating my webapp from Resin to Tomcat 6. In Resin there is an
>> option to "always save sessions" and "always load sessions" from the
>> persistent store (mysql db). Ive configured my tomcat instance to use
>> the JDBC for the persistence of sessions.
>> (http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html ). But the
>> sessions are stored only when Tomcat shutsdown/restarts or if the idle
>> time has exceeded. There is no mention of how to "always save" and
>> "always load sessions" from the db.
>>
>> My requirement is such that I want to run two standalone instances of
>> Tomcat (not using clustering) and for every request it loads the session
>> from the database and saves it back.
>>
>> Can you please tell me if this is possible in Tomcat . If yes, how.
> > From looking at the source code, setting maxIdleSwap to zero should do
> the trick.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


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


Re: Configuring Tomcat 6 to "Always Load" and "Always Save Sessions"

Posted by Mark Thomas <ma...@apache.org>.
On 14/01/2011 14:56, Reinwald Warapen wrote:
> Hey,
> Im am migrating my webapp from Resin to Tomcat 6. In Resin there is an
> option to "always save sessions" and "always load sessions" from the
> persistent store (mysql db). Ive configured my tomcat instance to use
> the JDBC for the persistence of sessions.
> (http://tomcat.apache.org/tomcat-6.0-doc/config/manager.html ). But the
> sessions are stored only when Tomcat shutsdown/restarts or if the idle
> time has exceeded. There is no mention of how to "always save" and
> "always load sessions" from the db.
> 
> My requirement is such that I want to run two standalone instances of
> Tomcat (not using clustering) and for every request it loads the session
> from the database and saves it back.
> 
> Can you please tell me if this is possible in Tomcat . If yes, how.

>From looking at the source code, setting maxIdleSwap to zero should do
the trick.

Mark

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