0

As we know that the memory is faster than the disk.

So I wonder if I can store the frequently requested files such as js / css / icons into memcache, and write a script such as php to get them from memcache to browsers instead of the normal way that server software read from disk.

I know that will make extra spend of executing php. But compare with slow speed of disk I/O, which is better.

horsley
  • 471
  • 4
  • 10
  • 1
    Depending on your system configuration, your OS may well be preconfigured to keep such frequently requested files in memory, so use a disk I/O utility to check that first :) – Daan Feb 06 '12 at 07:58

2 Answers2

2

There would be absolutely no point in doing this.

First, your OS' filesystem cache is good enough and will cache the files that really being accessed frequently already.

Next, the approach will actually make your site slower and more bandwidth-eater. While you are going to serve the files themselves, your webserver would often send merely an HTTP header instead of the file body.

Also, you will eat up a number of php-workers which is really precious and limited resource for the highload server.

Finally, premature optimization is a root of all evil.

If you want your files to be served really fast, move them to some sort of CDN.

Your Common Sense
  • 152,517
  • 33
  • 193
  • 313
  • 2
    That's the stupidest thing I've heard in awhile. Your points are all valid ... but your flat, categorical assertions are simply wrong. The answer to just about any question is "it depends". The short answer to this question is "Memcached" (or PHP cache, or any number of other alternatives) is at least worth CONSIDERING." IMHO... – paulsm4 Feb 06 '12 at 18:15
  • thank you for your concern. I am already considered memcache and found it useless for this case. – Your Common Sense Feb 06 '12 at 18:28
1

Using memcached with frequently accessed files (PHP source and includes, image files, etc etc) can absolutely boost performance.

Two caveats:

  • Do you have enough traffic that it's worth it?

  • Do the files you plan on caching ever change (or change often)?

But in general: sure. Go for it!

Here are some good links:

Community
  • 1
  • 1
paulsm4
  • 99,714
  • 15
  • 125
  • 160