logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



PHP Caching extensions accessing shared memory
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Apache Forum Index -> Other Software



View previous topic :: View next topic  
Author Message
C0nw0nk



Joined: 07 Oct 2013
Posts: 241
Location: United Kingdom, London

PostPosted: Sun 08 Feb '15 18:25    Post subject: PHP Caching extensions accessing shared memory Reply with quote

So i noticed something strange going on with wincache on my servers. When lets say a php process hits its max number of served requests.
Code:
set PHP_FCGI_MAX_REQUESTS=1000


That PHP process will close and the next PHP process in the que will start serving traffic, But when i look at the cache statistics they show that the cache uptime has been lets say "30 seconds" and its only cached "50-100 items" when on my previous php process it would say "cached files 500, cache uptime 40mins."

So does that mean when PHP closes a process for hitting its max request count it drops all the cached items from the memory too.


Are there any caches that pass the cache onto the next process, "shared memory access". ?

I was reading about APC doing it and as of XCache i am unsure.

Want to see if i can find a cache that shares its cache between all running PHP processes, Rather than just the one that seems to be serving traffic at the time.


//EDIT :
For those who encounter this same problem i posted the soloution here.

http://www.apachelounge.com/viewtopic.php?p=29858#29858


Last edited by C0nw0nk on Sun 15 Feb '15 15:53; edited 1 time in total
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Mon 09 Feb '15 11:57    Post subject: Reply with quote

None of them really use shared memory as they should on windows, trying to convince the developers has been a waste of (my) time..... so yes each process has its own cache and of-course is dropped on reload.
Looking at cache stats is mostly meaningless as you have no grip on which cache your looking at.
Back to top
C0nw0nk



Joined: 07 Oct 2013
Posts: 241
Location: United Kingdom, London

PostPosted: Mon 09 Feb '15 14:41    Post subject: Reply with quote

Just as i thought a pitty realy but hopefully some point in the future they get their heads around it.

I think memcached if you install and run that on a port on your server and use the php_memcached.dll that is a soloution but the last time i tried with memcache i remember it kept crashing not the most friendly or stable thing on windows.

I wounder if Jan-E would know of a soloution to this since he has fixed so many PHP extensions and ported them to windows too.
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Mon 09 Feb '15 17:55    Post subject: Reply with quote

Its quite simple but needs a proper programmer...

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686958%28v=vs.85%29.aspx
http://www.boost.org/doc/libs/1_41_0/doc/html/interprocess/sharedmemorybetweenprocesses.html

Back to top
C0nw0nk



Joined: 07 Oct 2013
Posts: 241
Location: United Kingdom, London

PostPosted: Mon 09 Feb '15 20:19    Post subject: Reply with quote

Hmmm i wounder if its worth finding a freelancer for this.

https://www.elance.com/

I take it XCache is more suited for the job than Wincache.
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Mon 09 Feb '15 23:22    Post subject: Reply with quote

I don't think it makes a difference, the whole job is making a shared memory module with an api and changing ??cache to use the api instead. Memcache would be good to start with.
Back to top
C0nw0nk



Joined: 07 Oct 2013
Posts: 241
Location: United Kingdom, London

PostPosted: Tue 10 Feb '15 14:13    Post subject: Reply with quote

Well i used memcached on windows a long time ago and i had to stop using it because it kept crashing. Idk if its been updated or fixed and i dont even know where you would get the binaries from now.
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Tue 10 Feb '15 15:49    Post subject: Reply with quote

I didn't mean to use memcache but to use the source as a base.

This module should;
- allocate x amount of memory and lock it
- wait for a semaphore (API)

??cache should;
- Change its memory management to use API

Inter IO is much faster then a tcp port, its the same way nginx uses the pid file (sort of an API) in order to know who to talk to about shared resources.

But then again, if xcache or whatever-cache was rewritten in Lua we could cache anything(php,py,perl,etc.) and have its cache shared automatically.
Back to top
C0nw0nk



Joined: 07 Oct 2013
Posts: 241
Location: United Kingdom, London

PostPosted: Wed 11 Feb '15 2:46    Post subject: Reply with quote

Sounds like it will be a big and exspensive task aslo i am currently just toying with xcache and a joomla 3.x install.

Code:
[xcache-common]
extension = php_xcache.dll

[xcache]
xcache.shm_scheme =        "mmap"
xcache.size  =               128M
xcache.count =                 1
xcache.cacher =               On
xcache.stat   =               On
xcache.optimizer =            On


Those are my current settings anything you recommend i add or use instead ?

What do you use in a Xcache production enviorment.

These are my wincache settings. (Production) But now i know PHP drops all cached content every time it hits max requests i am thinking on changing ttlmax to '0' so that while the php process is running it never drops cached content until the process closes on max request.
Code:
extension=php_wincache.dll
wincache.ttlmax=7200
wincache.chkinterval=300
wincache.enablecli=1
wincache.rerouteini="reroute.ini"
wincache.fcenabled=1
wincache.maxfilesize=2048
wincache.ocenabled=1
wincache.ucenabled=1
wincache.filecount=16384
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Wed 11 Feb '15 16:43    Post subject: Reply with quote

In the next release I've added some xcache stuff;

php-xcache-example.ini
Code:
[PHP]


;; php.ini ..............near/at the end:

;; http://xcache.lighttpd.net/
;; http://xcache.lighttpd.net/wiki/ReleaseArchive
;; https://groups.google.com/forum/#!forum/xcache

[xcache-common]
extension = php_xcache.dll

[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "xuser"
; xcache.admin.pass = md5($your_password)
xcache.admin.pass = "blabla"

[xcache]
; select low level shm/allocator scheme implemenation
xcache.shm_scheme =        "mmap"
; to disable: xcache.size=0
; to enable : xcache.size=64M etc (any size > 0) and your system mmap allows
xcache.size  =               32M
; set to cpu count (cat /proc/cpuinfo |grep -c processor)
xcache.count =                 1
; just a hash hints, you can always store count(items) > slots
xcache.slots =                8K
; ttl of the cache item, 0=forever
xcache.ttl   =                 0
; interval of gc scanning expired items, 0=no scan, other values is in seconds
xcache.gc_interval =           0

; same as aboves but for variable cache
xcache.var_size  =            4M
xcache.var_count =             1
xcache.var_slots =            8K
xcache.var_ttl   =             0
xcache.var_maxttl   =          0
xcache.var_gc_interval =     300

; mode:0, const string specified by xcache.var_namespace
; mode:1, $_SERVER[xcache.var_namespace]
; mode:2, uid or gid (specified by xcache.var_namespace)
xcache.var_namespace_mode =    0
xcache.var_namespace =        ""

; N/A for /dev/zero
xcache.readonly_protection = Off
; for *nix, xcache.mmap_path is a file path, not directory.
; Use something like "/tmp/xcache" if you want to turn on ReadonlyProtection
; 2 group of php won't share the same /tmp/xcache
; for win32, xcache.mmap_path=anonymous map name, not file path
; xcache.mmap_path =    "/dev/zero"
xcache.mmap_path =    "xcachemmap"

; leave it blank(disabled) or "/tmp/phpcore/"
; make sure it's writable by php (open_basedir is not checked)
xcache.coredump_directory =   ""
; Windows only. leave it as 0 (default) until you're told by XCache dev
xcache.coredump_type =         0

; disable cache after crash
xcache.disable_on_crash =     Off
xcache.experimental =         Off

; per request settings
xcache.cacher =               On
xcache.stat   =               On
xcache.optimizer =            On

[xcache.coverager]
; per request settings
; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance)
xcache.coverager =            Off
xcache.coverager_autostart =  On

; ini only settings
; make sure it's readable (open_basedir is checked) by coverage viewer script
; requires xcache.coverager=On
xcache.coveragedump_directory = ""
Back to top
puertoblack2003



Joined: 31 Jul 2009
Posts: 76

PostPosted: Thu 12 Feb '15 6:35    Post subject: Reply with quote

can xcache run together with memcache?
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 876
Location: Amsterdam, NL, EU

PostPosted: Thu 12 Feb '15 9:38    Post subject: Re: PHP Caching extensions accessing shared memory Reply with quote

C0nw0nk wrote:
Are there any caches that pass the cache onto the next process, "shared memory access". ?

The Zend OPcache
================
The Zend OPcache provides faster PHP execution through opcode caching and optimization. It improves PHP performance by storing precompiled script bytecode in the shared memory.

https://github.com/zendtech/ZendOptimizerPlus
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Thu 12 Feb '15 14:29    Post subject: Reply with quote

Maybe, haven't tested it yet, but the big question is, when you load multiple php-cgi instances are those instances going to use 1 shared memory pool or not?

The basic xcache design is 1 master which spawns children who use the master shared memory pool, in Windows this doesn't work so you have to run X masters and loadbalance the workload between them (running on different ports) each using its own memory pool.

When using opcache the load(balance) mechanism is not going to change, so if opcache uses a shared pool between all instances who is going to 'master' the pool?
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 876
Location: Amsterdam, NL, EU

PostPosted: Thu 12 Feb '15 14:51    Post subject: Reply with quote

Yes, more instances of php-cgi share the same memory pool. As far as I know no one masters the pool. There is no need for that when you see the pool as a collection of precompiled PHP-files with an index.

Just try it and see what happens with https://github.com/rlerdorf/opcache-status

The caveat: you cannot use OPcache on Windows for different PHP-versions. I tried to achieve this by compling a php_opcache64.dll with another fixed address, but it never became stable enough for production. So at the moment I am using PHP 5.3 as mod_php with XCache (Drupal 6) alongside PHP 5.6.5 NTS as mod_fcgid with OPcache.

See also https://github.com/zendtech/ZendOptimizerPlus/issues/109#issuecomment-20572357


Last edited by Jan-E on Thu 12 Feb '15 21:52; edited 1 time in total
Back to top
C0nw0nk



Joined: 07 Oct 2013
Posts: 241
Location: United Kingdom, London

PostPosted: Thu 12 Feb '15 20:05    Post subject: Reply with quote

So isit worth downloading the latest (Also i only use the 64bit binaries.) http://windows.php.net/download/

5.6.x branch enabling
extension=php_opcache.dll

And to use that instead of wincache i suppose the reason they ship opcache inside the zip archive is because it must be using shared memory.

I also have to toy about and figure out the best settings for production with opcache in a high traffic enviorment.


Also reading the documentation am i suppose to set a mmap base name ?

http://php.net/manual/en/opcache.configuration.php#ini.opcache.mmap-base
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Thu 12 Feb '15 21:44    Post subject: Reply with quote

Well I switched over and so far so good.

Code:
[PHP]


;; php.ini ..............near/at the end:

;; http://php.net/manual/en/opcache.installation.php
;; https://github.com/zendtech/ZendOptimizerPlus

zend_extension=php_opcache.dll

[opcache]
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=8000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=0
opcache.enable_file_override=1


C0nw0nk wrote:
Also reading the documentation am i suppose to set a mmap base name ?

Nope.
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 876
Location: Amsterdam, NL, EU

PostPosted: Thu 12 Feb '15 21:46    Post subject: Reply with quote

Yes, it is worth downloading. Installation is with

zend_extension=php_opcache.dll

The dll is in the zip-file for every release because it is a core extension of PHP. It is the preferred opcaching extension by the PHP developers. Probably it will be enables by default in PHP7.

Just use the default parameters to start with. They are in the readme of https://github.com/zendtech/ZendOptimizerPlus
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Thu 12 Feb '15 22:15    Post subject: Reply with quote

Is there any way to find out the base address all instances are using to verify they all use the same space?
Back to top
Jan-E



Joined: 09 Mar 2012
Posts: 876
Location: Amsterdam, NL, EU

PostPosted: Thu 12 Feb '15 23:53    Post subject: Reply with quote

C:\>type c:\Windows\ZendOPcache.MemoryBase@SYSTEM
20000000

The mmap_base is stored in a semaphore file called ZendOPcache.MemoryBase*. The '20000000' in my semaphore file is the fixed value that is compiled into the x86 opcache.dll:
https://github.com/zendtech/ZendOptimizerPlus/blob/master/shared_alloc_win32.c#L188

With x64 Windows I have seen different values in the semaphore file after each reboot:
https://github.com/zendtech/ZendOptimizerPlus/issues/109#issuecomment-22377260

BTW: did you try opcache.php from Rasmus Lerdorf?
https://github.com/rlerdorf/opcache-status

Rasmus Lerdorf launched PHP 1.0 back in 1995:
https://groups.google.com/forum/#!topic/comp.infosystems.www.authoring.cgi/PyJ25gZ6z7A/overview
Back to top
ng4win



Joined: 25 May 2014
Posts: 78

PostPosted: Fri 13 Feb '15 0:26    Post subject: Reply with quote

Jan-E wrote:
C:\>type c:\Windows\ZendOPcache.MemoryBase@SYSTEM
20000000

Hmmm php does not have rights there to write anything so this file ain't there...
Quote:
With x64 Windows I have seen different values in the semaphore file after each reboot:
https://github.com/zendtech/ZendOptimizerPlus/issues/109#issuecomment-22377260

ASLR thing.
Quote:
BTW: did you try opcache.php from Rasmus Lerdorf?
https://github.com/rlerdorf/opcache-status

Yes using that one.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Other Software Goto page 1, 2, 3  Next
Page 1 of 3