Re: Forum efficiency
From: Manuel Lemos (mlemos_at_acm.org)
Date: 02/17/04
- Next message: Pedro Graca: "Re: exec() gives only 127 back"
- Previous message: David Rybach: "Re: Algorithm for creating a tree structure from a linked list"
- In reply to: Daan: "Forum efficiency"
- Next in thread: Jochen Daum: "Re: Forum efficiency"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 17 Feb 2004 16:22:53 -0300
Hello,
On 02/17/2004 09:28 AM, Daan wrote:
> I have attempted to write my own forum using PHP and MySQL. It works,
> but the efficiency is far from ideal. It takes a long time to load e.g.
> the list with threads in a certain forum.
>
> I think the problem has to do with the fact that I have several SQL
> calls in nested loops, so if a large thread list has to be loaded, there
> are a lot of SQL queries to be executed. I have posted the code that
> initialises the forum below, so you can see what I mean.
>
> My question: is there a more efficient way to initialise my forum or is
> it better to begin from scratch?
Sure. Note down this thought:
- The way to write fast database applications is to avoid accessing
database as much as possible.
What I mean is that usually database accesses are the slowest factor in
database driven sites. So, you need to only access databases for the
essential.
In most content sites, including forums, you have much more database
accesses for retrieving data than to change that data.
So, what you can do to minimize the database reading accesses is to
cache the pages that you generate from reading the database data in
local disk files.
Then, whenever the data is changed, just removed the cached page files
to force that it is regenerated next time it is needed for display.
In this case, you may want to try this class that is meant to cache
generic data. You can use it to cache whole pages or just excerpts of
each page.
In your case, whenever somebody accesses a page that display a forum
thread, just use the cache class to verify whether the cache class
exists and is still valid.
If it does not exist, just regenerate it and pass its HTML (or just the
forum thread listing excerpt) to the class so it can store it safely
even when you have a busy site with many simultaneous accesses.
If the cache file exists and is upto date, just ask the class to
retrieve the HTML data from the cache files and display it.
Whenever a user updates the thread, just call the function of the class
that voids the cache data file, to force the thread listing page caches
to be regenerated from database next time these pages are accessed.
The speedup can be huge. So you have an idea, this technique is so
efficient that the site where this class is hosted is now holding more
than 6000 cached excerpts of pages.
http://www.phpclasses.org/filecache
-- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html
- Next message: Pedro Graca: "Re: exec() gives only 127 back"
- Previous message: David Rybach: "Re: Algorithm for creating a tree structure from a linked list"
- In reply to: Daan: "Forum efficiency"
- Next in thread: Jochen Daum: "Re: Forum efficiency"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|