eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'AbstractAnnealingCounter':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: AbstractAnnealingCounter


Inheritance:

   Object
   |
   +--AbstractAnnealingCounter
      |
      +--AnnealingCounter

Package:
stx:libbasic2
Category:
Collections-Support
Version:
rev: 1.3 date: 2023/11/15 07:00:06
user: cg
file: AbstractAnnealingCounter.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


a counter which decays over time;
useful to measure (i.e. count) events and give
recent events more weight than older ones.

For example, to measure hot spots in code, by counting calls
(where we want to forget old calls) 
for profilers or to implement better LRU algorithms.

The counter decays older events at a rate of decayRate per timeInterval.

Notice:

The standard AnnealingCounter has per-instance configurable rate and interval,
which may use up too much memory if you need many (zillions) of them.
In that case, make a subclass, which provides those from a constant (class variable or getter).
Redefinable:
    decayRate     eg. 0.5
    timeInterval  eg. 1 seconds
    now           eg. Timestamp now

For example, to use simulated clock ticks,
redefine >>timeInterval to return the integer 1,
and >>now to return whatever your (simulated clock) tick is.

copyright

COPYRIGHT (c) 2023 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

defaults
o  defaultDecayRate

o  defaultTimeInterval

instance creation
o  decayRate: decayRate interval: interval
an annealingCounter, which decays
at a rate of decayRate per interval

o  new
a default annealingCounter

queries
o  isAbstract
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.


Instance protocol:

accessing
o  increment
increment the counter

o  value
return the counter's current value

accessing-behavior
o  decayRate
a fallback

o  decayRate: decayRate

** This method must be redefined in concrete classes (subclassResponsibility) **

o  decayRate: decayRate interval: interval

o  interval
a fallback

o  interval: interval

** This method must be redefined in concrete classes (subclassResponsibility) **

o  now
by default, we use the real time

initialization
o  initialize
(comment from inherited method)
just to ignore initialize to objects which do not need it


Examples:


a counter which decays to 1/2 every second;
measure an event at t=1, t=5 and t=6, and fetch its value at t=7.

  |cnt|

  cnt := AnnealingCounter new.
  cnt decayRate:0.5.
  Delay waitForSeconds:1.
  cnt increment.
  Delay waitForSeconds:4.
  cnt increment.
  Delay waitForSeconds:1.
  cnt increment.
  Delay waitForSeconds:1.
  cnt value.   


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:16:14 GMT