Tabnine Logo
ThreadLocalDirectory
Code IndexAdd Tabnine to your IDE (free)

How to use
ThreadLocalDirectory
in
com.yahoo.concurrent

Best Java code snippets using com.yahoo.concurrent.ThreadLocalDirectory (Showing top 11 results out of 315)

origin: com.yahoo.vespa/vespajlib

/**
 * Input data from a producer thread.
 *
 * @param x
 *            the data to insert
 */
public void update(SAMPLE x) {
  update(x, getOrCreateLocal());
}
origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  Result r;
  long when = query.getStartTime() / 1000L;
  Hit meta = null;
  directory.update(when);
  if (useMetaHit) {
    if (query.properties().getBoolean(propertyName, false)) {
      List<QueryRatePerSecond> l = merge(directory.fetch());
      Tuple2<Integer, Double> maxAndMean = maxAndMean(l);
      meta = new QpsHit(maxAndMean.first, maxAndMean.second);
    }
  }
  r = execution.search(query);
  if (meta != null) {
    r.hits().add(meta);
  }
  return r;
}
origin: com.yahoo.vespa/simplemetrics

/**
 * Update a metric. This API is not intended for clients for the
 * simplemetrics API, declare a Counter or a Gauge using
 * {@link #declareCounter(String)}, {@link #declareCounter(String, Point)},
 * {@link #declareGauge(String)}, or {@link #declareGauge(String, Point)}
 * instead.
 *
 * @param s
 *            a single simple containing all meta data necessary to update a
 *            metric
 */
public void update(Sample s) {
  // pass around the receiver instead of histogram settings to avoid reading any volatile if unnecessary
  s.setReceiver(this);
  metricsCollection.update(s);
}
origin: com.yahoo.vespa/simplemetrics

private Bucket updateBuffer() {
  List<Bucket> buckets = metricsCollection.fetch();
  final long toMillis = System.currentTimeMillis();
  final int bucketIndex = generation++ % buffer.length;
  Bucket bucketToDelete = buffer[bucketIndex];
  Bucket latest = new Bucket(fromMillis, toMillis);
  for (Bucket b : buckets) {
    latest.merge(b, true);
  }
  buffer[bucketIndex] = latest;
  this.fromMillis = toMillis;
  return bucketToDelete;
}
origin: com.yahoo.vespa/container-search

static ThreadLocalDirectory<Deque<QueryRatePerSecond>, Long> createDirectory() {
  return new ThreadLocalDirectory<>(new QueryRate());
}
origin: com.yahoo.vespa/vespajlib

/**
 * Expose the thread local for the running thread, for use in conjunction
 * with update(SAMPLE, LocalInstance&lt;AGGREGATOR, SAMPLE&gt;).
 *
 * @return the current thread's local instance
 */
public LocalInstance<AGGREGATOR, SAMPLE> getLocalInstance() {
  return getOrCreateLocal();
}
origin: com.yahoo.vespa/vespajlib

/**
 * Update a value with a given thread local instance.
 *
 * <p>
 * If a producer thread is to insert a series of data, it is desirable to
 * limit the number of memory transactions to the theoretical minimum. Since
 * reading a thread local is the memory equivalence of reading a volatile,
 * it is then useful to avoid re-reading the running threads' input
 * instance. For this scenario, fetch the running thread's instance with
 * getLocalInstance(), and then insert the produced data with the multiple
 * calls necessary to update(SAMPLE, LocalInstance&lt;AGGREGATOR, SAMPLE&gt;).
 * </p>
 *
 * @param x
 *            the data to insert
 * @param localInstance
 *            the local data insertion instance
 */
public void update(SAMPLE x, LocalInstance<AGGREGATOR, SAMPLE> localInstance) {
  boolean isRegistered;
  isRegistered = localInstance.update(x, updater);
  if (!isRegistered) {
    put(localInstance);
  }
}
origin: com.yahoo.vespa/simplemetrics

/** gathers all data since last snapshot */
public Bucket getSnapshot() {
  final Bucket merged = new Bucket();
  for (Bucket b : collection.fetch()) {
    merged.merge(b, true);
  }
  return merged;
}
/** utility method for testing */
origin: com.yahoo.vespa/simplemetrics

public MockReceiver() {
  this(new ThreadLocalDirectory<>(new MetricUpdater()));
}
/** gathers all data since last snapshot */
origin: com.yahoo.vespa/container-search

  @Override
  public void run(Handle h, boolean firstRun) {
    List<Deque<QueryRatePerSecond>> data = directory.fetch();
    List<QueryRatePerSecond> chewed = merge(data);
    for (QueryRatePerSecond qps : chewed) {
      qpsStatistics.put((double) qps.howMany);
    }
  }
}
origin: com.yahoo.vespa/simplemetrics

private MetricManager(ManagerConfig settings, Updater<Bucket, Sample> updater) {
  log.log(LogLevel.CONFIG, "setting up simple metrics gathering." +
        " reportPeriodSeconds=" + settings.reportPeriodSeconds() +
        ", pointsToKeepPerMetric=" + settings.pointsToKeepPerMetric());
  metricsCollection = new ThreadLocalDirectory<>(updater);
  final AtomicReference<Bucket> currentSnapshot = new AtomicReference<>(null);
  executor = new ScheduledThreadPoolExecutor(1);
  // Fixed rate, not fixed delay, is it is not too important that each
  // bucket has data for exactly one second, but one should strive for
  // this.buffer to contain data for as close a period to the report
  // interval as possible
  executor.scheduleAtFixedRate(new MetricAggregator(metricsCollection, currentSnapshot, settings), 1, 1, TimeUnit.SECONDS);
  receiver = new MetricReceiver(metricsCollection, currentSnapshot);
}
com.yahoo.concurrentThreadLocalDirectory

Javadoc

A class for multiple producers and potentially multiple consumers (usually only one).

The consuming threads always unregisters the data producers when doing fetch(). This is the reason for having to do update through the directory. The reason for this is otherwise, we would either get reference leaks from registered objects belonging to dead threads if we did not unregister instances, otherwise the sampling thread would have to unregister the instance, and then we would create a memory relationship between all producing threads, which is exactly what this class aims to avoid.

A complete example from a test:

 
private static class SumUpdater implements ThreadLocalDirectory.Updater<Integer, Integer> { 
 @Override 
public Integer update(Integer current, Integer x) { 
return Integer.valueOf(current.intValue() + x.intValue()); 
} 
 @Override 
public Integer createGenerationInstance(Integer previous) { 
return Integer.valueOf(0); 
} 
} 
... then the producers does (where r is in instance of 
ThreadLocalDirectory)... 
 @Override 
public void run() { 
LocalInstance<Integer, Integer> s = r.getLocalInstance(); 
for (int i = 0; i < 500; ++i) { 
r.update(Integer.valueOf(i), s); 
} 
} 
... and the consumer... 
List<Integer> measurements = s.fetch() 

Invoking r.fetch() will produce a list of integers from all the participating threads at any time.

Refer to e.g. com.yahoo.search.statistics.PeakQpsSearcher for a production example.

Most used methods

  • update
    Update a value with a given thread local instance. If a producer thread is to insert a series of dat
  • <init>
  • fetch
    Fetch the current set of sampled data, and reset state of all thread local instances. The producer t
  • getOrCreateLocal
  • put

Popular in Java

  • Making http post requests using okhttp
  • runOnUiThread (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • onRequestPermissionsResult (Fragment)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Option (scala)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now