Skip to main content
May 6, 2010
Question

Saving session state to a remote DB...

  • May 6, 2010
  • 4 replies
  • 2928 views

I am currently implementing a clustered CF Environment and would like to explore the possibility of saving session state to a remote database.

I've googled  the topic just a bit but haven't found anything that goes into too much detail so i figured id try the forums.

Does anyone have any experience with this and if so is there anything you feel that is worth sharing?

Perhaps someone can point me to some documentation or good articles out there on the web?

Thanks

Mike

    This topic has been closed for replies.

    4 replies

    Participant
    January 6, 2011

    Hello Mike,

    I need to work in the clustered enviornment, So the best option that i found after searching a lot in the google is to store the session in the database . But i dont find any clue how to store the session in the Database using JSP, so when i saw this question and answer then i thought it might help me to solve my problem. Hence please help me to solve my problem as i dont have much working experience in this.

    Thanks

    Rajesh

    Community Expert
    January 8, 2011

    Why do you mention JSP here?

    You can simply use Client variables in CF. This can scale pretty well, although to do so you need to disable the global client variable update option.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    BKBK
    Community Expert
    Community Expert
    January 9, 2011

    Dave Watts wrote:

    Why do you mention JSP here?

    You can simply use Client variables in CF. This can scale pretty well, although to do so you need to disable the global client variable update option.

    Yes, Dave, naturally. I suggested client variables already. I do believe that that is the only viable option if you wish to store session data in the database.

    However, Ke4pym-ZwXpUa dismissed that, and the original poster, MikeG518, went with him. In my opinion, Ke4pym-ZwXpUa's experience that client variables don't scale is most probably due to poor implementation, not to the use of client variables.

    I should repeat here that storing sessions in the database is very poor design. It just wont scale. It is not for nothing that Coldfusion stores sessions in memory.

    July 12, 2010

    We did that for a time here.  But it got to the point where the database simply couldn't keep up (even on high powered hardware) with the load and we ended up doing away with it.

    It is nice in theory.  But if you've got a high load environment, it is very difficult to keep going.

    July 13, 2010

    Ke4pvm,

    Thanks for your input. 

    I was able to successfully save session state from 3 clustered JRUN instances to a remote DB.  When shutting down one of the instances the user is bounced to anothewr available instance where the users prior session is served up to them.

    So far i've only implemented this on a small scale and have run into intermittent problems here and there.

    I havent been able to test this architecture under heavy load just yet and i would be curious to know some possible glitches to look out for .

    If we do end up implementing this in a production environment, it will be getting hit pretty hard.

    Any input you could share would be greatly appreciated.

    Thanks

    Mike

    BKBK
    Community Expert
    Community Expert
    May 30, 2010

    Saving session state to a remote DB...

    MikeG518 wrote:

    I am currently implementing a clustered CF Environment and would like to explore the possibility of saving session state to a remote database.

    I've googled  the topic just a bit but haven't found anything that goes into too much detail so i figured id try the forums.

    Does anyone have any experience with this and if so is there anything you feel that is worth sharing?

    Perhaps someone can point me to some documentation or good articles out there on the web?

    Client variables were invented as a means of saving the session state of a clustered environment to a database.

    Inspiring
    May 9, 2010

    Why, specifically are you wanting to write sessions to the DB?  It's difficult to answer the question on the basis of your description, as you don't really articulate a specific requirement for you to be doing this.

    To answer your question in a brute force sort of way, a session comprises a struct of variables (the session scope) and one or two cookie values (jsessionid or cfid & cftoken).  So one could serialise the struct to WDDX or JSON, and bung it and those cookie values (which you'll need to identify which row to pull back out again) into your DB table.

    Or you could look at using client variables instead, which can be configured to be written to DB from the outset.

    --

    Adam

    May 19, 2010

    When i mentioned a CF Clustered env maybe i should have specified multiple instances on CF clustered together and  running under one Jrun4 installation.

    The intent is to achieve high availability.

    I hope i didnt force you to exert too much energy while trying to answer my question in such a brutal fasion (haha just kidding).

    Regardless, i did get this sucfcessfully implemented and working quite nicely.I would be glad to asssist anyone facing the same dillema.

    Thanks

    Participant
    September 25, 2010

    I am indeed very curious as to how you implemented this. My situation is slightly different, where I would like to share the session (and application) scope data between disparate applications, one running coldfusion and another ruby on rails. This is to facilitate migration to rails. A user on the site, through apache rewrite rules, could have a request to example.com/urla handled by coldfusion and example.com/urlb handled by rails ... they wouldn't know or care what handles the request on the backend.

    Also, people were mentioning heavy load doing this on a database server, but with caching systems like memcached, or (supposedly) highspeed nosql document stores like redis, mongo, whatever I would think the system could scale out quite well.