Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File access speed vs database access speed

Tags:

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

like image 624
user103219 Avatar asked May 11 '09 17:05

user103219


People also ask

Which is faster DB or file?

So for very simple operations, the filesystem is definitely faster. Filesystems will probably beat an RDBMS for raw read throughput too since there is less overhead. In fact, if you think about it, the database can never be faster than the filesystem it sits on in terms of raw throughput.

Why is Access database slow?

Over time, the performance of a database file can become slow because of space that remains allocated to deleted or temporary objects. The Compact and Repair command removes this wasted space and can help a database run faster and more efficiently.

Why database is faster?

Most people ask why is database so faster when compared to flat file entries of data. There are many reasons behind that, one of them is indexing. Of course the speed of the underlying disk subsystem's also plays a major role in increasing database speed.


2 Answers

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.

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.

like image 86
James Socol Avatar answered Oct 15 '22 18:10

James Socol


It depends on how the data is structured, how much there is and how often it changes.

If you've got relatively small amounts, of relatively static data with relatively simple relationships - then flat files are the right tool for the job.

Relational databases come into their own when the connections between the data are more complex. For basic 'look up tables' they can be a bit overkill.

But, if the data is constantly changing, then it can be easier to just use a database rather than handle the configuration management by hand - and for large amounts of data, with flat files you've got the additional problem of how do you find the one bit that you need, efficiently.

like image 37
Stringent Software Avatar answered Oct 15 '22 19:10

Stringent Software