tags:

views:

199

answers:

2

OK I have a social network, around 50,000 users so far and there is a friend table that show who is your friend on the site, this table is over a million rows

Not the tricky part, I show user posted bulletin, status posts, stuff like that that is only visible to people on your friend list. Keep in mind the size of the tables, user table around 50,000 so far and friend table around 1 million

1 method of getting the friends list to know what status posts to show to a user is to run this query below and put the results into an array

select friendid from friend_friend where userid=1 and status=1

I would then turn this array into a comma seperated list and use it in an IN clause on the mysql query that fetches the posts that this user is allowed to view

Hope that makes sense so far.

Now what if I were to save this friend array to a session variable since this query is ran very frequently? One of the drawbacks I see is if a user adds that person as a friend while they are logged in, they would show up as there friend until that session was reset but other then that, would this be bad performance for memory or whatever sessions use?

Also note there is sometimes up to 500 users logged in and some have a friend list of 10,000 friend ID's and this is a PHP/MySQL setup

Another question about session data, it is stored in file and not sytem memory correct? If it is on disk instead of memory then memory shouldn't be to much of a problem?

+2  A: 

have you looked into memcached? This article ( http://highscalability.com/memcached-and-storage-friend-list ) , and it's comment, highlight the pros and cons of your way versus offloading to memcache.

easement
Thanks I will check that out
jasondavis
+1  A: 

maybe you would want to respond to this problem dynamically.

if, let's say, a user has more than X friends, don't cache it. think of what could happen when a user has a lot of friends and you need to push the entire data through the connection... i think the user recognizes this as bigger performance reduction than the one when you need to query the list each time.

this is my opinion based on my experience with php/mysql... maybe there's a reason for doing what you proposed anyway^

regards

Atmocreations
Actually that is a great idea and i'm sure whatever route I go this will come into play somewhere with it
jasondavis