Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Which is faster?

Accessing 3 files Vs 1 SQL query



10:37 am on May 18, 2007 (gmt 0)

10+ Year Member


I am accessing 3 cached files to display a page (3parts of the page), so would this be faster than displaying normal page and applying i Select Query with LIMIT 1?

Thanks in advance


12:54 pm on May 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Query. Think about it: you're having to open, read and then close three files. As oppose to connecting to DB, running query and closing link once.


1:10 pm on May 18, 2007 (gmt 0)

10+ Year Member

I'd have naively put money on hard disk being much faster than a database lookup..


2:01 pm on May 18, 2007 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

test it and see

the thing is there are a lot of variables that affect the scenario so there really isn't a definitive answer.

I think it would be close but I think the filesystem would be quicker as long as you are not searching through the files. As soon as you have to search I think the db would be faster.


2:18 pm on May 18, 2007 (gmt 0)

WebmasterWorld Senior Member trillianjedi is a WebmasterWorld Top Contributor of All Time 10+ Year Member

As jatar_k says, measure it and find out.

Depending on your site structure and server resources you might also want to consider using the filesystem but out of a RAM disk rather than the hard disk.


3:30 pm on May 18, 2007 (gmt 0)

10+ Year Member

Yes - would depend heavily on your setup.

Is the database running on the local machine? How much memory does it have? Is it a query which gets run often?

If the database is local (or on a machine close to the webserver), not heavily loaded, and it's a query or table which has been accessed before, then you stand a good chance of the information you're after already being in memory, which will make the access very quick.

Reading files off disk will always be slower than reading information out of memory.


10:27 am on May 19, 2007 (gmt 0)

10+ Year Member


Thanks a lot for everybody who shared these informations with us...

I did tested it now and the result was good for the Cache!

i reloded the page 20 times with cache and 20 times with SQL so here is the average microseconds:

0.0044372 with Cache (it once went up to 0.006196)

0.0052821 with SQL (it once went up to 0.012971)

But there are few things i am thinking of since the site is not heavy loaded yet, i am planning to advertise in radio next month so i should be ready for the traffic!

I ve VPS with RAM 512

So the thing is, what will happen when the cache folder gets like few thousands of files? will it get slower to find the file needed to display? (I know i can empty it whenever with a cron)

And what if it got slower, will it be slower than SQL when the database get also hundered thousands more records?

So, i dono, i just think that the result can change when the site gets bigger!

When it gets bigger, then i am planning to move to dedicated server and hopefully harddisk 10k or 15k... but i have never experienced with any fast harddisk...

Does they really boost up things? hope u share any info about this!

Thanks for you all...


Featured Threads

Hot Threads This Week

Hot Threads This Month