Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing frequently accessed data in a file rather than MySQL

I'm working on a PHP content management system and, in testing, have noticed that quite a few of the system's MySQL tables are queried on almost every page but are very rarely written to. What I'm wondering is will this start to weigh heavily on the database as site traffic increases, and how can I solve/prevent this?

My initial thoughts were to start storing some of the more static data in files (using PHP serialization) but does this actually reduce server load? What I'm worried about is that I'd be simply transferring the high load from the database to the file system!

If somebody could clue me in on the better approach, that would be great. In case the volume of data itself has a large effect, I've detailed some of the data I'll be storing below:

  • Full list of Countries (including ISO country codes)
  • Site options (skin, admin email, support URLs etc.)
  • Usergroups (including permissions)
like image 449
Rowan Avatar asked Feb 11 '10 00:02

Rowan


1 Answers

You have to remember that reading a table from a database on a powerful server and on a fast connection is likely to be faster than reading it from disk on your local machine. The database will cache the entirety of these small, regularly accessed tables in memory.

By implementing the same functionality yourself in the file system, there is only a small possible speed up, but a huge chance to mess it up and make it slower.

It's probably best to stick with using the database.

like image 177
Mark Byers Avatar answered Oct 20 '22 22:10

Mark Byers