Re: [PHP] Which costs more: connecting to a DB or accessing the file system?

2002-06-25 Thread Luke Welling

"Mike" wrote:
> thaks for the reply.  I conducted a simple/rough benchmark to which is
more
> expensive.
...

> On the win box, file system access was 11 times faster, while on the
freeBSD
> box, file system access was 3 times faster.  The include of the adodb
class
> is not benchmarked, as part of this test, that that adds extra overhead as
> well.
>
> I suppose that filesystem access is faster.

The answer that you got that said "it depends", while superficially not very
useful is almost certainly right.

Compared to a 'select * from table' query, reading all of a file is likely
quicker regardless of which DB or DB abstraction you use.

How about some more complex cases:

 * 'select * from table where id = 999' compared to reading in a file and
finding the correct line?

 * inserting or altering a line in the middle of an ordered file, compared
to a simple insert or alter on a DB?

 * writing data to the file while 40 other script instances are all trying
to read and write to the file at the same time and doing your own
concurrency control, compared to letting a DB engine handle the concurrency
issues for you?

Simple tasks might be easier and quicker to do from a file, in which case,
if the application is unlikely to grow or evolve, the file might be the best
way to do things.  For complex or concurrent tasks, it can be much more
efficient in terms of both programming and execution time to let the DB
handle some of the harder parts for you.

It really does depend exactly what you are trying to do with your database
or file.

Cheers,

Luke Welling
--
PHP and MySQL Web Development
by Luke Welling and Laura Thomson
http://www.amazon.com/exec/obidos/ASIN/0672317842/tangledwebdesign




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Which costs more: connecting to a DB or accessing the file system?

2002-06-21 Thread mike

George,

"George Whiffen" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> I'm not quite sure what you are trying to achieve, but if holding the
> data in a file is realistically an option i.e. your data is static,  then
> why not consider holding your final output e.g. your web page/partpage
> in the file system?

For my purposes, I am not concerned with outputing dynamic web pages (that
uses a corresponding caching system), but rather parsing data that effects
code logic.

I've noticed that it is pretty popular amongst many PHP applications to
maintain script config information in a DB.  This has it's advantages, but
the extra calls to the DB looks to be pretty resource heavy.  What I am
trying to judge is the effectiveness of such practice.

Regards,

Michael



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Which costs more: connecting to a DB or accessing the file system?

2002-06-21 Thread George Whiffen

Mike wrote:

> Erik,
>
> thaks for the reply.  I conducted a simple/rough benchmark to which is more
> expensive.  I tested on a Intel PIII (450MHz 384MB ram) box running Win Xp,
> Apache 1.3.26 and PHP 4.2.1, and mysql 3.23.49  and freeBSD of similar stats
> (1000MHz, 1G ram).  I used the adodb database abstraction layer to make my
> connections (which adds extra weigt to the db initialization and queries,
> but this is the default method I use to access databases) to a db, and then
> queried a smallish db with a "select * from table."  I then benchmarked a
> file read of a similarily sized file.
>
> Win DB results average (not including the include of the adodb class):
>  time indexex time
> %
> Start1024676092.32095600-0.00%
> init db  1024676092.342583000.021627   75.19%
> query   1024676092.349426000.006843   23.79%
> close1024676092.349631000.000205   0.71%
> Stop1024676092.349719000.880.31%
> total -   0.028763
> 100.00%
>
> Win Filesystem results average:
>  time indexex time
> %
> Start 1024676092.35610400-0.00%
> file open1024676092.35685300  0.000749   28.59%
> read  1024676092.35846200  0.001609   61.41%
> close 1024676092.35863700  0.000175   6.68%
> Stop  1024676092.35872400  0.87   3.32%
> total- 0.002620
> 100.00%
>
> freeBSD DB results average (not including the include of the adodb class):
>  time indexex time
> %
> Start  1024677559.22131200   -0.00%
> init adodb  1024677559.22266700   0.001355   75.66%
> query 1024677559.22303400   0.000367   20.49%
> close  1024677559.22307900   0.45   2.51%
> Stop  1024677559.22310300   0.241.34%
> total   -  0.001791
> 100.00%
>
> freeBSD Filesystem results average:
> time index  ex time
> %
> Start 1024677559.22374400-
> 0.00%
> file open1024677559.22380700  0.63   11.23%
> read  1024677559.22423200  0.000425   75.76%
> close 1024677559.22428200  0.508.91%
> Stop  1024677559.22430500 0.234.10%
> total-0.000561
> 100.00%
>
> On the win box, file system access was 11 times faster, while on the freeBSD
> box, file system access was 3 times faster.  The include of the adodb class
> is not benchmarked, as part of this test, that that adds extra overhead as
> well.
>
> I suppose that filesystem access is faster.
>
> Michael
>
> "Erik Price" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> >
> > On Friday, June 21, 2002, at 11:19  AM, mike wrote:
> >
> > > I was reading somewhere (can't remember where) that connecting to a db
> > > is a
> > > pretty costly transaction.  DB queries aside, does anyone know of any
> > > benchmarks that demonstrate file access vs. db connections?
> > >
> > > Similarily, while DB queries offer alot of power, would it be cheaper
> > > (faster) to drop simple information that does not require heavy queries
> > > into
> > > a file and access it through the file system?
> >
> > I don't have any stats, but I think it really depends.  If you're
> > executing a really complex query that uses like six JOINs and eight
> > WHERE clauses, then the bottleneck is the DB and not the DB access
> > itself, so it would probably be quicker to have this information ready
> > in a file (or even better, cached in memory somehow, though I have no
> > experience doing this).  But I believe that with a simpler DB query, a
> > DB access is faster than a file read.
> >
> > Here's something that turned up in Google...
> > http://phplens.com/lens/php-book/optimizing-debugging-php.php
> >
> >
> > Erik
> >
> >
> >
> >
> > 
> >
> > Erik Price
> > Web Developer Temp
> > Media Lab, H.H. Brown
> > [EMAIL PROTECTED]
> >

Mike,

I'm not quite sure what you are trying to achieve, but if holding the
data in a file is realistically an option i.e. your data is static,  then
why not consider holding your final output e.g. your web page/partpage
in the file system?

If you need your php script to generate it in the first place or
regenerate it on request there are simple techniques to allow
you to do this without reassembling it on every request.

Basically you get your script to see if the

Re: [PHP] Which costs more: connecting to a DB or accessing the file system?

2002-06-21 Thread mike

Erik,

thaks for the reply.  I conducted a simple/rough benchmark to which is more
expensive.  I tested on a Intel PIII (450MHz 384MB ram) box running Win Xp,
Apache 1.3.26 and PHP 4.2.1, and mysql 3.23.49  and freeBSD of similar stats
(1000MHz, 1G ram).  I used the adodb database abstraction layer to make my
connections (which adds extra weigt to the db initialization and queries,
but this is the default method I use to access databases) to a db, and then
queried a smallish db with a "select * from table."  I then benchmarked a
file read of a similarily sized file.

Win DB results average (not including the include of the adodb class):
 time indexex time
%
Start1024676092.32095600-0.00%
init db  1024676092.342583000.021627   75.19%
query   1024676092.349426000.006843   23.79%
close1024676092.349631000.000205   0.71%
Stop1024676092.349719000.880.31%
total -   0.028763
100.00%


Win Filesystem results average:
 time indexex time
%
Start 1024676092.35610400-0.00%
file open1024676092.35685300  0.000749   28.59%
read  1024676092.35846200  0.001609   61.41%
close 1024676092.35863700  0.000175   6.68%
Stop  1024676092.35872400  0.87   3.32%
total- 0.002620
100.00%


freeBSD DB results average (not including the include of the adodb class):
 time indexex time
%
Start  1024677559.22131200   -0.00%
init adodb  1024677559.22266700   0.001355   75.66%
query 1024677559.22303400   0.000367   20.49%
close  1024677559.22307900   0.45   2.51%
Stop  1024677559.22310300   0.241.34%
total   -  0.001791
100.00%

freeBSD Filesystem results average:
time index  ex time
%
Start 1024677559.22374400-
0.00%
file open1024677559.22380700  0.63   11.23%
read  1024677559.22423200  0.000425   75.76%
close 1024677559.22428200  0.508.91%
Stop  1024677559.22430500 0.234.10%
total-0.000561
100.00%


On the win box, file system access was 11 times faster, while on the freeBSD
box, file system access was 3 times faster.  The include of the adodb class
is not benchmarked, as part of this test, that that adds extra overhead as
well.

I suppose that filesystem access is faster.

Michael


"Erik Price" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> On Friday, June 21, 2002, at 11:19  AM, mike wrote:
>
> > I was reading somewhere (can't remember where) that connecting to a db
> > is a
> > pretty costly transaction.  DB queries aside, does anyone know of any
> > benchmarks that demonstrate file access vs. db connections?
> >
> > Similarily, while DB queries offer alot of power, would it be cheaper
> > (faster) to drop simple information that does not require heavy queries
> > into
> > a file and access it through the file system?
>
> I don't have any stats, but I think it really depends.  If you're
> executing a really complex query that uses like six JOINs and eight
> WHERE clauses, then the bottleneck is the DB and not the DB access
> itself, so it would probably be quicker to have this information ready
> in a file (or even better, cached in memory somehow, though I have no
> experience doing this).  But I believe that with a simpler DB query, a
> DB access is faster than a file read.
>
> Here's something that turned up in Google...
> http://phplens.com/lens/php-book/optimizing-debugging-php.php
>
>
> Erik
>
>
>
>
> 
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Which costs more: connecting to a DB or accessing the file system?

2002-06-21 Thread Erik Price


On Friday, June 21, 2002, at 11:19  AM, mike wrote:

> I was reading somewhere (can't remember where) that connecting to a db 
> is a
> pretty costly transaction.  DB queries aside, does anyone know of any
> benchmarks that demonstrate file access vs. db connections?
>
> Similarily, while DB queries offer alot of power, would it be cheaper
> (faster) to drop simple information that does not require heavy queries 
> into
> a file and access it through the file system?

I don't have any stats, but I think it really depends.  If you're 
executing a really complex query that uses like six JOINs and eight 
WHERE clauses, then the bottleneck is the DB and not the DB access 
itself, so it would probably be quicker to have this information ready 
in a file (or even better, cached in memory somehow, though I have no 
experience doing this).  But I believe that with a simpler DB query, a 
DB access is faster than a file read.

Here's something that turned up in Google...
http://phplens.com/lens/php-book/optimizing-debugging-php.php


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Which costs more: connecting to a DB or accessing the file system?

2002-06-21 Thread mike

I was reading somewhere (can't remember where) that connecting to a db is a
pretty costly transaction.  DB queries aside, does anyone know of any
benchmarks that demonstrate file access vs. db connections?

Similarily, while DB queries offer alot of power, would it be cheaper
(faster) to drop simple information that does not require heavy queries into
a file and access it through the file system?

Michael



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php