Storage Plan: Map v/s linear
Brian Beuning
BBeuning at corecard.com
Mon Nov 12 21:22:36 UTC 2007
I suggest worrying about your DB schema first.
Do you want person^2 entries in your DB?
Once you settle on your DB schema, then just mirror it in memcached.
Are connections reflexive? If A is a friend of B, does that imply B is a
friend of A?
I think any DBA would like option 2 better.
Brian Beuning
SHARED
create table People (
personID int,
name varchar(50),
-- more personal info columns
primary key (personID)
)
OPTION 1
create table Relations (
Aid int,
data blob, -- contains HashMap table
primary key (Aid)
)
OPTION 2
create table Relations (
Aid int,
Bid int,
type int,
primary key (Aid, Bid)
)
-----Original Message-----
From: Rakesh Rajan [mailto:rakeshxp at gmail.com]
Sent: Saturday, November 10, 2007 7:14 AM
To: memcached at lists.danga.com
Subject: Storage Plan: Map v/s linear
Hi Folks,
I am trying to use memcached to store the relationships between persons ( So
person A -> Relationship Type -> Person B ) ( Java based solution )
So given a person, I would need
1) To see if another person is a connection
2) And the connection type.
As I see it, I could implement this in 2 ways
OPTION 1
For each user store a HashMap of personID,relationshipType.
e.g
Map<Integer,Integer> relationMap = new
HashMap<Integer,Integer>();
relationMap.put(1,1); .......
memcache.put( "prefix" + sourcePersonID , relationMap);
In this case, there would be as many keys in memcached, as there are
persons.
OPTION 2
Use both person IDs in the memcahe key.
e.g
memcache.put( "prefix" + sourcePersonID + ":"+ targetPersonID ,
relationType);
In this case, there would be at max persons^2 keys in memcahed.
Assumptions
1) Each person would have an average of 200-300 friends
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 )
I would like to know which of option is better for my requirement ?
Thanks,
Rakesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20071112/ad200c3c/attachment-0001.html
More information about the memcached
mailing list