You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by fa...@geocom.com.uy on 2010/10/28 19:31:22 UTC

RV: Session & Context variables architecture problem

Dear All,

                I'm currently using Tomcat 6.0.28 and having some doubt on
how to solve and implement this problem:

 

                               My webapp has a MySQL Database with a table
named "parameters", in which we have just two columns ("property" and
"value"). This table is acceded many times but doesn't change often.

 

                               For performance purposes I want to save this
parameters in the user's tomcat session, so they are read from memory and
not database. So far so good.

 

                               Now the problem: how can I tell this sessions
that an attribute has changed?

 

                I had suggestions of using "context variables" instead of
"session variables", but that didn't solve the problem.

 

Any help in this matter is more than welcome. I have no problem in changing
the approach, and may be not use sessions at all.

 

Thanks in advance.

 

Best regards,

                Federico Alvarez.

 

Info:

                Tomcat 6.0.28

                Java 1.6

                MySQL 5.5

                NOT USING HIBERNATE, so 2nd Level cache is not an option


Re: RV: Session & Context variables architecture problem

Posted by Ronald Klop <ro...@base.nl>.
Just query the database. Enable query caching in mysql. And only optimize in java if you see a bottleneck.
My mysql does 15000 queries/sec.

What is your expectation of number of queries?

Ronald.


Op donderdag, 28 oktober 2010 19:31 schreef falvarez@geocom.com.uy:
> 
>  
> 
> Dear All,
> 
>                 I'm currently using Tomcat 6.0.28 and having some doubt on
> how to solve and implement this problem:
> 
>  
> 
>                                My webapp has a MySQL Database with a table
> named "parameters", in which we have just two columns ("property" and
> "value"). This table is acceded many times but doesn't change often.
> 
>  
> 
>                                For performance purposes I want to save this
> parameters in the user's tomcat session, so they are read from memory and
> not database. So far so good.
> 
>  
> 
>                                Now the problem: how can I tell this sessions
> that an attribute has changed?
> 
>  
> 
>                 I had suggestions of using "context variables" instead of
> "session variables", but that didn't solve the problem.
> 
>  
> 
> Any help in this matter is more than welcome. I have no problem in changing
> the approach, and may be not use sessions at all.
> 
>  
> 
> Thanks in advance.
> 
>  
> 
> Best regards,
> 
>                 Federico Alvarez.
> 
>  
> 
> Info:
> 
>                 Tomcat 6.0.28
> 
>                 Java 1.6
> 
>                 MySQL 5.5
> 
>                 NOT USING HIBERNATE, so 2nd Level cache is not an option
> 
> 
> 
> 
> 


Re: RV: Session & Context variables architecture problem

Posted by Pid * <pi...@pidster.com>.
Nothing like wasting your time to get job satisfaction...


p

On 29 Oct 2010, at 17:39, "falvarez@geocom.com.uy"
<fa...@geocom.com.uy> wrote:

> Thanks Ronald and Pid for the help.
>
> Honestly I don't know if this parameters thing is really a performance issue, but I've been assigned to work on it so I don't have much choice, ;).
>
> I liked the idea of a class handling the attributes in ServletContext.
>
> I'll give it a try and let you know of the outcome.
>
> Thanks again.
>
> Best regards,
>    Federico Alvarez.
>
>
>
>
> Lic. Federico Alvarez
> Analista Genexus
> ········································································
> GEOCOM Uruguay S.A.
> Dionisio Oribe 3071 // Montevideo CP 11600 // Uruguay
> Tels.: (+598) 2 481 7777 ext. 775 / Fax.: 481 7777 ext. 718
>  EnGEOCOM  nos comprometemos con el Medio Ambiente: Antes de imprimir este e-mail piense bien si es necesario.
> NOTA DE CONFIDENCIALIDAD: La informacion transmitida en este mensaje y sus archivos adjuntos son para la persona o entidad a la cual esta dirigida y puede contener material privilegiado y/o confidencial. Su transmision se encuentra legalmente protegida. Si usted ha recibido este e-mail por error, comuniquelo inmediatamente por esta via su autor y eliminelo de su sistema. Si usted no es el destinatario especificado en el mensaje, cualquier revelacion copia o distribucion de su contenido esta estrictamente prohibida. Es responsabilidad del receptor asegurarse que el mensaje y sus archivos adjuntos se encuentren libres de virus. El mensaje expresa la opinion de su autor pero no necesariamente la de GEOCOM Uruguay S.A. Ni GEOCOM Uruguay S.A ni su autor se hacen responsables por las alteraciones que pueda sufrir este mensaje a partir de su envio.
>
> -----Mensaje original-----
> De: Pid [mailto:pid@pidster.com]
> Enviado el: jueves, 28 de octubre de 2010 19:36
> Para: Tomcat Users List
> Asunto: Re: RV: Session & Context variables architecture problem
>
> On 28/10/2010 18:31, falvarez@geocom.com.uy wrote:
>> Dear All,
>>                I'm currently using Tomcat 6.0.28 and having some
>> doubt on how to solve and implement this problem:
>>                               My webapp has a MySQL Database with a
>> table named "parameters", in which we have just two columns
>> ("property" and "value"). This table is acceded many times but doesn't change often.
>>
>>                               For performance purposes I want to save
>> this parameters in the user's tomcat session, so they are read from
>> memory and not database. So far so good.
>
> Do you actually know that this is a performance problem, or are you guessing that it is?
>
>>                               Now the problem: how can I tell this
>> sessions that an attribute has changed?
>
> Using the session will mean that you have duplicate copies of this information in each session.
>
>>                I had suggestions of using "context variables" instead
>> of "session variables", but that didn't solve the problem.
>
> *If* you need to do this, using the Context is probably better.
>
> I would suggest that you created a class which periodically updated all the values by selecting the data in the DB and storing the result in the Context.
>
> Implementing a ServletContextListener will give you access to the ServletContext and two methods, for app startup & shutdown, which you can use to start the periodic process, and properly stop it (very important).
>
> You may consider using a Timer, or something from the java.util.concurrent package.
>
>
> p
>
>> Any help in this matter is more than welcome. I have no problem in
>> changing the approach, and may be not use sessions at all.
>>
>> Thanks in advance.
>>
>> Best regards,
>>
>>                Federico Alvarez.
>>
>> Info:
>>
>>                Tomcat 6.0.28
>>                Java 1.6
>>                MySQL 5.5
>>
>>                NOT USING HIBERNATE, so 2nd Level cache is not an
>> option
>
>
>
> ---------------------------------------------------------------------
> 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: RV: Session & Context variables architecture problem

Posted by fa...@geocom.com.uy.
Thanks Ronald and Pid for the help.

Honestly I don't know if this parameters thing is really a performance issue, but I've been assigned to work on it so I don't have much choice, ;).

I liked the idea of a class handling the attributes in ServletContext.

I'll give it a try and let you know of the outcome.

Thanks again.

Best regards,
	Federico Alvarez.




Lic. Federico Alvarez
Analista Genexus 
········································································ 
GEOCOM Uruguay S.A. 
Dionisio Oribe 3071 // Montevideo CP 11600 // Uruguay 
Tels.: (+598) 2 481 7777 ext. 775 / Fax.: 481 7777 ext. 718 
 EnGEOCOM  nos comprometemos con el Medio Ambiente: Antes de imprimir este e-mail piense bien si es necesario.
NOTA DE CONFIDENCIALIDAD: La informacion transmitida en este mensaje y sus archivos adjuntos son para la persona o entidad a la cual esta dirigida y puede contener material privilegiado y/o confidencial. Su transmision se encuentra legalmente protegida. Si usted ha recibido este e-mail por error, comuniquelo inmediatamente por esta via su autor y eliminelo de su sistema. Si usted no es el destinatario especificado en el mensaje, cualquier revelacion copia o distribucion de su contenido esta estrictamente prohibida. Es responsabilidad del receptor asegurarse que el mensaje y sus archivos adjuntos se encuentren libres de virus. El mensaje expresa la opinion de su autor pero no necesariamente la de GEOCOM Uruguay S.A. Ni GEOCOM Uruguay S.A ni su autor se hacen responsables por las alteraciones que pueda sufrir este mensaje a partir de su envio.

-----Mensaje original-----
De: Pid [mailto:pid@pidster.com] 
Enviado el: jueves, 28 de octubre de 2010 19:36
Para: Tomcat Users List
Asunto: Re: RV: Session & Context variables architecture problem

On 28/10/2010 18:31, falvarez@geocom.com.uy wrote:
> Dear All,
>                 I'm currently using Tomcat 6.0.28 and having some 
> doubt on how to solve and implement this problem:
>                                My webapp has a MySQL Database with a 
> table named "parameters", in which we have just two columns 
> ("property" and "value"). This table is acceded many times but doesn't change often.
> 
>                                For performance purposes I want to save 
> this parameters in the user's tomcat session, so they are read from 
> memory and not database. So far so good.

Do you actually know that this is a performance problem, or are you guessing that it is?

>                                Now the problem: how can I tell this 
> sessions that an attribute has changed?

Using the session will mean that you have duplicate copies of this information in each session.

>                 I had suggestions of using "context variables" instead 
> of "session variables", but that didn't solve the problem.

*If* you need to do this, using the Context is probably better.

I would suggest that you created a class which periodically updated all the values by selecting the data in the DB and storing the result in the Context.

Implementing a ServletContextListener will give you access to the ServletContext and two methods, for app startup & shutdown, which you can use to start the periodic process, and properly stop it (very important).

You may consider using a Timer, or something from the java.util.concurrent package.


p

> Any help in this matter is more than welcome. I have no problem in 
> changing the approach, and may be not use sessions at all.
> 
> Thanks in advance.
> 
> Best regards,
> 
>                 Federico Alvarez.
> 
> Info:
> 
>                 Tomcat 6.0.28
>                 Java 1.6
>                 MySQL 5.5
> 
>                 NOT USING HIBERNATE, so 2nd Level cache is not an 
> option



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


Re: RV: Session & Context variables architecture problem

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

Pid,

On 10/28/2010 5:36 PM, Pid wrote:
> I would suggest that you created a class which periodically updated all
> the values by selecting the data in the DB and storing the result in the
> Context.
> 
> Implementing a ServletContextListener will give you access to the
> ServletContext and two methods, for app startup & shutdown, which you
> can use to start the periodic process, and properly stop it (very
> important).
> 
> You may consider using a Timer, or something from the
> java.util.concurrent package.

I would be even lazier (pun intended): record the last-accessed-time of
the data in the Context as well, and perform a re-fetch whenever that
time is too old (or missing entirely). That avoids the headache of
managing another thread on the server (how many questions do we get
about still-running threads on app shutdown?) and does not refresh the
values from the database unless they are actually requested by code (and
therefore doesn't do speculative fetches that might not be required at all).

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzO1hcACgkQ9CaO5/Lv0PBuKQCePhvYb/rpMHOdUbNRdnJXu6Ud
aWEAn0F8AZcBVBw7KtKkwtGzluualYS6
=ur/V
-----END PGP SIGNATURE-----

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


Re: RV: Session & Context variables architecture problem

Posted by Pid <pi...@pidster.com>.
On 28/10/2010 18:31, falvarez@geocom.com.uy wrote:
> Dear All,
>                 I'm currently using Tomcat 6.0.28 and having some doubt on
> how to solve and implement this problem:
>                                My webapp has a MySQL Database with a table
> named "parameters", in which we have just two columns ("property" and
> "value"). This table is acceded many times but doesn't change often.
> 
>                                For performance purposes I want to save this
> parameters in the user's tomcat session, so they are read from memory and
> not database. So far so good.

Do you actually know that this is a performance problem, or are you
guessing that it is?

>                                Now the problem: how can I tell this sessions
> that an attribute has changed?

Using the session will mean that you have duplicate copies of this
information in each session.

>                 I had suggestions of using "context variables" instead of
> "session variables", but that didn't solve the problem.

*If* you need to do this, using the Context is probably better.

I would suggest that you created a class which periodically updated all
the values by selecting the data in the DB and storing the result in the
Context.

Implementing a ServletContextListener will give you access to the
ServletContext and two methods, for app startup & shutdown, which you
can use to start the periodic process, and properly stop it (very
important).

You may consider using a Timer, or something from the
java.util.concurrent package.


p

> Any help in this matter is more than welcome. I have no problem in changing
> the approach, and may be not use sessions at all.
> 
> Thanks in advance.
> 
> Best regards,
> 
>                 Federico Alvarez.
> 
> Info:
> 
>                 Tomcat 6.0.28
>                 Java 1.6
>                 MySQL 5.5
> 
>                 NOT USING HIBERNATE, so 2nd Level cache is not an option