473,734 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2189
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********@myo ddweb.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.p hp")
?>

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

Good luck!

--
Jim Carlock
Post replies to the group.
Jan 24 '07 #4
"FFMG" <spambuc...@myo ddweb.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.p hp")
?>

<data.php>
function GetMyArray() {
return(array("d ata1", "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.ph p>
<FFMG>
<23 Jan 2007 22:51:23 -0800>
<11************ *********@s48g2 000cws.googlegr oups.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_siz e #bytes (ei: query_cache_siz e 5242880, that's 5MB)
query_cache_typ e ? (ei: query_cache_siz e 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...@myo ddweb.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.p hp")
:: ?>
::
:: <data.php>
:: function GetMyArray() { return(array("d ata1", "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("d ata1", "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
1795
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 rewrite all my code in Java, just so I can have threads. And private methods. And private class properties. And real encapsulation. And interfaces. And abstract classes. And the ability to do anything.
1
2022
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. Where can I find such free software which converting flat file to xml? Is there any place I can get the source code ? Thanks a lot.
13
3424
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 using a flat file to storing data. I have to do this because mySQL is not installed on my web server, and I am not the root user. The amount of data is so small, that it isn't worth a full-blown database anyway. However, while the data is...
1
4477
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 files ) and update an Access table with the following information: (1) Filename (variable lenght) (2) Modified File Date/Time
1
5625
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 know if I'm using the command correctly. Question: I run this command as a superuser, and the "copy from" command is run like a SQL command on the command line, correct?
2
2366
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 every time, which might require a truncate and re-fill of the data (I haven't figured out if they'll let me update yet, but because of performance concerns inserts are cheaper then updates) I figure to use SystemFileWatch to catch the file comming...
14
2278
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 time-effective is this method (flat file data storage). Anyone can share thoughts? Thanks
2
6144
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 the execution need to be written in external flat file ( Log file to know the error ) . Is there anything similar in db2 like UTL_FILE in oracle . Please find the sample coding in oracle which will write the output to a external flat...
15
5275
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 show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
0
8946
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
9449
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
9310
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
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
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
6031
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
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.