Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measure consensus metrics for all events. #9604

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.swirlds.common.io.streams.SerializableDataOutputStream;
import com.swirlds.common.system.NodeId;
import com.swirlds.common.system.SoftwareVersion;
import com.swirlds.common.system.transaction.ConsensusTransaction;
import com.swirlds.common.system.transaction.internal.ConsensusTransactionImpl;
import com.swirlds.common.utility.CommonUtils;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -89,9 +88,6 @@ private static class ClassVersion {
/** the payload: an array of transactions */
private ConsensusTransactionImpl[] transactions;

/** are any of the transactions user transactions */
private boolean hasUserTransactions;

public BaseEventHashedData() {}

/**
Expand Down Expand Up @@ -131,7 +127,6 @@ public BaseEventHashedData(
this.otherParentHash = otherParentHash;
this.timeCreated = Objects.requireNonNull(timeCreated, "The timeCreated must not be null");
this.transactions = transactions;
checkUserTransactions();
}

/**
Expand Down Expand Up @@ -236,25 +231,6 @@ public void deserialize(
timeCreated = in.readInstant();
in.readInt(); // read serialized length
transactions = in.readSerializableArray(ConsensusTransactionImpl[]::new, maxTransactionCount, true);
checkUserTransactions();
}

/**
* Check if array of transactions has any user created transaction inside
*/
private void checkUserTransactions() {
if (transactions != null) {
for (final ConsensusTransaction t : getTransactions()) {
if (!t.isSystem()) {
hasUserTransactions = true;
break;
}
}
}
}

public boolean hasUserTransactions() {
return hasUserTransactions;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,6 @@ public boolean isCreatedBy(final NodeId id) {
return Objects.equals(getCreatorId(), id);
}

public boolean hasUserTransactions() {
return baseEvent.getHashedData().hasUserTransactions();
}

//////////////////////////////////////////
// BaseEventUnhashedData
//////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public class ConsensusMetricsImpl implements ConsensusMetrics {
private final NodeId selfId;

/**
* Time when this platform received the first event created by someone else in the most recent round.
* This is used to calculate Statistics.avgFirstEventInRoundReceivedTime which is "time for event, from
* receiving the first event in a round to the first event in the next round".
* Time when this platform received the first event created by someone else in the most recent round. This is used
* to calculate Statistics.avgFirstEventInRoundReceivedTime which is "time for event, from receiving the first event
* in a round to the first event in the next round".
*/
private static volatile Instant firstEventInLastRoundTime = null;
/**
Expand All @@ -126,12 +126,9 @@ public class ConsensusMetricsImpl implements ConsensusMetrics {
/**
* Constructor of {@code ConsensusMetricsImpl}
*
* @param selfId
* the {@link NodeId} of this node
* @param metrics
* a reference to the metrics-system
* @throws IllegalArgumentException
* if one of the parameters is {@code null}
* @param selfId the {@link NodeId} of this node
* @param metrics a reference to the metrics-system
* @throws IllegalArgumentException if one of the parameters is {@code null}
*/
public ConsensusMetricsImpl(final NodeId selfId, final Metrics metrics) {
this.selfId = CommonUtils.throwArgNull(selfId, "selfId");
Expand Down Expand Up @@ -213,34 +210,24 @@ public void consensusReached(final EventImpl event) {
// Keep a running average of how many seconds from when I first know of an event
// until it achieves consensus. Actually, keep two such averages: one for events I
// create, and one for events I receive.
// Because of transThrottle, these statistics can end up being misleading, so we are only tracking events that
// have user transactions in them.
if (event.hasUserTransactions()) {
if (Objects.equals(selfId, event.getCreatorId())) { // set either created or received time to now
avgCreatedConsensusTime.update(
event.getBaseEvent().getTimeReceived().until(Instant.now(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
} else {
avgReceivedConsensusTime.update(
event.getBaseEvent().getTimeReceived().until(Instant.now(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
avgCreatedReceivedConsensusTime.update(
event.getTimeCreated().until(Instant.now(), ChronoUnit.NANOS) * NANOSECONDS_TO_SECONDS);
}
if (Objects.equals(selfId, event.getCreatorId())) {
avgCreatedConsensusTime.update(
event.getBaseEvent().getTimeReceived().until(Instant.now(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
} else {
avgReceivedConsensusTime.update(
event.getBaseEvent().getTimeReceived().until(Instant.now(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
avgCreatedReceivedConsensusTime.update(
event.getTimeCreated().until(Instant.now(), ChronoUnit.NANOS) * NANOSECONDS_TO_SECONDS);
}

// Because of transThrottle, these statistics can end up being misleading, so we are only tracking events that
// have user transactions in them.
if (event.hasUserTransactions()) {
if (Objects.equals(selfId, event.getCreatorId())) {
avgSelfCreatedTimestamp.update(
event.getTimeCreated().until(event.getConsensusTimestamp(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
} else {
avgOtherReceivedTimestamp.update(
event.getBaseEvent().getTimeReceived().until(event.getConsensusTimestamp(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
}
if (Objects.equals(selfId, event.getCreatorId())) {
avgSelfCreatedTimestamp.update(event.getTimeCreated().until(event.getConsensusTimestamp(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
} else {
avgOtherReceivedTimestamp.update(
event.getBaseEvent().getTimeReceived().until(event.getConsensusTimestamp(), ChronoUnit.NANOS)
* NANOSECONDS_TO_SECONDS);
}
}

Expand Down
Loading