mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Changed rel no. ref. host to overall unique msg
Relative number of messages have been calculated against one random seed node. Now, these numbers are calculated against the total number of unique messages available on all seed nodes. Lets us judge whether seed nodes are in sync not only quantitatively but also qualitatively.
This commit is contained in:
parent
b357bb8540
commit
56f67e74e8
1 changed files with 18 additions and 29 deletions
|
@ -53,9 +53,9 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -90,27 +90,12 @@ public class P2PSeedNodeSnapshot extends P2PSeedNodeSnapshotBase {
|
||||||
private int proposalheight = daostateheight;
|
private int proposalheight = daostateheight;
|
||||||
private int blindvoteheight = daostateheight;
|
private int blindvoteheight = daostateheight;
|
||||||
|
|
||||||
/**
|
|
||||||
* Efficient way to count message occurrences.
|
|
||||||
*/
|
|
||||||
private class Counter {
|
|
||||||
private int value = 0;
|
|
||||||
|
|
||||||
int value() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void increment() {
|
|
||||||
value++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use a counter to do statistics.
|
* Use a counter to do statistics.
|
||||||
*/
|
*/
|
||||||
private class MyStatistics implements Statistics<Counter> {
|
private class MyStatistics implements Statistics<Set<Integer>> {
|
||||||
|
|
||||||
private final Map<String, Counter> buckets = new HashMap<>();
|
private final Map<String, Set<Integer>> buckets = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statistics create() {
|
public Statistics create() {
|
||||||
|
@ -123,12 +108,12 @@ public class P2PSeedNodeSnapshot extends P2PSeedNodeSnapshotBase {
|
||||||
// For logging different data types
|
// For logging different data types
|
||||||
String className = message.getClass().getSimpleName();
|
String className = message.getClass().getSimpleName();
|
||||||
|
|
||||||
buckets.putIfAbsent(className, new Counter());
|
buckets.putIfAbsent(className, new HashSet<>());
|
||||||
buckets.get(className).increment();
|
buckets.get(className).add(message.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Counter> values() {
|
public Map<String, Set<Integer>> values() {
|
||||||
return buckets;
|
return buckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,8 +173,8 @@ public class P2PSeedNodeSnapshot extends P2PSeedNodeSnapshotBase {
|
||||||
// report
|
// report
|
||||||
Map<String, String> report = new HashMap<>();
|
Map<String, String> report = new HashMap<>();
|
||||||
// - assemble histograms
|
// - assemble histograms
|
||||||
bucketsPerHost.forEach((host, statistics) -> statistics.values().forEach((type, counter) -> report
|
bucketsPerHost.forEach((host, statistics) -> statistics.values().forEach((type, set) -> report
|
||||||
.put(OnionParser.prettyPrint(host) + ".numberOfMessages." + type, String.valueOf(((Counter) counter).value()))));
|
.put(OnionParser.prettyPrint(host) + ".numberOfMessages." + type, Integer.toString(((Set) set).size()))));
|
||||||
|
|
||||||
// - assemble diffs
|
// - assemble diffs
|
||||||
// - transfer values
|
// - transfer values
|
||||||
|
@ -197,22 +182,26 @@ public class P2PSeedNodeSnapshot extends P2PSeedNodeSnapshotBase {
|
||||||
bucketsPerHost.forEach((host, value) -> messagesPerHost.put(OnionParser.prettyPrint(host), value));
|
bucketsPerHost.forEach((host, value) -> messagesPerHost.put(OnionParser.prettyPrint(host), value));
|
||||||
|
|
||||||
// - pick reference seed node and its values
|
// - pick reference seed node and its values
|
||||||
Optional<String> referenceHost = messagesPerHost.keySet().stream().sorted().findFirst();
|
String referenceHost = "overall_number_of_unique_messages";
|
||||||
Map<String, Counter> referenceValues = messagesPerHost.get(referenceHost.get()).values();
|
Map<String, Set<Object>> referenceValues = new HashMap<>();
|
||||||
|
messagesPerHost.forEach((host, statistics) -> statistics.values().forEach((type, set) -> {
|
||||||
|
referenceValues.putIfAbsent((String) type, new HashSet<>());
|
||||||
|
referenceValues.get(type).addAll((Set) set);
|
||||||
|
}));
|
||||||
|
|
||||||
// - calculate diffs
|
// - calculate diffs
|
||||||
messagesPerHost.forEach(
|
messagesPerHost.forEach(
|
||||||
(host, statistics) -> {
|
(host, statistics) -> {
|
||||||
statistics.values().forEach((messageType, count) -> {
|
statistics.values().forEach((messageType, set) -> {
|
||||||
try {
|
try {
|
||||||
report.put(OnionParser.prettyPrint(host) + ".relativeNumberOfMessages." + messageType,
|
report.put(OnionParser.prettyPrint(host) + ".relativeNumberOfMessages." + messageType,
|
||||||
String.valueOf(((Counter) count).value() - referenceValues.get(messageType).value()));
|
String.valueOf(((Set) set).size() - referenceValues.get(messageType).size()));
|
||||||
} catch (MalformedURLException | NullPointerException ignore) {
|
} catch (MalformedURLException | NullPointerException ignore) {
|
||||||
log.error("we should never have gotten here", ignore);
|
log.error("we should never have gotten here", ignore);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
report.put(OnionParser.prettyPrint(host) + ".referenceHost", referenceHost.get());
|
report.put(OnionParser.prettyPrint(host) + ".referenceHost", referenceHost);
|
||||||
} catch (MalformedURLException ignore) {
|
} catch (MalformedURLException ignore) {
|
||||||
log.error("we should never got here");
|
log.error("we should never got here");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue