Re: [PHP-DEV] Memory warning hook

2013-03-06 Thread Julien Pauli
One should try ext/memtrack http://pecl.php.net/package/memtrack

Also ext/memprof https://github.com/arnaud-lb/php-memory-profiler/

Julien.Pauli

On Tue, Mar 5, 2013 at 9:14 PM,  wrote:

> >This is not the same at all. When are you going to run this code? Memory
> allocations happen all the time. What Nathan asked for is an event that is
> triggered when the memory consumption reaches a >threshold.
> >
> >However, there is a different solution, which is better IMHO in the case
> of
> >caches: weak references. A weak reference automatically frees the memory
> of the object, when the memory is needed.
> >http://php.net/manual/en/book.weakref.php.
> >
> >Having said that, none of these solutions scale up to multiple servers.
> >This is why shared cache systems like memcached are recommended.
>
> I agree this probably is a good solution and I personally do use it along
> with shared memory tools, however there may be cases where the dev may gain
> more benefit from having a memory-warning installable trigger in place.
> This would allow things like allowing the dev to release certain cache
> objects before others or something completely different that I have not
> thought of yet.
>
> > Running the GC is most likely faster than most cleanup routines a user
> could run, also usually there is not that much stuff cached in PHP scripts.
> If a PHP script has "tons" of data, which it can easily throw >away, in
> memory this sounds like a smell of an bad architecture. Cache cache-worthy
> stuff in memcache or such and fetch only the data you need.
> >
> >Also: What should happen if the system runs out of memory while doing the
> cleanup? Anything sane doesn't sound good either.
> Yes running the GC is much faster except they are two completely different
> processes... in my example the dev is keeping references to data for
> possible future use later on however it's not possible to know when to
> release these references so php's GC can collect them if the user does not
> implement something quite juristic like ticks or frequent function calls
> throughout a code base.
>
> >You can use ticks :)
> >
> >
> http://php.net/control-structures.declare#control-structures.declare.ticks
>
> Yes Ticks are something useable (like said above) however I have found
> ticks are clunky, frequently shunned, and you'd be ticking for no reason
> most of the time.
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


RE: [PHP-DEV] Memory warning hook

2013-03-05 Thread nathan
>This is not the same at all. When are you going to run this code? Memory 
>allocations happen all the time. What Nathan asked for is an event that is 
>triggered when the memory consumption reaches a >threshold.
>
>However, there is a different solution, which is better IMHO in the case of
>caches: weak references. A weak reference automatically frees the memory of 
>the object, when the memory is needed.
>http://php.net/manual/en/book.weakref.php.
>
>Having said that, none of these solutions scale up to multiple servers.
>This is why shared cache systems like memcached are recommended.

I agree this probably is a good solution and I personally do use it along with 
shared memory tools, however there may be cases where the dev may gain more 
benefit from having a memory-warning installable trigger in place. This would 
allow things like allowing the dev to release certain cache objects before 
others or something completely different that I have not thought of yet.

> Running the GC is most likely faster than most cleanup routines a user could 
> run, also usually there is not that much stuff cached in PHP scripts. If a 
> PHP script has "tons" of data, which it can easily throw >away, in memory 
> this sounds like a smell of an bad architecture. Cache cache-worthy stuff in 
> memcache or such and fetch only the data you need.
>
>Also: What should happen if the system runs out of memory while doing the 
>cleanup? Anything sane doesn't sound good either.
Yes running the GC is much faster except they are two completely different 
processes... in my example the dev is keeping references to data for possible 
future use later on however it's not possible to know when to release these 
references so php's GC can collect them if the user does not implement 
something quite juristic like ticks or frequent function calls throughout a 
code base.

>You can use ticks :)
>
>http://php.net/control-structures.declare#control-structures.declare.ticks

Yes Ticks are something useable (like said above) however I have found ticks 
are clunky, frequently shunned, and you'd be ticking for no reason most of the 
time.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Memory warning hook

2013-03-05 Thread Sebastian Krebs
2013/3/5 Lazare Inepologlou 

> 2013/3/5 Tom Boutell 
>
> > Can't you do this already? memory_limit can be fetched via ini_read,
> > and together with memory_get_usage you should be able to check for
> > this sort of thing. Admittedly having to parse memory_limit (which can
> > be in various units) is not perfect.
> >
>
> This is not the same at all. When are you going to run this code? Memory
> allocations happen all the time. What Nathan asked for is an event that is
> triggered when the memory consumption reaches a threshold.
>

You can use ticks :)

http://php.net/control-structures.declare#control-structures.declare.ticks



>
> However, there is a different solution, which is better IMHO in the case of
> caches: weak references. A weak reference automatically frees the memory of
> the object, when the memory is needed.
> http://php.net/manual/en/book.weakref.php.
>
> Having said that, none of these solutions scale up to multiple servers.
> This is why shared cache systems like memcached are recommended.
>

Well, maybe I don't understand, what you are trying to tell, but if you run
out of memory, this of course only affects one server on its own.


>
>
>
>
> > On Tue, Mar 5, 2013 at 1:23 PM,   wrote:
> > > As PHP applications are turning into large frameworks one of the issues
> > > arriving is memory management. One of the issues is that many
> frameworks
> > use
> > > sophisticated caching techniques to make accessing the same data
> quickly,
> > > this improves speed it is at the cost of memory. Often the developer
> > knows
> > > these areas that cache and often times already have functions in place
> to
> > > clear out the cache, however in the case where PHP is approaching or
> > exceeds
> > > memory limits PHP runs the GC then dies if it cannot allocate enough
> > memory.
> > > If we implemented "memory warning" triggers or user function that will
> be
> > > called before the GC is executed which allows the user to try and free
> up
> > > some memory on their own. This hopefully would give more flexibility to
> > > allowing these advanced caching techniques but at the same time allow
> the
> > > cache to be cleared out in case memory is getting low.
> > >
> > >
> > >
> > > Thoughts?
> > >
> > >
> > >
> > > Thanks,
> > >
> > > Software Developer
> > >
> > > Nathan Bruer
> > >
> > >
> > >
> >
> >
> >
> > --
> > Tom Boutell
> > P'unk Avenue
> > 215 755 1330
> > punkave.com
> > window.punkave.com
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> Lazare INEPOLOGLOU
> Ingénieur Logiciel
>



-- 
github.com/KingCrunch


Re: [PHP-DEV] Memory warning hook

2013-03-05 Thread Lazare Inepologlou
2013/3/5 Tom Boutell 

> Can't you do this already? memory_limit can be fetched via ini_read,
> and together with memory_get_usage you should be able to check for
> this sort of thing. Admittedly having to parse memory_limit (which can
> be in various units) is not perfect.
>

This is not the same at all. When are you going to run this code? Memory
allocations happen all the time. What Nathan asked for is an event that is
triggered when the memory consumption reaches a threshold.

However, there is a different solution, which is better IMHO in the case of
caches: weak references. A weak reference automatically frees the memory of
the object, when the memory is needed.
http://php.net/manual/en/book.weakref.php.

Having said that, none of these solutions scale up to multiple servers.
This is why shared cache systems like memcached are recommended.




> On Tue, Mar 5, 2013 at 1:23 PM,   wrote:
> > As PHP applications are turning into large frameworks one of the issues
> > arriving is memory management. One of the issues is that many frameworks
> use
> > sophisticated caching techniques to make accessing the same data quickly,
> > this improves speed it is at the cost of memory. Often the developer
> knows
> > these areas that cache and often times already have functions in place to
> > clear out the cache, however in the case where PHP is approaching or
> exceeds
> > memory limits PHP runs the GC then dies if it cannot allocate enough
> memory.
> > If we implemented "memory warning" triggers or user function that will be
> > called before the GC is executed which allows the user to try and free up
> > some memory on their own. This hopefully would give more flexibility to
> > allowing these advanced caching techniques but at the same time allow the
> > cache to be cleared out in case memory is getting low.
> >
> >
> >
> > Thoughts?
> >
> >
> >
> > Thanks,
> >
> > Software Developer
> >
> > Nathan Bruer
> >
> >
> >
>
>
>
> --
> Tom Boutell
> P'unk Avenue
> 215 755 1330
> punkave.com
> window.punkave.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Lazare INEPOLOGLOU
Ingénieur Logiciel


Re: [PHP-DEV] Memory warning hook

2013-03-05 Thread Johannes Schlüter
On Tue, 2013-03-05 at 12:23 -0600, nat...@starin.biz wrote:
> As PHP applications are turning into large frameworks one of the issues
> arriving is memory management. One of the issues is that many frameworks use
> sophisticated caching techniques to make accessing the same data quickly,
> this improves speed it is at the cost of memory. Often the developer knows
> these areas that cache and often times already have functions in place to
> clear out the cache, however in the case where PHP is approaching or exceeds
> memory limits PHP runs the GC then dies if it cannot allocate enough memory.
> If we implemented "memory warning" triggers or user function that will be
> called before the GC is executed which allows the user to try and free up
> some memory on their own. This hopefully would give more flexibility to
> allowing these advanced caching techniques but at the same time allow the
> cache to be cleared out in case memory is getting low.

Running the GC is most likely faster than most cleanup routines a user
could run, also usually there is not that much stuff cached in PHP
scripts. If a PHP script has "tons" of data, which it can easily throw
away, in memory this sounds like a smell of an bad architecture. Cache
cache-worthy stuff in memcache or such and fetch only the data you need.

Also: What should happen if the system runs out of memory while doing
the cleanup? Anything sane doesn't sound good either.

johannes



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Memory warning hook

2013-03-05 Thread Tom Boutell
Can't you do this already? memory_limit can be fetched via ini_read,
and together with memory_get_usage you should be able to check for
this sort of thing. Admittedly having to parse memory_limit (which can
be in various units) is not perfect.

On Tue, Mar 5, 2013 at 1:23 PM,   wrote:
> As PHP applications are turning into large frameworks one of the issues
> arriving is memory management. One of the issues is that many frameworks use
> sophisticated caching techniques to make accessing the same data quickly,
> this improves speed it is at the cost of memory. Often the developer knows
> these areas that cache and often times already have functions in place to
> clear out the cache, however in the case where PHP is approaching or exceeds
> memory limits PHP runs the GC then dies if it cannot allocate enough memory.
> If we implemented "memory warning" triggers or user function that will be
> called before the GC is executed which allows the user to try and free up
> some memory on their own. This hopefully would give more flexibility to
> allowing these advanced caching techniques but at the same time allow the
> cache to be cleared out in case memory is getting low.
>
>
>
> Thoughts?
>
>
>
> Thanks,
>
> Software Developer
>
> Nathan Bruer
>
>
>



-- 
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Memory warning hook

2013-03-05 Thread nathan
As PHP applications are turning into large frameworks one of the issues
arriving is memory management. One of the issues is that many frameworks use
sophisticated caching techniques to make accessing the same data quickly,
this improves speed it is at the cost of memory. Often the developer knows
these areas that cache and often times already have functions in place to
clear out the cache, however in the case where PHP is approaching or exceeds
memory limits PHP runs the GC then dies if it cannot allocate enough memory.
If we implemented "memory warning" triggers or user function that will be
called before the GC is executed which allows the user to try and free up
some memory on their own. This hopefully would give more flexibility to
allowing these advanced caching techniques but at the same time allow the
cache to be cleared out in case memory is getting low.

 

Thoughts?

 

Thanks,

Software Developer

Nathan Bruer