I have websites developed in PHP. Im using Opcode cache.
But because Opcode cache like eAccelerator or APC is cached in RAM, I needs too much RAM.
So Im looking for any project or technique which cache the PHP Opcode in hard disk.
Thanks so much
(my website is not generate money, so Im thinking about cheaper solution)
all op-code caches allow you to configure the maximum size of shared memory used (look for a configuration option with shm - for SHared Memory - in the name, eg. apc.shm_size). so you can control that they don't use too much ram.
some caches also allow you to cache on disk instead/besides of caching in ram:
eAccelerator
the question is if a small amount of shared memory or a disk only cache gains you anything in performance compared to plain php without op-code cache. as always when using a cache, you should benchmark this.
Related
I'm thinking of replacing some of my file system caching (via phpfastcache) over to memcache (again using phpfastcache) but I have a query on storage sizes. Potentially a silly question but:
If I had 80gb of file cache storage being used would that equal to needing 80gb of ram to store the exact same cache via memory?
I'm thinking they potentially use different compression methods but I've struggled to find an answer online.
80gb of cache is huge, I'm myself surprised that Phpfastcache handles it well. If you migrate to Memcache, for sure you can expect some serious memory issue on the server.
For such size I recommend you more performant backends such as Mongodb/Couchdb/Arangodb or maybe Redis too.
If you're just looking for backend storage stats, you can have a look at this API offered by Phpfastcache: Wiki - Cache Statistics
It will return you misc statistics provided by the backends supported by Phpfastcache.
(Note: I'm the author of this Library)
Since some time, I have been doing hobby projects again in PHP. One of the things I am running is a small application to store some Json data.
And another to make some big calculations.
As we all know, PHP itself is not the best language for this (working with big calculations), since we need to compile it everytime we call it, it's kinda slow (if you compare it with golang or other languages that are already compiled before it runs).
To increase the speed of PHP we can use opcache to compile everything and store it in the Ram memory, so it will load much quicker.
Ram: Random access memory
But one of the things I found out, is that you can use opcache as file storage as well (https://patrickkerrigan.uk/blog/php-opcache-file-cache/), instead of putting it in more expensive Ram memory (since storage is cheaper than memory).
I understand why you would add it into Ram, since it is really quick. but why not use file storage more for servers that don't have that much Ram (it's slower, but will still increase the speed of your application since it is compiled to binary code)?
When you are low on memory and there are multiple PHP in opcache it would eat the memory, but when you store it on file storage, it matters less?
I did not find a lot of articles about this. Are there big drawbacks to this approach?
Is there a caching system in PhP that's both fast and big?
If I cache in disk the IO goes up.
If I cache in memory, the memory is small.
I need a comprehensive caching system that cache in memory, but when the memory goes big automatically dump large data sequentially to disk.
Any such thing in PhP?
The site store huge number of small items (30k) millions of them. Each data is stored in a file now
You should try one of these:
APC
XCACHE
EACCELERATOR
MEMCACHE
ZEND OPTIMIZER
These are the best PHP cache solutions available.
Sounds like you want Redis. It's sort of like memcache but with disk based persistance/overflow.
The reason I ask is because when using top I don't see a process for anything like APC. So I assume that the memory usage would be accounted for in an apache process.
Is that the case, and does that mean that the memory APC is using is replicated in each apache process, thereby taking up potentially much more memory than what was originally assigned to it?
If this is the case would memcache be a better solution, even if it's not being used on multiple loadbalanced servers?
APC uses shared memory to store its opcode cache. In the case of mod_php this memory is shared between all Apache processes. So a 30MB cache only takes up 30MB even if there are 5 Apache processes.
However, when using mod_php, each Apache process does waste a lot of resources as each process contains the PHP interpreter. Thus, when Apache serves static content (html, css, js, image files, etc) it uses a process with the full PHP interpreter loaded. To get around this, some people use FastCGI via mod_fastcgi or mod_fcgi. Using an opcode cache with FastCGI becomes a bit trickier.
There is currently no way to use memcache as an opcode cache. Even if there was, it would probably be slower than desired.
Besides being an opcode cache, APC also provides shared memory. That strongly suggests that it has its own internal shared memory system similar to memcached.
Can anyone tell me what is the memory usage overhead associated with PHP opcode cache?
I've seen a lot of reviews of opcode cache but all of them only concentrate on the performance increase. I have a small entry level VPS and memory limits are a concern for me.
Most of the memory overhead will come from the opcode cache size. Each opcode cacher has their own default(e.g. 30MB for APC) which you can change through the config file.
Other than the cache size, the actual memory overhead of the cacher itself is negligible.
In todays world: It's neglectible. I think memory consumption was about 50 MB bigger with eAccelerator then it was without when I did my benchmarks.
If you really need the speed but do have headaches that your RAM might be not enough: grab $40 and buy another GIG of RAM for your server ;)
You can set a limit to memory consumption for APC, but that potentially limits its effectiveness.
If you're just using it for silent opcode caching, then it should be fine. Once the memory allotment is full, no new files will be cached, but everything will work as expected. However, the user-space cache functions like apc_store() and apc_fetch() will fail silently and inexplicably if there is no memory available.
This can be tricky to catch and debug since no error is reported and no exception is thrown.