Wincache vs. opcache, coexist? Any tuning needed? RSS

8 replies

Last post Sep 21, 2017 10:42 PM by DropPhone

  • Wincache vs. opcache, coexist? Any tuning needed?

    Sep 06, 2017 04:10 AM|startover909|LINK

    Sorry if this question has been asked before (couldn't find a satisfactory answer via search). With PHP 7+ and built-in Zend Opcache enabled, is it still necessary to enable Wincache? Are there any potential conflicts between these two caching mechanisms? Are there any specific recommended settings/tunings when they're used together? Finally, is Wincache fully compatible with IIS 10?

    Thanks!

  • Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 06, 2017 04:29 PM|DRUE|LINK

    The newer WinCache versions don't have OP caching anymore -- the WinCache team removed it so solve this exact question.

    If you want any OP caching, you have to use Zend.

    You can still get additional improvements by using the WinCache file cache.

    I've seen no issues in IIS 10 so far.

  • Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 06, 2017 08:02 PM|startover909|LINK

    This is my understanding, please correct me if I'm wrong:

    wincache's file cache caches the PHP script files themselves in shared memory so that they don't have to be read from disk.

    opcache caches the compiled form of the scripts so that they're ready for execution upon request and don't have to be re-compiled.

    If this is true, that means as long as opcache is working properly and contains the compiled scripts in its shared memory, wincache's file cache essentially becomes redundant as those physical scripts won't even be used.

    *However", I can think of this scenario:  opcache is set to "re-validate" the cache from time to time (determined by opcache.revalidate_freq). When this revalidation occurs, it needs to access the underlying .php scripts. If these scripts are cached by wincache's file cache, will they be used by opcache to speed up the validation process? Or will opcache always request the files on the disk?

  • Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 06, 2017 10:58 PM|DRUE|LINK

    I believe, in that case, OP cache's re-validation will use the WinCache in-memory cached file.

    Another scenario you should consider is that the OP cache could be cleared if it becomes full, crashes, etc. If WinCache doesn't have all the files in memory, it will have to get them all again from the disk.

    Unless you are working in a low resource environment, you should have both on. The memory usage from file cache only takes up several MB for me. You can check yours using wincache.php in the download.

  • Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 07, 2017 01:07 AM|DRUE|LINK

    I thought about it a little more, and I think you should also make sure to set wincache.ttlmax to 0. This is because on a busy site, the OP cache will continue to serve the application, while the WinCache layer will stay there unused. If the site goes idle, and the OP cache gets cleared, WinCache will be pinged and if the TTL is not high enough, it will re-read contents from the disk, rendering its caching benefits useless.

  • DropPhone DropPhone

    360 Posts

    Microsoft

    Moderator

    Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 12, 2017 09:31 PM|DropPhone|LINK

    startover909

    as long as opcache is working properly and contains the compiled scripts in its shared memory, wincache's file cache essentially becomes redundant as those physical scripts won't even be used.

    ...for *.php files, yes.

    However, WinCache's file cache will cache any file that is opened via the PHP streams interface.  That includes *.txt, *.jpg, *.tiff, *.whatever files.  This can mean potentially huge savings, because pulling static content out of shared memory is faster than pulling it off disk, and massively faster than pulling it from a network-backed file system (like SMB or NFS).

  • DropPhone DropPhone

    360 Posts

    Microsoft

    Moderator

    Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 12, 2017 09:56 PM|DropPhone|LINK

    DRUE

    I think you should also make sure to set wincache.ttlmax to 0.

    Setting this to 0 means that stale/expired items will never be scavenged.  The WinCache shared memory segment will eventually become full, until it is no longer able to create new items.  When that happens, you'll eventually devolve to a state where only un-servable, expired items exist in the cache, and you'll get 100% cache misses for all lookups.  It may take days, months or weeks to get to that state, but you *will* eventually get there.

    DRUE

    If the site goes idle, and the OP cache gets cleared, WinCache will be pinged and if the TTL is not high enough, it will re-read contents from the disk, rendering its caching benefits useless.

    Let's split this apart.

    First, if the site goes idle, and the w3wp.exe spins down, the WinCache file cache will also spin down.

    Second, I don't know what you mean by 'pinged'.  All cache operations are performed during operations initiated by executing a PHP script.  That includes cache scavenging.  The scavenger isn't on some kind of timer, waking up every N seconds to scavenge things.  If there is no activity, then the scavenger doesn't run.  Of course, there are also safeguards to ensure that, when the cache is being used heavily, the scavenger doesn't run on every single request.

    Third, for file cache entries, TTL isn't really the thing you care about.  It's the timestamp on the file.  And the wincache.chkinterval and the wincache.fcndetect settings.  If the underlying file system supports file change notifications, and fcndetect is enabled, then cached files will only get marked as stake when a change notification fires.  If the underlying file system doesn't support change notifications, then the chkinterval is used.  But here again, it's only referenced while a cache operation is executing.

    I hope this helps!

        --E.

  • Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 19, 2017 12:54 AM|startover909|LINK

    DropPhone

    Setting this to 0 means that stale/expired items will never be scavenged.  The WinCache shared memory segment will eventually become full, until it is no longer able to create new items.  When that happens, you'll eventually devolve to a state where only un-servable, expired items exist in the cache, and you'll get 100% cache misses for all lookups.  It may take days, months or weeks to get to that state, but you *will* eventually get there.

    Most IIS configurations have application pools recycled on a regular interval (default 29 hours). My understanding is that when the application pool recycles, the wincache will also reset, correct? If so would you say setting ttlmax to 0 is okay as long as the IIS application pool is set to recycle on a reasonable basis, such that between the intervals of said recycling, the wincache cache pool is unlikely to degrade to your described state?

    Thanks.

  • DropPhone DropPhone

    360 Posts

    Microsoft

    Moderator

    Re: Wincache vs. opcache, coexist? Any tuning needed?

    Sep 21, 2017 10:42 PM|DropPhone|LINK

    startover909

    would you say setting ttlmax to 0 is okay as long as the IIS application pool is set to recycle on a reasonable basis

    sure, you can set it to 0.  But I'd still recommend leaving it at the default.