473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DB -> Flat file, did I waste my time?

In my site I have a config table, (MySQL), with about 30 entries; the
data is loaded on every single page load. This is not the only call to
the db, (we do a total of about 8 calls to the db).
As with many configurations settings, once the options are set the
values will not change much.

So I thought it would be a good idea to move the data to a flat file.
I have written a small wrapper class to first look for the file, if it
exists then load the data from that file, if not the data is loaded
from the database and then saved to a file.
That way I can copy the database without worries about the cached data
itself.

It all works as expected, but the question is, did I waste my time?
How can I do some load test on my server to see what would be better?
Database call or flat file read.

My personal guess is that the flat file will only help under very heavy
load, (a couple of hundreds/thousand pages a seconds).

What do you think?
Will the flat file help at all?

Simon

Jan 24 '07 #1
9 2171
FFMG schrieb:
In my site I have a config table, (MySQL), with about 30 entries; the
data is loaded on every single page load. This is not the only call to
the db, (we do a total of about 8 calls to the db).
As with many configurations settings, once the options are set the
values will not change much.

So I thought it would be a good idea to move the data to a flat file.
I have written a small wrapper class to first look for the file, if it
exists then load the data from that file, if not the data is loaded
from the database and then saved to a file.
That way I can copy the database without worries about the cached data
itself.

It all works as expected, but the question is, did I waste my time?
How can I do some load test on my server to see what would be better?
Database call or flat file read.

My personal guess is that the flat file will only help under very heavy
load, (a couple of hundreds/thousand pages a seconds).

What do you think?
Will the flat file help at all?

Simon
I would guess that the relational database is better for a great amount
of data that needs to be sorted and changed regularly. The flat file is
better for a small amount of data that gets read extremely often, always
in the same order, but never written.

Almost all PHP/MySQL CMS (eg Drupal and MediaWiki) have their basic
configuration settings in a file - so it probably isn't a bad idea.

--
CB
Jan 24 '07 #2
Flat file is very common for settings, but database is popular enough too. I
think both are good solutions. I have used both.

You did brain-stretching when writing the wrapper, and exercise is always
good. It is waste of time to even think anymore, if you wasted your time or
not.

So, now stop thinking that and continue to do something else. Remember to be
happy.
Jan 24 '07 #3
"FFMG" <sp********@myoddweb.comwrote:
: In my site I have a config table, (MySQL), with about 30 entries;
: the data is loaded on every single page load. This is not the only
: call to the db, (we do a total of about 8 calls to the db).
:
: As with many configurations settings, once the options are set
: the values will not change much.

Use an include file that holds a function that returns the data inside
an array. This works well for textual and numeric data.

<?php
require("data.php")
?>

<data.php>
function GetMyArray() {
return(array("data1", "data2", 1, 2, 3, 4));
}
</data.php>

Good luck!

--
Jim Carlock
Post replies to the group.
Jan 24 '07 #4
"FFMG" <spambuc...@myoddweb.comwrote:: In my site I have a config table, (MySQL), with about 30 entries;
: the data is loaded on every single page load. This is not the only
: call to the db, (we do a total of about 8 calls to the db).
:
: As with many configurations settings, once the options are set
: the values will not change much.

Use an include file that holds a function that returns the data inside
an array. This works well for textual and numeric data.

<?php
require("data.php")
?>

<data.php>
function GetMyArray() {
return(array("data1", "data2", 1, 2, 3, 4));}</data.php>
Sorry I am not sure I follow, what is that code for?

How does it answer my OP?

Simon

Jan 24 '07 #5
<comp.lang.php>
<FFMG>
<23 Jan 2007 22:51:23 -0800>
<11*********************@s48g2000cws.googlegroups. com>
It all works as expected, but the question is, did I waste my time?
How can I do some load test on my server to see what would be better?
Database call or flat file read.

My personal guess is that the flat file will only help under very heavy
load, (a couple of hundreds/thousand pages a seconds).

What do you think?
Will the flat file help at all?
I've done the script below using flat files .

How its going to perform under a heavy load is anybodys guess - but i
think theres too much worring about heavy loads as most websites will
never have hundreds or thousands of users at the same time .

Most websites arnt google / microsoft / youtube / etc etc .
--
www.phptakeaway.co.uk
(work in progress)
Jan 25 '07 #6
FFMG wrote:
In my site I have a config table, (MySQL), with about 30 entries; the
data is loaded on every single page load. This is not the only call to
the db, (we do a total of about 8 calls to the db).
As with many configurations settings, once the options are set the
values will not change much.

So I thought it would be a good idea to move the data to a flat file.
I have written a small wrapper class to first look for the file, if it
exists then load the data from that file, if not the data is loaded
from the database and then saved to a file.
That way I can copy the database without worries about the cached data
itself.

It all works as expected, but the question is, did I waste my time?
How can I do some load test on my server to see what would be better?
Database call or flat file read.

My personal guess is that the flat file will only help under very heavy
load, (a couple of hundreds/thousand pages a seconds).

What do you think?
Will the flat file help at all?

Simon
FFMG,

MySQL will cache queries and not go to the db if it doesn't need
to... in this case, if keeping the config data in the db is convienent
for you then leave it there. Make sure you have the following MySQL
system variables set:

query_cache_size #bytes (ei: query_cache_size 5242880, that's 5MB)
query_cache_type ? (ei: query_cache_size 1, 0 = OFF / 1 = ON / 2 = DEMAND)

So really what's happening is either MySQL will cache the result set
or your web server will cache the flatfile. The only way to test would
be to write a small script that timed both the database call and the
flatfile call.

You can get this info from MySQL Administrator or command line, or
set them in my.ini, etc.

Norm

Jan 25 '07 #7
"FFMG" <spambuc...@myoddweb.comwrote:
: In my site I have a config table, (MySQL), with about 30 entries;
: the data is loaded on every single page load. This is not the only
: call to the db, (we do a total of about 8 calls to the db).
:
: As with many configurations settings, once the options are set
: the values will not change much.

Jim Carlock replied...
:: Use an include file that holds a function that returns the data inside
:: an array. This works well for textual and numeric data.
::
:: <?php
:: require("data.php")
:: ?>
::
:: <data.php>
:: function GetMyArray() { return(array("data1", "data2", 1, 2, 3, 4)); }
:: </data.php>
::

"FFMG" asked...
: Sorry I am not sure I follow, what is that code for?
:
: How does it answer my OP?

A data file holds information. An array typically gets created to
hold text and numbers and it loads super fast. You mentioned
30(?) items, and that seems trivial for the most part (unless each item
ends up of massive size). My response presented an alternative
way to look at it the problem. You stated you tried the the "flat file"
alternative.

If it's the programmer that only does the updates, it's rather easy to
update the included file's array contents. You could also write that
array to disk (I'm thinking along the lines of text and numbers as
opposed to binary data... I haven't messed with trying to put binary
contents into an array).

It sounded like you have a common file that gets loaded up by a lot
of pages, that doesn't get updated often.

Under those conditions, using require() or include() seems like a
natural choice (it requires much more thought though if you've
got multiple users that update things concurrently, so in that case
a DBMS is probably the best thing to stick with).

The question you asked, "Flat file, did I waste my time?" comes
across as one of those goofy subjective questions, like "Did I
waste my time getting married?" It's a rather personal question
that only you can answer yourself. I can not argue that one way
or the other, it's 100% your question! And either YOU answer it,
"I wasted my time!", or you state, "I learned something, so while
I spent some time on it, all is well and I'll get over it". Those may
or may not be the only answers (some folks create really goofy
answers to such ponderings) and noone but you can answer that
question.

It's not a good idea to ask anyone else if "YOU" wasted your
time. How can anyone else know without you specifically telling
them that you wasted your time?

--
Jim Carlock
Post replies to the group.
Jan 25 '07 #8
>
"FFMG" asked...
: Sorry I am not sure I follow, what is that code for?
:
: How does it answer my OP?

A data file holds information. An array typically gets created to
hold text and numbers and it loads super fast. You mentioned
30(?) items, and that seems trivial for the most part (unless each item
ends up of massive size). My response presented an alternative
way to look at it the problem. You stated you tried the the "flat file"
alternative.
Sorry, your reply did not say that.
In fact when you said, "Use an include file that holds a function that
returns the data inside an array. This works well for textual and
numeric data."

I did not know you meant that this was another approach.
Seen that I was not really asking for another approach but to rather
compare my approach with using the database I might be forgiven for
asking what you were referring to.
>
If it's the programmer that only does the updates,
If that was the case then I would use define(...) or even hardcode the
values in the code.
Using an array is not practical in a 'config' situation.
And using the array the way you propose makes it unusable, (unless you
know that item 0 = data1 and so on).
It sounded like you have a common file that gets loaded up by a lot
of pages, that doesn't get updated often.
Yes, that is what I said, but it does get updated.
Under those conditions, using require() or include() seems like a
natural choice
No it is not. You option makes it very hard to update, if at all.
It is not flexible and does not make the code very portable.

In my case, (as mentioned), it does get updated from time to time.
Updating code and then ftp the contents from time to time is just not
practical in most cases.

It means that no values can be updated by anyone else than the
programmer.
It is indeed a solution, but a bit of a drastic one.
>
The question you asked, "Flat file, did I waste my time?" comes
across as one of those goofy subjective questions, like "Did I
waste my time getting married?"
Really? Was my post the same as asking about marriage?
If you had read my OP, (because it is quite clear that you did not read
it until I asked you what you where taking about), you would have
understood that I was asking about comparing reading a simple file and
reading a simple table.

I said that I wrote a wrapper, (BTW that implies that I am familiar
with such things as 'arrays()', 'include()' and 'require()'), my
question invited a discussion on flat files vs table, (both simple).
I even go further, (to make it clear to those who actually read the
post), and ask if reading a flat file is as fast as reading a table.
So, did I waste my time doing that wrapper?

I did not ask you for 3 lines of code and a 'good luck', good luck for
what?
I can not argue that one way
or the other, it's 100% your question! And either YOU answer it,
"I wasted my time!", or you state, "I learned something, so while
I spent some time on it, all is well and I'll get over it". Those may
or may not be the only answers (some folks create really goofy
answers to such ponderings) and noone but you can answer that
question.
No, a programmer would have said, "You wasted your time because reading
a flat file is slower than reading a table" or "you did not waste your
time because reading a flat file will free some resources on your
database".

Come one, you know exactly what I was asking.
You can throw insults around as much as you like, but the fact remains
that you did not read my post properly and now you try and make it as
if you knew all along what you were taking about.
You then tried to increase your post count by adding a totally useless
post.

I mean,
function GetMyArray() {
return(array("data1", "data2", 1, 2, 3, 4));
}
Did you really think that it was:
1) Answering my post?
2) A practical answer, (given my OP)?
>
It's not a good idea to ask anyone else if "YOU" wasted your
time. How can anyone else know without you specifically telling
them that you wasted your time?
It might be better to only answer posts properly rather than wasting
both our times.

Regards,

Oh, and 'good luck'.

Simon

Jan 25 '07 #9
FFMG wrote:
In my site I have a config table, (MySQL), with about 30 entries; the
data is loaded on every single page load. This is not the only call to
the db, (we do a total of about 8 calls to the db).
As with many configurations settings, once the options are set the
values will not change much.

So I thought it would be a good idea to move the data to a flat file.
I have written a small wrapper class to first look for the file, if it
exists then load the data from that file, if not the data is loaded
from the database and then saved to a file.
That way I can copy the database without worries about the cached data
itself.

It all works as expected, but the question is, did I waste my time?
How can I do some load test on my server to see what would be better?
Database call or flat file read.

My personal guess is that the flat file will only help under very heavy
load, (a couple of hundreds/thousand pages a seconds).

What do you think?
Will the flat file help at all?

Simon
And in addition to my previous post... you can include your config
table in your regular backups and it's one less thing to worry about if
you happen to lose anything.

Norm
Jan 25 '07 #10

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

Similar topics

5
by: lawrence | last post by:
Is there a way to tell PHP, "Spend 5 seconds trying to reach the database, if you can't reach it, then load the file from the cached flat file." I suspect the answer is no. I'm tempted to...
1
by: BlackSnail | last post by:
I need a free software which can convert flat file to xml. I know there are some product,XML Converter of unidex and xmlTextWriter. But I want to find a free software and get the source code. ...
13
by: raykyoto | last post by:
Hi all, I'm sure this is a popular question that comes up every few months here. Indeed, I've looked at some of the past postings, but I would like to ask things differently. Basically, I'm...
1
by: Pierre Maricq | last post by:
Hi, I am using Win2000 and Access2000. I need to build build a macro or write a VBA in Access that would screen all files contained in a directory on my C drive (files are structrured DAT...
1
by: Knepper, Michelle | last post by:
Hi out there, I'm a first-time user of the "Copy ... From..." command, and I'm trying to load a table from a text flat file. http://www.postgresql.org/docs/7.4/static/sql-copy.html I don't...
2
by: Red2 | last post by:
Hi All, I am receiving a flat file data feed from another system. This is comming in every 10 minutes and is going to need to be a high permormance system. The file will contain all the data...
14
by: vunet.us | last post by:
Hi, I would like to use flat file data storage instead of database. Since I am new to it, I am wondering: What text file extension is a safe one to store my data online and how cost- and...
2
by: murthydb2 | last post by:
Hi My requirement is that i have to write a stored procedure in db2 and that will be executed in a batch file . Any system error or validation error that occurs inside the db2 sp during...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.