alekseykorzun / memfs-php
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 2
Open Issues: 0
Type:filesystem
Requires
- php: >=5.3.0
- alekseykorzun/memcached-wrapper-php: 0.2.*@dev
This package is not auto-updated.
Last update: 2024-11-09 14:55:32 UTC
README
This package provides a way to store application files in Memcached pool with automatic parsing using eval() upon retrieval.
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.
Performance
First let's look at benchmarks running in VirtualBox on MacBook Pro:
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.
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.
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.
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.
Depending on your load the link between the servers must be greater than 100Mbps.
Make sure to use igBinary with the latest version of daemon.
Installation
If you have your autoloader, simply update namespaces and drop the files into your frameworks library.
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.
Benchmark
You can benchmark and gauge how much benefit this optimization might bring you by running:
php benchmark/run.php
make sure to run it twice before reading the results so the application can cache files
Bugs & Feedback
Feel free to reach me via e-mail aleksey@webfoundation.net