cassandra icon indicating copy to clipboard operation
cassandra copied to clipboard

CNDB-9821 Auto sync RequestSensors increments to SensorsRegistry

Open aymkhalil opened this issue 1 year ago • 1 comments

Proposal #1 for https://github.com/riptano/cndb/issues/9821

  • Deprecated the SensorsRegister#syncAllSensors. Instead, automatically synchronize sensors increments via RequestSensors#incrementThenSyncSensor.
  • Use DoubleAdder instead of AtomicDouble to reduce thread contention on updates.
  • Add a simple RequestSensorsBench to benchmark public APIs.

Based on benchmark results, the RequestSensors#incrementThenSyncSensor followed by a sensor read from the registry has the below throughout:

Benchmark                       Mode  Cnt       Score       Error  Units
RequestSensorsBench.increment  thrpt    5  509069.346 ± 32108.453  ops/s

It is worth noting that the switch from AtomicDouble to DoubleAdder didn't have significant improvement in terms of throughput, but it is safe to assume there is 1:M ration between reading from and writing to sensors registry per request which is what DoubleAdder is meant for (however we may need 1<<M to experience the benefits)

However the same functionally if we were to add SensorsRegister#syncAllSensors (benchmark code below) is:

Benchmark                       Mode  Cnt     Score     Error  Units
RequestSensorsBench.increment  thrpt    5  9197.702 ± 944.301  ops/s
@Benchmark
@Threads(50)
public void syncAllSensors()
{
    // pick a sensor at random
    Type type = Type.values()[(int) (Math.random() * Type.values().length)];
    int sensorIndex = (int) (Math.random() * NUM_SENSORS);
    Context context = new Context("keyspace", "table" + sensorIndex, "tableId" + sensorIndex);
    requestSensors.incrementSensor(context, type, Math.random());
    requestSensors.syncAllSensors();
    SensorsRegistry.instance.getSensor(context, type).ifPresent(Sensor::getValue);
}

aymkhalil avatar Jun 17 '24 22:06 aymkhalil

Closed in favor of https://github.com/datastax/cassandra/pull/1184

aymkhalil avatar Aug 13 '24 15:08 aymkhalil