Memcached-backed SessionProvider for session state
I believe memcached works where the server(s) maintain a key value store which the client populates. When a client wishes to retrieve a value it computes a hash of the key to determine the server it will use. In the example of storing session state where the client puts the value of KEY1 in SERVER1 and for some reason SERVER1 becomes unavailable, what happens when the client goes to retrieve KEY1? Is it correct to say the data is not available on another server? If this is the case what benefits do you get from using AppHarbor addon memcacher over using a Session State server?
Support Staff 2 Posted by friism on 21 Feb, 2012 08:38 PM
Hi Noel
When sessions are stored in process (the default), the session cannot be shared between instances. This is a problem since a user may login and have a session set on one instance that another instance serving a subsequent request to that user will not know about.
By storing sessions in Memcacher (whose servers are run separately from the AppHarbor application servers), sessions for a given application are stored in one central location shared by all instances. A user can thus be logged in on one AppHarbor instance and that session is accessible (via the central memcached session store) to other instances serving requests for that application.
Note that Session State Servers (that is non-in-process session state) is not available on AppHarbor and we recommend using Memcached.
Let us know if you have other questions.
Michael
3 Posted by Noel Mc grath on 21 Feb, 2012 09:42 PM
Michael,
Thanks for the reply.
I understand that sessions are stored seperatly, using memcacher, on different servers to where an application is deployed.
My question is if the server where the session is stored using memcacher goes down and my application tries to retrieve that session what happens?
Am I correct in saying that the key-value collection stored in memcacher Server1 is not duplicated (distributed) across to memcacher Server2 so therefore if Server1 goes down the key-value cannot be retrieved
Support Staff 4 Posted by friism on 27 Feb, 2012 05:37 PM
Hi Noel
You are correct that the memcacher servers are currently not replicated. What happens if a memcacher server is unavailable would depend on the provider implementaion, and I haven't checked the details. Your users would loose their sessions though, and would have to log back in to your site.
Note that the memcacher servers have excellent uptime. Barring some initial teething trouble, we have not had any issues keeping them up.
Let us know if you have other questions.
Michael