org.apache.cassandra.service

## Class PBSPredictor

- java.lang.Object
- - org.apache.cassandra.service.PBSPredictor

- All Implemented Interfaces:
    PBSPredictorMBean

      public class PBSPredictor
      extends java.lang.Object
      implements PBSPredictorMBean

  Performs latency and consistency predictions as described in "Probabilistically Bounded Staleness for Practical Partial Quorums" by Bailis et al. in VLDB 2012. The predictions are of the form:

  With ReplicationFactor `N`, read consistency level of `R`, and write consistency level `W`, after `t` seconds, `p`% of reads will return a version within `k` versions of the last written; this should result in a latency of `L` ms.

  These predictions should be used as a rough guideline for system operators. This interface is exposed through nodetool.

  The class accomplishes this by measuring latencies for reads and writes, then using Monte Carlo simulation to predict behavior under a given N,R, and W based on those latencies.

  We capture four distributions:

  - `W`: time from when the coordinator sends a mutation to the time that a replica begins to serve the new value(s)

  - `A`: time from when a replica accepting a mutation sends an acknowledgment to the time the coordinator hears of it

  - `R`: time from when the coordinator sends a read request to the time that the replica performs the read

  - `S`: time from when the replica sends a read response to the time when the coordinator receives it

  `A` and `S` are mostly network-bound, while W and R depend on both the network and local processing time.

  Caveats: Prediction is only as good as the latencies collected. Accurate prediction requires synchronizing clocks between replicas. We collect a running sample of latencies, but, if latencies change dramatically, predictions will be off.

  The predictions are conservative, or worst-case, meaning we may predict more staleness than in practice in the following ways:
  - We do not account for read repair.
  - We do not account for Merkle tree exchange.
  - Multi-version staleness is particularly conservative.
  - We simulate non-local reads and writes. We assume that the coordinating Cassandra node is not itself a replica for a given key.

  The predictions are optimistic in the following ways:
  - We do not predict the impact of node failure.
  - We do not model hinted handoff.
  See Also:
    `ConsistencyLevel`, `AbstractReplicationStrategy`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `MBEAN_NAME`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `disableConsistencyPredictionLogging()`
    `PBSPredictionResult` | `doPrediction(int n, int r, int w, float timeSinceWrite, int numberVersionsStale, float percentileLatency)`
    `void` | `enableConsistencyPredictionLogging()`
    `void` | `init()`
    `static PBSPredictor` | `instance()`
    `boolean` | `isLoggingEnabled()`
    `void` | `logReadResponse(java.lang.String id, long constructionTime)`
    `void` | `logReadResponse(java.lang.String id, long responseCreationTime, long receivedTime)`
    `void` | `logWriteResponse(java.lang.String id, long constructionTime)`
    `void` | `logWriteResponse(java.lang.String id, long responseCreationTime, long receivedTime)`
    `void` | `setMaxLoggedLatenciesForConsistencyPrediction(int maxLogged)`
    `void` | `setNumberTrialsForConsistencyPrediction(int numTrials)`
    `void` | `startReadOperation(java.lang.String id)`
    `void` | `startReadOperation(java.lang.String id, long startTime)`
    `void` | `startWriteOperation(java.lang.String id)`
    `void` | `startWriteOperation(java.lang.String id, long startTime)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MBEAN_NAME

          public static final java.lang.String MBEAN_NAME

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### instance

          public static PBSPredictor instance()

    - #### enableConsistencyPredictionLogging

          public void enableConsistencyPredictionLogging()

      Specified by:
        `enableConsistencyPredictionLogging` in interface `PBSPredictorMBean`

    - #### disableConsistencyPredictionLogging

          public void disableConsistencyPredictionLogging()

      Specified by:
        `disableConsistencyPredictionLogging` in interface `PBSPredictorMBean`

    - #### isLoggingEnabled

          public boolean isLoggingEnabled()

    - #### setMaxLoggedLatenciesForConsistencyPrediction

          public void setMaxLoggedLatenciesForConsistencyPrediction(int maxLogged)

      Specified by:
        `setMaxLoggedLatenciesForConsistencyPrediction` in interface `PBSPredictorMBean`

    - #### setNumberTrialsForConsistencyPrediction

          public void setNumberTrialsForConsistencyPrediction(int numTrials)

      Specified by:
        `setNumberTrialsForConsistencyPrediction` in interface `PBSPredictorMBean`

    - #### init

          public void init()

    - #### doPrediction

          public PBSPredictionResult doPrediction(int n,
                                         int r,
                                         int w,
                                         float timeSinceWrite,
                                         int numberVersionsStale,
                                         float percentileLatency)

      Specified by:
        `doPrediction` in interface `PBSPredictorMBean`

    - #### startWriteOperation

          public void startWriteOperation(java.lang.String id)

    - #### startWriteOperation

          public void startWriteOperation(java.lang.String id,
                                 long startTime)

    - #### startReadOperation

          public void startReadOperation(java.lang.String id)

    - #### startReadOperation

          public void startReadOperation(java.lang.String id,
                                long startTime)

    - #### logWriteResponse

          public void logWriteResponse(java.lang.String id,
                              long constructionTime)

    - #### logWriteResponse

          public void logWriteResponse(java.lang.String id,
                              long responseCreationTime,
                              long receivedTime)

    - #### logReadResponse

          public void logReadResponse(java.lang.String id,
                             long constructionTime)

    - #### logReadResponse

          public void logReadResponse(java.lang.String id,
                             long responseCreationTime,
                             long receivedTime)

Copyright © 2014 The Apache Software Foundation