<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>
<BODY>
<DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>I
suggest worrying about your DB schema first.</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>Do you
want person^2 entries<SPAN class=323121321-12112007> in your
DB</SPAN>?</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>Once
you settle on your DB schema, then just mirror it in
memcached.</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>Are connections reflexive? If A is a
friend of B, does that imply B is a</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>friend of A?</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>I think any DBA would like option 2
better.</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>Brian
Beuning</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>SHARED</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2> </DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>create table
People (</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial><FONT color=#0000ff size=2> personID
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial><FONT color=#0000ff size=2> name
varchar(50),</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN
class=323121321-12112007> -- more personal info
columns</SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2> primary key
(personID)</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff
size=2>)</FONT></SPAN></SPAN></DIV></FONT></SPAN></SPAN>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>OPTION 1
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN><SPAN
class=120271121-12112007><SPAN class=323121321-12112007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>create table Relations
(</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial><FONT color=#0000ff size=2> Aid
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2> data
blob, -- contains HashMap table</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN
class=323121321-12112007></SPAN></SPAN><SPAN class=120271121-12112007><SPAN
class=323121321-12112007><FONT face=Arial><FONT color=#0000ff
size=2> primary key (Aid)</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>)</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN
class=323121321-12112007></SPAN></SPAN> </DIV></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>OPTION 2</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN><SPAN
class=120271121-12112007><SPAN class=323121321-12112007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>create table Relations
(</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial><FONT color=#0000ff size=2> Aid
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2> Bid
int,</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial><FONT color=#0000ff size=2> type
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial><FONT color=#0000ff size=2> primary key (Aid,
Bid)</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT
face=Arial color=#0000ff size=2>)</FONT></SPAN></SPAN></DIV></SPAN></DIV>
<BLOCKQUOTE>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Rakesh Rajan
[mailto:rakeshxp@gmail.com]<BR><B>Sent:</B> Saturday, November 10, 2007 7:14
AM<BR><B>To:</B> memcached@lists.danga.com<BR><B>Subject:</B> Storage Plan:
Map v/s linear<BR><BR></FONT></DIV>Hi Folks,<BR><BR>I am trying to use
memcached to store the relationships between persons ( So person A ->
Relationship Type -> Person B ) ( Java based solution )<BR><BR>So
given a person, I would need <BR>1) To see if another person is a connection
<BR>2) And the connection type.<BR><BR>As I see it, I could implement this in
2 ways<BR><BR><B>OPTION 1</B><BR><BR>For each user store a HashMap of
personID,relationshipType.
<BR>e.g<BR>
Map<Integer,Integer> relationMap = new HashMap<Integer,Integer>();
<BR>
relationMap.put(1,1);
.......<BR><BR>
memcache.put( "prefix" + sourcePersonID , relationMap);<BR><BR>In this
case, there would be as many keys in memcached, as there are
persons.<BR><BR><BR><B>OPTION 2</B><BR> <BR> Use both
person IDs in the memcahe key.<BR>
e.g<BR> memcache.put( "prefix" +
sourcePersonID + ":"+ targetPersonID , relationType);<BR><BR>In this
case, there would be at max persons^2 keys in memcahed.
<BR><BR><BR><B>Assumptions</B><BR>1) Each person would have an average of
200-300 friends<BR>2) Memcahed would be on a different set of servers compared
to the webapps ( So there would be a N/W delay in passing the data from
memcached -> webapp ) <BR><BR>I would like to know which of option is
better for my requirement ?
<BR><BR>Thanks,<BR>Rakesh<BR></BLOCKQUOTE></BODY></HTML>