Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Way of accessing data...

by kiat (Vicar)
on Apr 12, 2004 at 14:02 UTC ( #344387=perlquestion: print w/ replies, xml ) Need Help??
kiat has asked for the wisdom of the Perl Monks concerning the following question:

Hi all

I want to display the total number of membership on the main web page. I'm divided between the following two ways of doing it

1) Since that information is available in the database, just query the database and get the number.

2) As and when the database is updated with a new member, write that information to a flatfile to be included as in include file within the relevant html page.

Which of the above methods would you most likely use and why.

Not quite directly related to perl but still I look forward to reading your views.

As usual, thanks in anticipation :)

Comment on Way of accessing data...
Re: Way of accessing data...
by jeffa (Chancellor) on Apr 12, 2004 at 14:07 UTC

    If you already have the infomation in the database, then definitely query it for the number. Why?

    SELECT count(*) FROM user
    This question is a perfect candidate for the ChatterBox, which i invite to please consider asking your question there first.

    UPDATE: says kiat "the hosting company sets a limit on the number of queries by the hour". So why didn't you specify that in your original question? That's very very important stuff that you should have said up front. Now the answer changes, naturally, to #2.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Thanks jeffa :)

      I'm partly concerned because the hosting company sets a limit on the number of queries by the hour for the particular package I'm purchasing. Hence, I'm wondering whether that sort of statistics can be saved into a textfile...

        Or to get the best of both worlds, have a cron set up to query the database every x minutes and dump the count to a flat file, you don't get artificially high numbers (in the case that you delete inactive users), and you don't get hit with excess queries.


        -Waswas
Re: Way of accessing data...
by arden (Curate) on Apr 12, 2004 at 14:08 UTC
    kiat, this is a question of trade offs. You have to answer two questions first, 1) how often does the "total number of membership" change and 2) how often does the "main web page" get accessed? Then consider the amount of CPU time it takes process the query to dynamically create the webpage versus the CPU time to serve up a static page along with the time it would take to update the static page.

    Now that you have those numbers, figure out which one will take less overall CPU. I'm going to wager that unless your membership is a very fluid thing, it'll be cheaper to keep a static page and update it either from the account creation/deletion script or daily from a cronjob.

    - - arden.

      Thanks arden! I like your point about tradeoffs. I didn't think of it that way - I was just wondering if one method is prefered over the other in a noraml setting. But now I've something more specific to weigh my options on.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://344387]
Approved by blue_cowdawg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-08-27 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (236 votes), past polls