Skip to content

Commit

Permalink
[transaction-manager] compute transaction latency metric
Browse files Browse the repository at this point in the history
  • Loading branch information
je-ik committed Jan 20, 2025
1 parent 789fc53 commit 209d390
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/cz/o2/proxima/core/transaction/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ public State aborted() {
return new State(
sequentialId, stamp, Flags.ABORTED, getInputAttributes(), Collections.emptySet());
}

public boolean isFinal() {
return this.flags == Flags.COMMITTED || this.flags == Flags.ABORTED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package cz.o2.proxima.direct.transaction.manager;

import cz.o2.proxima.core.metrics.ApproxPercentileMetric;
import cz.o2.proxima.core.metrics.GaugeMetric;
import cz.o2.proxima.core.metrics.MetricFactory;
import cz.o2.proxima.core.metrics.TimeAveragingMetric;
Expand Down Expand Up @@ -46,6 +47,10 @@ public class Metrics {
private final TimeAveragingMetric transactionsRolledBack =
factory.timeAveraging(GROUP, "transactions_rolled_back", 1_000);

@Getter
private final ApproxPercentileMetric transactionLatency =
factory.percentile(GROUP, "transactions_latency", 300_000, 5_000);

@Getter private final GaugeMetric numWritesCached = factory.gauge(GROUP, "writes_cached");

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ private void processTransactionUpdateRequest(
State newState = transitionState(transactionId, currentState, request);
monitoringPolicy.stateUpdate(transactionId, currentState, newState);
Response response = getResponseForNewState(request, currentState, newState);
if (newState.isFinal()) {
metrics.getTransactionLatency().increment(currentTimeMillis() - newState.getStamp());
}
// we have successfully computed new state, produce response
log.info(
"Transaction {} transitioned due to {} from state {} to state {}, returning {}",
Expand Down

0 comments on commit 209d390

Please sign in to comment.