Re: too slow to unset big array (after mem fragment)
| From: | Xuefer Tinys | Date: | Sat, 22 Jan 2005 03:48:29 +0000 |
| Subject: | Re: too slow to unset big array (after mem fragment) | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207027@lists.php.net to get a copy of this message | ||
On Fri, 21 Jan 2005 11:49:30 -0800 (PST), Richard Lynch <ceo@l-i-e.com> wrote:
>
> Perhaps you could store all data with an index of time rounded off to
> minutes (hours, whatever).
>
> Example:
>
> <?php
> //15 minutes -- Change larger/smaller for more/less frequent purges
> $purge_time = 60 * 15
> $now = time();
>
> //purge old data:
> $old = floor($now - $purge_time) / $purge_time);
> unset($tracker[$old]);
>
> //store incoming data:
> $current = floor($now / $purge_time);
> $tracker[$current][...whatever you use now...] = ...data...;
> ?>
looks good for GC, but seems bad for "in USE"
whenever there's an incoming new data which is not set in
$tracker[$current][...whatever you use now...], i have to go through
back all chunks of $tracker[] to archive "1hour tracking" effect
for $tracker[...]['site.view'][$siteid], only the first click is new,
cos they click same site
but for $tracker[...]['thread.view'][$threadid], almost all clicks is
new, cos they don't read same thread
each time i roll chunk, current online users make
$tracker[...]['site.view'][$siteid] is double from chunk[new-1] to
chunk[new]
too freq make it too many copies
but i'd guess it's ok for 'thread.view', "cos they don't read same
thread", no double
imagine if u guys write ip tracked(1 ip 1 view) counter, how will u
write the daemon?
database is slow imho
> If you make the $purge_time *TOO* small, smaller than the frequency with
> which the loop runs, then old data will get "missed" and never purged.
no problem, i can do
$expred = floor((time() - 1hour)/$pure_time);
reset(..)
while(list ... each())
break if $key >= not expired