文件与数据库的效率 [英] Efficiency of file vs database

查看:50
本文介绍了文件与数据库的效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个程序可以读取文件的内容(1行,5''|''

分隔的项目)。每隔一段时间(每天两次,每天两次,每天两次),它会重写该文件的内容。每当写入文件时,我也会做一些数据库

更新查询。如果我需要更新数据库,我只打开

数据库连接器。脚本本身

每30秒运行一次。我的问题是,每次读取文件的速度更快,更有效吗?或者打开数据库连接器

并进行查询?文件名永远不会改变,我一次读完整个

文件(679次)。

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

推荐答案

ircmaxell写道:
ircmaxell wrote:

好​​的,我有一个程序读取文件的内容(1行,5''|''

分隔项目)。每隔一段时间(每天两次,每天两次,每天两次),它会重写该文件的内容。每当写入文件时,我也会做一些数据库

更新查询。如果我需要更新数据库,我只打开

数据库连接器。脚本本身

每30秒运行一次。我的问题是,每次读取文件的速度更快,更有效吗?或者打开数据库连接器

并进行查询?文件名永远不会改变,我一次读取整个

文件(679次)。
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).






只有一种方法可以找到:时间戳两个操作并查看它们需要多长时间

需要完成。

但结果可能因机器负载和所需的磁盘IO而变化很大(对于

其他进程)。


一般情况下:如果您的应用程序运行正常并带有一个小文件,请保留



如果文件很大,数据库通常会更快因为打开一个

大文件并将其加载到内存中会花费磁盘时间,这通常是现代机器上的瓶颈(快速CPU,相对较慢的磁盘IO)。


更一般:如果你没有问题,不要修理它。 :-)

当你写一个文件并采取预防措施时当然要小心

其他进程没有做同样的事情(文件锁定)。


只需2美分。


问候,

Erwin Moller

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


接下来来自ircmaxell的消息。 。 。
Following on from ircmaxell''s message. . .

>好的,我有一个程序可以读取文件的内容(1行,5''|''
分隔的项目)。每隔一段时间(每天两次,每天200次),它会重写该文件的内容。每当写入文件时,我也会做一些数据库更新查询。如果我需要更新数据库,我只打开
数据库连接器。脚本本身每30秒运行一次。我的问题是,每次读取文件或打开数据库连接器并进行查询是否更快,更高效?文件名永远不会改变,我一次读完整个
文件(679次)。
>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).



好​​了,因为你有两种方法可供选择你不比较

吗?如果您无法检测到速度差异那么无关紧要。


根据我的经验,这种选择可能取决于其他的

无论如何。


我有一种感觉,你是在一个机器周期的小山谷里制造一座山。

-

PETER FOX自瓷器业务倒下以来不一样
pe ****** @ eminent.demon.co.uk.not.this.bit.no.html

2 Tees Close,Witham,Essex。

埃塞克斯的重力啤酒< http://www.eminent.demon.co.uk>

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******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>

嗯,我遇到的问题是,在高峰时间,服务器是资源限制(CPU和Ram)和获得大约100个请求
$ b每秒$ b(包括图片)。所以,如果我可以节省一点点,它就会产生差异......即使在最高峰时,脚本也会每隔30美元运行一次,但是如果我能减少的话这个

程序创建的内存占用,它会减少Apache的子进程内存占用...

只是一个问题......谢谢!


12月18日早上6:20,Peter Fox

< peter ... @ eminent.demon.co.uk.not.this.bit.no。 html写道:
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...@eminent.demon.co.uk.not.this.bit.no.html wrote:

继续从ircmaxell的消息。 。 。
Following on from ircmaxell''s message. . .

好​​的,我有一个程序可以读取文件的内容(1行,5''|''

分隔的项目)。每隔一段时间(每天两次,每天两次,每天两次),它会重写该文件的内容。每当写入文件时,我也会做一些数据库

更新查询。如果我需要更新数据库,我只打开

数据库连接器。脚本本身

每30秒运行一次。我的问题是,每次读取文件的速度更快,更有效吗?或者打开数据库连接器

并进行查询?文件名永远不会改变,我一次读完整个

文件(679次)。好了,因为你有两种方法可供你使用,为什么不比较
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



他们?如果您无法检测到速度差异那么无关紧要。


根据我的经验,这种选择可能取决于其他的

无论如何。


我有一种感觉,你是在一个机器周期的小山谷里制造一座山。

-

PETER FOX自瓷器业务下滑以来不一样

彼得... @ eminent.demon.co.uk.not .this.bit.no.html

2 Tees Close,Witham,Essex。

埃塞克斯的重力啤酒< http://www.eminent.demon.co。 UK>

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...@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>


这篇关于文件与数据库的效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆