CNDB-9821 Auto sync RequestSensors increments to SensorsRegistry
Proposal #1 for https://github.com/riptano/cndb/issues/9821
- Deprecated the
SensorsRegister#syncAllSensors. Instead, automatically synchronize sensors increments viaRequestSensors#incrementThenSyncSensor. - Use
DoubleAdderinstead ofAtomicDoubleto reduce thread contention on updates. - Add a simple
RequestSensorsBenchto 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);
}
Quality Gate passed
Issues
2 New issues
0 Accepted issues
Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code
Closed in favor of https://github.com/datastax/cassandra/pull/1184