Debating Using Sessions To Save DB Load...Thoughts?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
jbh
Forum Commoner
Posts: 89
Joined: Tue Dec 05, 2006 7:01 pm

Debating Using Sessions To Save DB Load...Thoughts?

Post by jbh »

Hey,

I am building a website that will likely host 10,000+ users with screen names who will be logged in and use
the site often. One key function is using Geo IP where I can pull their city/state and that data comes in handy
every time they answer a poll question or view results. Long story short, I was thinking that instead of using the DB
to pull that data every so often for a user, I should simply load those values into a session when they log in.

This way, if 10,20,50K++ users ever are at the site at once it's not hitting the DB each time I need to filter poll results
based on their city or state. By using a session which pulls these values only once during log-in, I am not needlessly
hitting the db over and over agian.

Thoughts?

Thank you for your time.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Debating Using Sessions To Save DB Load...Thoughts?

Post by Christopher »

You can certainly do that. But if you go to a distributed architecture, you will end up with database based sessions and be back to the same problem. Perhaps putting these values in a cookie would be a good solution.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Debating Using Sessions To Save DB Load...Thoughts?

Post by josh »

How about abstracting "finder" / "locator" services for each domain entity, later on you can "jimmy" in a cache layer if it is deemed necessary.
User avatar
PHPHorizons
Forum Contributor
Posts: 175
Joined: Mon Sep 14, 2009 11:38 pm

Re: Debating Using Sessions To Save DB Load...Thoughts?

Post by PHPHorizons »

Hello jbh, the only thing I'd add is that, if you are already starting sessions for your users, then there is still a savings by storing that data in a session instead of querying on each page load.

The session data is queried anyways, so by not querying this geo ip data on each page load, you are saving a lot of queries, even with db sessions.
Selkirk
Forum Commoner
Posts: 41
Joined: Sat Aug 23, 2003 10:55 am
Location: Michigan

Re: Debating Using Sessions To Save DB Load...Thoughts?

Post by Selkirk »

I haven't found the Geo-IP extension to be particularly slow. I may be reading it on every request in one application. Now I'm gonna have to check.

10K simultaneous users? You sure you'll have that many?

I'd way until the performance is measurably a problem before trying to fix it.
Post Reply