org.hd.d.pg2k.ai.scorer
Class ScorerCreator.ScorerWork

java.lang.Object
  extended by org.hd.d.pg2k.ai.scorer.ScorerCreator.ScorerWork
Enclosing class:
ScorerCreator

public static final class ScorerCreator.ScorerWork
extends java.lang.Object

Class to encapsulate all background and evolution work for a given ScorerCache. The doChunk() entry point is designed to be thread-safe and highly threadable, ie can be called from multiple worker threads at once.


Field Summary
private  boolean allowScorerSharingByEvent
          If true, then we try to retrieve persisted/shared Scorers from the system variables event mechanism.
private  java.util.concurrent.atomic.AtomicLong excessSlowTimeNs
          Excess time spent running slow evolution methods (ns).
private  SimpleLoggerIF log
          Logger; never null.
private  AbstractScorerCache scorerCache
          Underlying Scorer cache; never null.
 
Constructor Summary
ScorerCreator.ScorerWork(AbstractScorerCache scorerCache, SimpleLoggerIF log, boolean allowScorerSharingByEvent)
          Create instance.
 
Method Summary
 void doChunk(long endTime, long minEndTime, boolean special, java.util.Queue<java.lang.String> inboundEval)
          Run one chunk of work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scorerCache

private final AbstractScorerCache scorerCache
Underlying Scorer cache; never null.


log

private final SimpleLoggerIF log
Logger; never null.


allowScorerSharingByEvent

private final boolean allowScorerSharingByEvent
If true, then we try to retrieve persisted/shared Scorers from the system variables event mechanism.


excessSlowTimeNs

private final java.util.concurrent.atomic.AtomicLong excessSlowTimeNs
Excess time spent running slow evolution methods (ns). In order to attempt to balance the amount of time spent on different methods of generating new Scorers, given that they can be orders of magnitude apart in execution time, we attempt to balance the total run-time they take.

This is increased by the execution time of each "slow" instance and decreased by the execution time of each "fast" instance. Slow methods may only start when it is negative, fast ones otherwise.

Run-time for "failed" executions may or may not be included.

This starts at zero, and the effect of the "fair share" scheduling that this controls should be to keep it as close to zero (on either side of zero) as possible.

This is thread-safe.

Constructor Detail

ScorerCreator.ScorerWork

public ScorerCreator.ScorerWork(AbstractScorerCache scorerCache,
                                SimpleLoggerIF log,
                                boolean allowScorerSharingByEvent)
Create instance.

Parameters:
scorerCache - cache of Scorers to work with; never null
log - logger; never null
allowScorerSharingByEvent - if true, then we try to retrieve persisted/shared Scorers from the system variables event mechanism
Method Detail

doChunk

public final void doChunk(long endTime,
                          long minEndTime,
                          boolean special,
                          java.util.Queue<java.lang.String> inboundEval)
Run one chunk of work. Note that if the minTime or minEndTime values are not more than 1ms beyond 'now' then this avoids computations that are likely to require especially large amounts of CPU time/effort.

Parameters:
special - if true, do extra background work and normal work
inboundEval - if non-null then is queue of externally-supplied Scorers to evaluate and insert into the population if appropriate; these are regarded as potentially untrusted so are validated and canonicalised before use
endTime - target end time for this chunk of work to stop by
minEndTime - time before which we should not stop (ie target minimum quantum)

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.