Forum Moderators: phranque

Message Too Old, No Replies

Website/database performance question.

Better to go back to the DB each time or use an array?

         

HughMungus

1:50 am on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My website is very hierarchical, e.g., Category1, Subcategory1, Subcategory2. Every time someone clicks on a top category selection, the page has to look and create an array of all the rows that match that category. Right now, when someone clicks on a subcategory, I'm having the page go back to the DB to get the subcategory info. Assuming that the performance of the database itself is not an issue, would the page be faster by going back to the DB each time or storing that large chunk of data in an array and then manipulating the original array to get the subcategory info?

TIA

m_shroom

4:35 am on Jun 14, 2004 (gmt 0)

10+ Year Member



Assuming you are useing PHP to access your db and I read your post corectly.

No. A click means a whole new page is writen from scrach useing the link and varibles pasted by the click (all varibles must be recreated).

Yes. Accessing db = accessing hard drive. Use your ram and keep disk access to a minumum.

HughMungus

5:02 am on Jun 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah. Cool. Hadn't thought of it as memory vs. hard drive. Thanks!

ExpLarry

7:05 am on Jun 14, 2004 (gmt 0)

10+ Year Member



Accessing db = accessing hard drive.

Often frequently accessed pages will be cached in RAM either by the DB or the underlying OS, so DB reads do not necessarily entail drive seeks.

On my busiest site I made sure the server has more than enough RAM to keep the DB in memory - cost a wee bit more but the performance gains were worth it.

Note that writes to the DB will access the drive almost immediately; if you can, postpone any writes until the page has been delivered to the client.

The precise details will depend on your setup.