MemFS-PHP
This package provides a way to store application files in Memcached pool with automatic
parsing using eval() upon retrieval., (*1)
I wrote this after trolling a friend of mine how storing files in Memcached is faster than including
them from disk, so while there are definite uses for this under right circumstances make sure you understand
what you are doing., (*2)
First let's look at benchmarks running in VirtualBox on MacBook Pro:, (*3)
Loaded 500 files using regular include() in 0.020308017730713
Loaded 500 files using MemFS in 0.15591597557068
Loaded 500 files using MemFS (10 files at the time) 0.018874883651733
Loaded 500 files using MemFS (250 files at the time) 0.015585899353027
Loaded 500 files using MemFS (500 files at the time) 0.016402959823608
Keep in mind that the laptop in question has SSD drive., (*4)
As you can see, when compared directly one for one you might get performance degradation but as you
scale up and request 10+ files you will see a slight speed increase of about 0.00143313407 seconds., (*5)
Not much but this benchmark is not scientific and was performed on an empty machine with SSD drive with no I/O
load. Your setup might be different, and if you take 0.0014 * requests per seconds, your application is processing you
might see a benefit of saving 14 seconds per 10000 requests., (*6)
Use cases
- Servers that host PHP based applications in a saturated or slow I/O environment.
- Distributed applications that regularly update their logic can be renewed by updating memory pool with new code that they will include (and evaluate).
- Applications that need to load and parse more than one file in consecutive order.
Memcached
For optimal results, make sure server hosting cache pool is hosted on a separate server but shares the LAN
with your web servers., (*7)
Depending on your load the link between the servers must be greater than 100Mbps., (*8)
Make sure to use igBinary with the latest version of daemon., (*9)
Installation
If you have your autoloader, simply update namespaces and drop the files
into your frameworks library., (*10)
For people that do not have that setup, you can visit http://getcomposer.org to install
composer on your system. After installation simply run composer install
in the parent
directory of this distribution to generate vendor/ directory with a cross-system autoloader., (*11)
Benchmark
You can benchmark and gauge how much benefit this optimization might bring you by running:, (*12)
php benchmark/run.php
make sure to run it twice before reading the results so the application can cache files, (*13)
Bugs & Feedback
Feel free to reach me via e-mail aleksey@webfoundation.net, (*14)