文件访问速度vs数据库访问速度 [英] File access speed vs database access speed

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

问题描述

我在php中开发的网站使得每个页面查看许多MySQL数据库请求。虽然很多是小请求与正确设计的指数。我不知道是否值得为这些页面开发一个缓存脚本。

The site I am developing in php makes many MySQL database requests per page viewed. Albeit many are small requests with properly designed index's. I do not know if it will be worth while to develop a cache script for these pages.

1)文件I / O通常比数据库请求快?这取决于服务器吗?是否有一种方法来测试每个服务器可以处理多少?

1) Are file I/O generally faster than database requests? Does this depend on the server? Is there a way to test how many of each your server can handle?

2)其中一个页面检查数据库的文件名,然后检查服务器以查看它存在,然后决定要显示什么。这个我认为会从缓存的页面视图中受益?

2) One of the pages checks the database for a filename, then checks the server to see if it exists, then decides what to display. This I would assume would benefit from a cached page view?

此外,如果有任何其他信息,这个话题,你可以转发我,将非常感谢。

Also if there is any other information on this topic that you could forward me to that would be greatly appreciated.

感谢

推荐答案

(查找文件名等),您可能会从 memcached 中受益。您可以将最热(最近创建的,最近使用的,取决于您的应用程序)数据存储在内存中,然后在缓存未命中时查询DB(以及可能的文件)。内存访问远远快于数据库或文件。

If you're doing read-heavy access (looking up filenames, etc) you might benefit from memcached. You could store the "hottest" (most recently created, recently used, depending on your app) data in memory, then only query the DB (and possibly files) when the cache misses. Memory access is far, far faster than database or files.

如果你需要写访问,数据库是一条路。如果您使用MySQL,请使用InnoDB表或其他支持行级锁定的引擎。

If you need write-heavy access, a database is the way to go. If you're using MySQL, use InnoDB tables, or another engine that supports row-level locking. That will avoid people blocking while someone else writes (or worse, writing anyway).

但最终,这取决于数据。

But ultimately, it depends on the data.

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

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