473,804 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Efficiency of file vs database

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

Dec 18 '06 #1
10 3305
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
Dec 18 '06 #2
Following on from ircmaxell's message. . .
>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).
Well since you have both methods at your disposal why don't you compare
them? If you can't detect a speed difference then it doesn't matter.

In my experience this sort of choice will probably depend on other
things anyway.

I have a feeling that you're making a mountain out of a molehill of
machine cycles.

--
PETER FOX Not the same since the porcelain business went down the pan
pe******@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Dec 18 '06 #3
Well, the problem I have, is that durring the peak times, the server is
at its limit of resouces (CPU and Ram) and getting around 100 requests
per second (images included). So if I could save a tiny bit, it would
make a difference... Even at its peak, the script runs every 30
seconds, however if I could reduce the memory footprint created by this
program, it would reduce Apache's child process memory footprints...
Just a question... Thanks!

On Dec 18, 6:20 am, Peter Fox
<peter...@emine nt.demon.co.uk. not.this.bit.no .htmlwrote:
Following on from ircmaxell's message. . .
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).Well since you have both methods at your disposal why don't you compare
them? If you can't detect a speed difference then it doesn't matter.

In my experience this sort of choice will probably depend on other
things anyway.

I have a feeling that you're making a mountain out of a molehill of
machine cycles.

--
PETER FOX Not the same since the porcelain business went down the pan
peter...@eminen t.demon.co.uk.n ot.this.bit.no. html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.dem on.co.uk>
Dec 18 '06 #4

Erwin Moller wrote:
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).
Building upon that... The file may be small enough right now for it
not to matter. But if it starts to get bigger in the future and you've
already gone heavily down this path, you may need to do significant
backtracking to switch over to a database.

Just something to keep in mind.

Dec 18 '06 #5
ircmaxell wrote:
Well, the problem I have, is that durring the peak times, the server is
at its limit of resouces (CPU and Ram) and getting around 100 requests
per second (images included). So if I could save a tiny bit, it would
make a difference... Even at its peak, the script runs every 30
seconds
If the script runs every 30 seconds, but you get 100 requests per second,
that means that only 0.3% of requests are for this particular script.
Which means that you might be better off optimising the other 99.7% of the
requests!

Although Apache is a lovely server, there are some others which might run
faster for you if you don't need some of the extra features that Apache
provides. Take a look at, say, "thttpd" -- your PHP will likely run slower
(as it runs PHP through CGI instead of mod_php) but the speed-up you get
for other files may more than make up for it.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Dec 18 '06 #6
Well, let me clarify... The site is comprised of a complete php
frontend (Joomla). There are 4 HTML files and an XML file that recieve
90% of the traffic (the other 10% accounts for enough traffic to keep
php running fast). The script that we are talking about rewrites those
5 files (plus a tiny one) on every run. I need to use apache for
mod_rewrite and other functions on other domains hosted.
The site : www.bagsofcrap.com
One HTML file http://www.bagsofcrap.com/woot.html
XML file http://www.bagsofcrap.com/woot.xml
Small txt file http://www.bagsofcrap.com/wootdata.txt

I would post the update script, but that's pointless...

On a side note. Would it be worth it to not write 4 HTML files, but
have them hit a small php file instead that queries a database for the
data? Or is my way most efficient?
Toby Inkster wrote:
ircmaxell wrote:
Well, the problem I have, is that durring the peak times, the server is
at its limit of resouces (CPU and Ram) and getting around 100 requests
per second (images included). So if I could save a tiny bit, it would
make a difference... Even at its peak, the script runs every 30
seconds

If the script runs every 30 seconds, but you get 100 requests per second,
that means that only 0.3% of requests are for this particular script.
Which means that you might be better off optimising the other 99.7% of the
requests!

Although Apache is a lovely server, there are some others which might run
faster for you if you don't need some of the extra features that Apache
provides. Take a look at, say, "thttpd" -- your PHP will likely run slower
(as it runs PHP through CGI instead of mod_php) but the speed-up you get
for other files may more than make up for it.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Dec 19 '06 #7
Usually when in need to compare which is faster, I tend to think that
in the very end databases are just flat files. The only difference
between real flat files and database is the database software, which
has been built to optimize, among other things, the speed of quering of
the data.

This of course might not be the case in your problem, since reading
just a simple file might be faster. However if the database software is
in the same server with the php, the connection should be very fast.

Just babbling, try it out. As someone mentioned, if your file grows
you'll might be at risk in the future. Databases are just so much more
scalable.

jussi

Dec 19 '06 #8
On Tue, 19 Dec 2006 11:59:29 -0800, ju*****@gmail.c om wrote:
Usually when in need to compare which is faster, I tend to think that in
the very end databases are just flat files. The only difference between
real flat files and database is the database software, which has been
built to optimize, among other things, the speed of quering of the data.
If you disregard all of the fundamentals of database design...
normalization, index optimization, etc.

A flat file can be very fast as long as you're talking about a very small
file. At the point the overhead of the database server matches the access
time of the flat file based on its size the database server will always be
faster... assuming your database isn't designed like a flat file (which it
shouldn't be).
Dec 19 '06 #9
Well, I wound up redesigning the program anyway, and what a speed
difference!!! I went to an almost completely database system (I still
write a bunch of files, but I don't read any of them). The page load
went from .93 seconds to .24 seconds... The file read portion went
from .36 seconds to (are you ready?) a measly .00023 seconds using the
database... WOW!!! You can say that is a little difference...

On Dec 19 2006, 3:29 pm, Ivan Marsh <anno...@you.no wwrote:
On Tue, 19 Dec 2006 11:59:29 -0800, juss...@gmail.c om wrote:
Usually when in need to compare which is faster, I tend to think that in
the very end databases are just flat files. The only difference between
real flat files and database is the database software, which has been
built to optimize, among other things, the speed of quering of the data.If you disregard all of the fundamentals of database design...
normalization, index optimization, etc.

A flat file can be very fast as long as you're talking about a very small
file. At the point the overhead of the database server matches the access
time of the flat file based on its size the database server will always be
faster... assuming your database isn't designed like a flat file (which it
shouldn't be).
Jan 22 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1926
by: Daan | last post by:
Hello all, I have attempted to write my own forum using PHP and MySQL. It works, but the efficiency is far from ideal. It takes a long time to load e.g. the list with threads in a certain forum. I think the problem has to do with the fact that I have several SQL calls in nested loops, so if a large thread list has to be loaded, there are a lot of SQL queries to be executed. I have posted the code that initialises the forum below, so...
1
1524
by: Gooseman | last post by:
Hi, I'm constructing a page that contains a list of files that can be downloaded - The file details (name, description, date) are stored on a database (mySQL). When displaying the file details on HTML I use filesize() to display the size of each file. Is this really inefficient? Would it be better to store the size of the file on the database instead. What's kind of performance difference are we talking about.
1
1932
by: Nathan Bloomfield | last post by:
Hi, I am a new database developer and would appreciate some advice on improving the efficiency of my database. The code below is an example of one of the more complex queries in the database (very basic in the scheme of things). Can anyone offer advice in improving the structure considering this database resides on a network with limited bandwidth. The query runs
2
2323
by: Sara | last post by:
Hi - I've been reading the posts for a solution to my query, and realize that I should ask an "approch" question as well. We receive our production data from a third party, so my uers import the data from Excel into the appropriate tables. There are 6 different databases that receive data, though 4 of them only get one table each. I have learned how to automate the data import through
13
2203
by: MLH | last post by:
I have a RDBMS app consisting of 3 primary mdb's... 1) a front-end with a few STATIC tables and the other menagerie of objects 2) a back-end with most of my DYNAMIC tables. I'll call it my main backend. 3) another back-end = zip.mdb with about 43000 zips/cities/states The app has been operating stably (is that a word?) for some years. No probs. The main backend is 63.3 megs now and contains tens of thousands of letters - legal...
2
1901
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across the top showing different panels. A DropDownList with a 50+ value/text entries exists on more than one panel but only one will be displayed at a time. Examples might be US states, countries, category codes, etc.
12
2319
by: PD | last post by:
I am currently making a dating website. I want to have some information on how to structure the database and the php files so that I can achieve speed and efficiency. Can some one please give me suggestions and point me to references where I can get this information.
19
2936
by: vamshi | last post by:
Hi all, This is a question about the efficiency of the code. a :- int i; for( i = 0; i < 20; i++ ) printf("%d",i); b:- int i = 10;
2
1807
by: pedalpete | last post by:
Hey mysql gurus, I've got a bit of an efficiency question, and just trying to figure out how best to manage this. For my site HearWhere.com, I have a table which holds artists shows. When i am refreshing the collection of shows and geocoding the locations, the database response for user queries slows significantly - which is understandable. One option I'm considering is to have one database which the users connect to for queries,...
0
9712
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.