Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2327] Notify of dropped messages #1156

Merged
merged 7 commits into from
Mar 28, 2019

Conversation

rojotek
Copy link
Member

@rojotek rojotek commented Mar 22, 2019

Added ability to subscribe to dropped transactions from the transaction pending pool.
Implemented subscription webservice to support this.
Added metrics to the pending transactions, tracking the number of local and remote transactions in the pool.

@rojotek rojotek changed the title Notify of dropped messages [PAN-2327] Notify of dropped messages Mar 22, 2019
@@ -54,25 +58,61 @@
private final Collection<PendingTransactionListener> listeners =
newSetFromMap(new ConcurrentHashMap<>());

private final Collection<PendingTransactionDroppedListener> transactionDroppedListeners =
newSetFromMap(new ConcurrentHashMap<>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this please use the Subscribers class? It's specifically designed to be the pattern for tracking listeners.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"remoteTransactionCounter",
"count of remote created transactions in the pending transaction pool",
"taskName")
.labels(getClass().getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These metrics aren't quite right. I'd suggest:

final LabelledMetric<Counter> transactionCounter = metricsSystem
    .createLabelledCounter(
    MetricCategory.TRANSACTION_POOL,
    "transactions_total",
    "Total number of transactions added to the pending transaction pool",
    "source");

this.localTransactionCounter = transactionCounter.label("local");
this.remoteTransactionCounter = transactionCounter.label("remote");

We don't need or want the class name in the metrics at all and the advantage of using a single labelled metric for both local and remote is it indicates that these are very related (its easy to add them together to see all transactions).

if (removedTransactionInfo.isReceivedFromLocalSource()) {
localTransactionCounter.inc(-1);
} else {
remoteTransactionCounter.inc(-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Counters should never be decremented, they only go up. We should have a separate "transactions_dropped_total" counter that we increment here (probably with a "source" label for local & remote).


for (final Subscription subscription : subscriptions) {
subscriptionManager.sendMessage(
subscription.getId(), new PendingTransactionResult(pendingTransaction));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create the PendingTransactionResult once and reuse it to send to each subscription?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can just simplify the metrics a bit.

final String addedToBlock) {
transactionRemovedCounters.put(
new DecrementTransactionKey("local".equals(source), "addedToBlock".equals(addedToBlock)),
transactionCounter.labels(source, "removed", addedToBlock));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've probably over-optimised this (probably because of my previous suggestions, sorry). It's ok to call .labels multiple times. It's very slightly faster if you can just store the result like with localTransactionAddedCounter and removeTransactionAddedCounter. Given there's both a local/remote and addedToBlock/dropped axis, I'd just store the LabelledMetric<Counter> and then when you need to increment call .labels(...).inc(). The indirection of looking up in a map likely nullifies any benefit to the caching.

@rojotek rojotek force-pushed the notify-of-dropped-messages branch 2 times, most recently from 647db57 to 247fc44 Compare March 27, 2019 23:47
@rojotek rojotek merged commit 9e7c966 into PegaSysEng:master Mar 28, 2019
@rojotek rojotek deleted the notify-of-dropped-messages branch March 28, 2019 10:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants