homepage Welcome to WebmasterWorld Guest from 54.197.183.230
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Which is faster?
Accessing 3 files Vs 1 SQL query
smagdy

10+ Year Member



 
Msg#: 3342863 posted 10:37 am on May 18, 2007 (gmt 0)

Hello,

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

 

ahmedtheking

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3342863 posted 12:54 pm on May 18, 2007 (gmt 0)

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.

davidpbrown

10+ Year Member



 
Msg#: 3342863 posted 1:10 pm on May 18, 2007 (gmt 0)

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

jatar_k

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



 
Msg#: 3342863 posted 2:01 pm on May 18, 2007 (gmt 0)

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.

trillianjedi

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



 
Msg#: 3342863 posted 2:18 pm on May 18, 2007 (gmt 0)

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.

nobody

10+ Year Member



 
Msg#: 3342863 posted 3:30 pm on May 18, 2007 (gmt 0)

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.

smagdy

10+ Year Member



 
Msg#: 3342863 posted 10:27 am on May 19, 2007 (gmt 0)

Hello,

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...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved