View Single Post

  #2 (permalink)  
Old 12-18-2006
Erwin Moller
 
Posts: n/a
Default Re: Efficiency of file vs database

ircmaxell wrote:

> Ok, I have a program that reads the contents of a file (1 line, 5 '|'
> seperated items). Every so often (between twice a day, and 200 times a
> day), it rewrites the contents of that file. I also do a few database
> update queries whenever the file is written. I only open up the
> database connector if I need to update the database. The script itself
> runs every 30 seconds. My question, is that is it faster and more
> efficient to read the file every time, or open the database connector
> and make a query? The file name never changes, and I read the whole
> file at one time (679 bites).


Hi,

Only one way to find out: timestamp both operations and see how long they
take to complete.
But the results may vary a lot based on machineload and needed diskIO (for
other processes).

In general: If your application is running fine with a small file, leave it
that way.
A database will typically be faster if your file is big, because opening a
big file and loading it into memory will take diskIO time, which is often a
bottleneck on modern machines (fast CPU, relatively slow disk IO).

More general: If you don't have a problem, don't fix it. :-)
You should of course be carefull when writing to a file and take precautions
no other process is doing the same (filelocking).

just my 2 cent.

Regards,
Erwin Moller
Reply With Quote