<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
I've been thinking more on this issue and I've decided to implement a
database-backed SessionStore, specifically using MySQL memory (or heap)
tables. So the obvious first question is somewhat a repeat of David's -
Has anyone built a SessionDatabaseStore before?<br>
<br>
I did some more reading up on memcached and was scared off using it as
a session store. No data is replicated, only hashed and stored to a
particular server, which means that portion of the cache is lost when
that server dies. You can wrap your own replication around memcached,
to store the data twice with two different keys guaranteed to hash to
different servers, but at that point I started looking at the built-in
replication of MySQL instead. I need active sessions to remain
available when web/app servers or db servers die.<br>
<br>
I like memcached for it's intended purpose though. Currently I'm using
a home-rolled in-process caching scheme for frequently accessed db
objects (i.e. singleton classes with dictionaries keyed by primary key
of the db table). My intention when moving to the clustered environment
was to use some kind of RPC between the appservers to delete an object
from the cache when it is saved to the db. Then each appserver machine
lazily updates as needed. This means each appserver potentially has the
full cache, as opposed to memcached which spreads the cache over
multiple servers. If the total object cache is small enough to fit in
the usable memory of each appserver machine, then the per-machine cache
will obviously always be faster (assuming the app has more cache hits
than db writes!). But once the object cache grows beyond that single
server limit, memcached looks pretty sweet, and the python API looks
quite straightforward.<br>
<br>
Regarding the "hard to find bugs" when using SessionFileStore, they are
probably related to multiple threads accessing and saving the session,
with one clobbering the other. This can happen if thread A grabs
session 1, then thread B grabs session 1, then thread A saves session
1, then thread B saves session 1 (overwriting thread A's save). This
can never happen with SessionMemoryStore because it doesn't pickle the
session objects - they are kept in memory in a dictionary - meaning
that thread B "sees" thread A's changes as soon as they occur, because
both threads point to the same object.<br>
<br>
A SessionStore backed by a database or memcached would exhibit the same
functionality as the SessionFileStore. It's another concern I have to
investigate with when migrating to a cluster...<br>
<br>
If others have input/experience with clustered appservers, or
alternative session store algorithms, please speak out!<br>
<br>
Peace - Ben<br>
<br>
<br>
Hancock, David (DHANCOCK) wrote:
<blockquote
cite="mid9F2ABF88F1AD85459BC13BE147EAFFD414805312@..."
type="cite">
<title>Message</title>
<meta http-equiv="Content-Type" content="text/html; ">
<meta content="MSHTML 6.00.2800.1522" name="GENERATOR">
<div><span class="339240923-25102005"><font color="#0000ff"
face="Arial" size="2">We aren't clustered (currently), but soon I want
to run the ThreadedAppServer on multiple machines again. We backed away
from this a while ago for other reasons, but at the time we used the
session FileStore with an NFS-mounted directory. We tried sticky
sessions in our load-balancer (Cisco LocalDirector) but we never got
them to work reliably.</font></span></div>
<div><span class="339240923-25102005"></span> </div>
<div><span class="339240923-25102005"><font color="#0000ff"
face="Arial" size="2">Our applications (WebKit included) are already
quite database-intensive, so I'd rather try something like memcached
before doing an additional update on each page switch. The memcached
daemons in a few places on the network seems ideal, and my
(simple-minded) benchmarks comparing Oracle retrievals vs memcached
retrievals shows them to be 10-12 times faster.</font></span></div>
<div><span class="339240923-25102005"></span> </div>
<div><span class="339240923-25102005"><font color="#0000ff"
face="Arial" size="2">Before implementing our earlier load-balanced
configuration, we benchmarked the difference between FileStore and
MemoryStore. It was only about a 15% penalty for the FileStore. That
testing was with a local filesystem, not NFS. FileStore can introduce
some hard-to-find bugs when two windows of the same session attempt to
update the session file at the same time.</font></span></div>
<div><span class="339240923-25102005"></span> </div>
<div><span class="339240923-25102005"><font color="#0000ff"
face="Arial" size="2">I haven't got any numbers comparing MemoryStore
(or DynamicStore) with memcached storage, but I would expect
MemoryStore to perform a few percent better (data is already in the
process, no need for possible network traffic).</font></span></div>
<div><span class="339240923-25102005"></span> </div>
<div><span class="339240923-25102005"><font color="#0000ff"
face="Arial" size="2">I'm still hoping to hear of an existing
implementation, though...</font></span></div>
<!-- Converted from text/rtf format -->
<p><span lang="en-us"><b><font face="Arial" size="2">Cheers!</font></b></span>
<br>
<span lang="en-us"><b><font face="Arial" size="2">--</font></b></span>
<br>
<span lang="en-us"><font face="Arial" size="2">David Hancock |
<a class="moz-txt-link-abbreviated" href="mailto:dhancock@...> | 410-266-4384</font> </span></p>
<div class="OutlookMessageHeader" dir="ltr" align="left" lang="en-us"><font
face="Tahoma" size="2">-----Original Message-----<br>
<b>From:</b> Ben Parker [<a class="moz-txt-link-freetext" href="mailto:ben@...>] <br>
<b>Sent:</b> Tuesday, October 25, 2005 6:22 PM<br>
<b>To:</b> Hancock, David (DHANCOCK)<br>
<b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:webware-discuss@...>
<b>Subject:</b> Re: [Webware-discuss] Anybody made a memcached
SessionStore?<br>
<br>
</font></div>
Hancock, David (DHANCOCK) wrote:
<blockquote
cite="mid9F2ABF88F1AD85459BC13BE147EAFFD41480530B@..."
type="cite">
<meta content="MS Exchange Server version 6.5.7226.0"
name="Generator">
<!-- Converted from text/rtf format -->
<p><font face="Arial" size="2">We're thinking about creating a
memcached SessionStore backend, but (being quite lazy and not as smart
as most other people) I'd much rather copy or adapt somebody else's
code. Has anyone done this already? Any advice before I start in on
this project?</font></p>
</blockquote>
<br>
Interesting - are you looking to use this in a clustered environment?
I wonder if memcached would give any performance benefit over
SessionMemoryStore for a single server.<br>
<br>
Fairly soon, I will have to implement clustered app server machines for
load-balancing and failover, and I'm looking at using a database
session store to achieve session management across multiple machines
without requiring sticky sessions. although I'm still just beginning to
get the test environment together.<br>
<br>
peace!<br>
Ben<br>
</blockquote>
<br>
</body>
</html>
|