Speed VS Overhead

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Speed VS Overhead

Post by Zoram »

In a recent conversation this was said:
hawleyjr wrote:You'll find that you will have much more overhead if you store the data in files. Use a db, much easier.
I was curious. Which would be faster, querying a text datatype from the db to display to the screen or including a text file?

For a few hundred pages at most would it cause that much overhead to store static versions of the content?

Or would it still be better to use the db and query it every time?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Databases are made to store data. What is going to happen in 2 months when you decide you need a search feature for all of those static files?

Also, this would be a pretty easy benchmark test to do :)
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

Well, as far as searching goes i can still use the db to do the searching since the actual data is still stored in the db. Then I can link the results to the page that will bring up the correct section.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What about updates? do you really want to have double entry? Also, you are quering the db regardless. Why do both?
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

Actually... The query is done in the menu. Then the $_GET variable is used to see if the file exists and includes it. So it does that without a query. As far as double entry it doesn't seem that bad to write to a file at the same time that i write to the db on edits.

EDIT | I've done some testing and it seems to be about .032 seconds faster to include the file on a moderate size section. [.229 - .197]
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post by Gambler »

I did a synthetic test once. Including empty file is about 2 times slower than issuing empty query. Which means DB isn't that much faster. And it can choke under heavy load.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

hawleyjr wrote:Databases are made to store data. What is going to happen in 2 months when you decide you need a search feature for all of those static files?

Also, this would be a pretty easy benchmark test to do :)
Actually they are made to make SPECIFIC elements of stored data easier to access. :) If you only need a couple of items out of the data it is easier and usually faster to pull those two elements out of a database than out of a file.

If you always need all of the elements it is easier and faster to use a file instead of a database.

An example is the game I work on. On previous versions 300 variables were stored in a database table and loaded from the database with every page load. We changed to loading those 300 variables from a file instead of the database. Loading those 300+ variables from the database was many, MANY times slower and many times more CPU intensive.

So it all depends upon what you are going to do. Sometimes using a database is the slowest and most memory/CPU intensive option you can use.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

hawleyjr wrote:You'll find that you will have much more overhead if you store the data in files. Use a db, much easier.

Thread where Hawleyjr made this quote.
I think Hawleyjr has been quoted out of context.
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

It's not exactly what hawleyjr was refering to, it's just what got me thinking about the diffence in using a txt file to store a section of text that is of moderate size compared with selecting it out of a database every time.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Zoram wrote:It's not exactly what hawleyjr was refering to, it's just what got me thinking about the diffence in using a txt file to store a section of text that is of moderate size compared with selecting it out of a database every time.
Ahh ... well to quote Rasmus Lerdorf, "Cache! Cache! Cache!"
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Zoram wrote:It's not exactly what hawleyjr was refering to, it's just what got me thinking about the diffence in using a txt file to store a section of text that is of moderate size compared with selecting it out of a database every time.
I'll reiterate Buddha443556's comment. Its all about the cache.

If your db has a solid cache setting, and you are indeed selecting specific data (not whole pages), then the database will often be at an advantage. On the other hand, if you are selecting whole pages of data, and perhaps you dont control the db cache settings, then flat-files will likely be a win.

Like with any discussion about performance, test! Your specific situation will likely vary from anyone else's experience, so instead of guessing, find out. :)
Post Reply