Page 1 of 1
Speed VS Overhead
Posted: Sun Jan 22, 2006 11:33 am
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?
Posted: Sun Jan 22, 2006 12:15 pm
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

Posted: Sun Jan 22, 2006 12:26 pm
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.
Posted: Sun Jan 22, 2006 12:28 pm
by hawleyjr
What about updates? do you really want to have double entry? Also, you are quering the db regardless. Why do both?
Posted: Sun Jan 22, 2006 12:40 pm
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]
Posted: Sun Jan 22, 2006 1:01 pm
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.
Posted: Sun Jan 22, 2006 1:30 pm
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.
Posted: Sun Jan 22, 2006 1:51 pm
by Buddha443556
I think Hawleyjr has been quoted out of context.
Posted: Sun Jan 22, 2006 1:57 pm
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.
Posted: Sun Jan 22, 2006 2:04 pm
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!"
Posted: Sun Jan 22, 2006 2:36 pm
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.
