Skip to content

Commit

Permalink
Remove display of data from last second
Browse files Browse the repository at this point in the history
  • Loading branch information
chimp1984 committed Aug 27, 2020
1 parent a88e8f8 commit 8c61953
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 48 deletions.
4 changes: 2 additions & 2 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,8 @@ settings.net.heightColumn=Height

settings.net.needRestart=You need to restart the application to apply that change.\nDo you want to do that now?
settings.net.notKnownYet=Not known yet...
settings.net.sentData=Sent data: {0}, {1} messages, {2} messages/sec, {3} messages sent in last second
settings.net.receivedData=Received data: {0}, {1} messages, {2} messages/sec, {3} messages received in last second
settings.net.sentData=Sent data: {0}, {1} messages, {2} messages/sec
settings.net.receivedData=Received data: {0}, {1} messages, {2} messages/sec
settings.net.ips=[IP address:port | host name:port | onion address:port] (comma separated). Port can be omitted if default is used (8333).
settings.net.seedNode=Seed node
settings.net.directPeer=Peer (direct)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,14 @@ public void activate() {
sentDataTextField.textProperty().bind(createStringBinding(() -> Res.get("settings.net.sentData",
FormattingUtils.formatBytes(Statistic.totalSentBytesProperty().get()),
Statistic.numTotalSentMessagesProperty().get(),
Statistic.numTotalSentMessagesPerSecProperty().get(),
Statistic.numTotalSentMessagesLastSecProperty().get()),
Statistic.numTotalSentMessagesLastSecProperty()));
Statistic.numTotalSentMessagesPerSecProperty().get()),
Statistic.numTotalSentMessagesPerSecProperty()));

receivedDataTextField.textProperty().bind(createStringBinding(() -> Res.get("settings.net.receivedData",
FormattingUtils.formatBytes(Statistic.totalReceivedBytesProperty().get()),
Statistic.numTotalReceivedMessagesProperty().get(),
Statistic.numTotalReceivedMessagesPerSecProperty().get(),
Statistic.numTotalReceivedMessagesLastSecProperty().get()),
Statistic.numTotalReceivedMessagesLastSecProperty()));
Statistic.numTotalReceivedMessagesPerSecProperty().get()),
Statistic.numTotalReceivedMessagesPerSecProperty()));

bitcoinSortedList.comparatorProperty().bind(bitcoinPeersTableView.comparatorProperty());
bitcoinPeersTableView.setItems(bitcoinSortedList);
Expand Down
44 changes: 4 additions & 40 deletions p2p/src/main/java/bisq/network/p2p/network/Statistic.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,36 @@ public class Statistic {
private final static LongProperty totalReceivedBytes = new SimpleLongProperty(0);
private final static Map<String, Integer> totalReceivedMessages = new ConcurrentHashMap<>();
private final static Map<String, Integer> totalSentMessages = new ConcurrentHashMap<>();
private final static Map<String, Integer> totalReceivedMessagesLastSec = new ConcurrentHashMap<>();
private final static Map<String, Integer> totalSentMessagesLastSec = new ConcurrentHashMap<>();
private final static LongProperty numTotalSentMessages = new SimpleLongProperty(0);
private final static LongProperty numTotalSentMessagesLastSec = new SimpleLongProperty(0);
private final static DoubleProperty numTotalSentMessagesPerSec = new SimpleDoubleProperty(0);
private final static LongProperty numTotalReceivedMessages = new SimpleLongProperty(0);
private final static LongProperty numTotalReceivedMessagesLastSec = new SimpleLongProperty(0);
private final static DoubleProperty numTotalReceivedMessagesPerSec = new SimpleDoubleProperty(0);
private static String totalSentMessagesLastSecString;
private static String totalReceivedMessagesLastSecString;

static {
UserThread.runPeriodically(() -> {
numTotalSentMessages.set(totalSentMessages.values().stream().mapToInt(Integer::intValue).sum());
numTotalSentMessagesLastSec.set(totalSentMessagesLastSec.values().stream().mapToInt(Integer::intValue).sum());
numTotalReceivedMessages.set(totalReceivedMessages.values().stream().mapToInt(Integer::intValue).sum());
numTotalReceivedMessagesLastSec.set(totalReceivedMessagesLastSec.values().stream().mapToInt(Integer::intValue).sum());

long passed = (System.currentTimeMillis() - startTime) / 1000;
numTotalSentMessagesPerSec.set(((double) numTotalSentMessages.get()) / passed);
numTotalReceivedMessagesPerSec.set(((double) numTotalReceivedMessages.get()) / passed);

// We keep totalSentMessagesPerSec in a string so it is available at logging (totalSentMessagesPerSec is reset)
totalSentMessagesLastSecString = totalSentMessagesLastSec.toString();
totalReceivedMessagesLastSecString = totalReceivedMessagesLastSec.toString();

// We do not clear the map as the totalSentMessagesPerSec is not thread safe and clearing could lead to null pointers
totalSentMessagesLastSec.entrySet().forEach(e -> e.setValue(0));
totalReceivedMessagesLastSec.entrySet().forEach(e -> e.setValue(0));
}, 1);

// We log statistics every minute
UserThread.runPeriodically(() -> {
log.info("Network statistics:\n" +
"Bytes sent: {} kb;\n" +
"Number of sent messages/Sent messages: {} / {};\n" +
"Number of sent messages of last sec/Sent messages of last sec: {} / {};\n" +
"Number of sent messages per sec: {};\n" +
"Bytes received: {} kb\n" +
"Number of received messages/Received messages: {} / {};\n" +
"Number of received messages of last sec/Received messages of last sec: {} / {};",
"Number of received messages per sec: {};",
totalSentBytes.get() / 1024d,
numTotalSentMessages.get(), totalSentMessages,
numTotalSentMessagesLastSec.get(), totalSentMessagesLastSecString,
numTotalSentMessagesPerSec.get(),
totalReceivedBytes.get() / 1024d,
numTotalReceivedMessages.get(), totalReceivedMessages,
numTotalReceivedMessagesLastSec.get(), totalReceivedMessagesLastSecString);
numTotalReceivedMessagesPerSec.get());
}, 60);
}

Expand All @@ -111,10 +95,6 @@ public static LongProperty numTotalSentMessagesProperty() {
return numTotalSentMessages;
}

public static LongProperty numTotalSentMessagesLastSecProperty() {
return numTotalSentMessagesLastSec;
}

public static DoubleProperty numTotalSentMessagesPerSecProperty() {
return numTotalSentMessagesPerSec;
}
Expand All @@ -123,10 +103,6 @@ public static LongProperty numTotalReceivedMessagesProperty() {
return numTotalReceivedMessages;
}

public static LongProperty numTotalReceivedMessagesLastSecProperty() {
return numTotalReceivedMessagesLastSec;
}

public static DoubleProperty numTotalReceivedMessagesPerSecProperty() {
return numTotalReceivedMessagesPerSec;
}
Expand Down Expand Up @@ -189,12 +165,6 @@ void addReceivedMessage(NetworkEnvelope networkEnvelope) {
counter = totalReceivedMessages.get(messageClassName) + 1;
}
totalReceivedMessages.put(messageClassName, counter);

counter = 1;
if (totalReceivedMessagesLastSec.containsKey(messageClassName)) {
counter = totalReceivedMessagesLastSec.get(messageClassName) + 1;
}
totalReceivedMessagesLastSec.put(messageClassName, counter);
}

void addSentMessage(NetworkEnvelope networkEnvelope) {
Expand All @@ -210,12 +180,6 @@ void addSentMessage(NetworkEnvelope networkEnvelope) {
counter = totalSentMessages.get(messageClassName) + 1;
}
totalSentMessages.put(messageClassName, counter);

counter = 1;
if (totalSentMessagesLastSec.containsKey(messageClassName)) {
counter = totalSentMessagesLastSec.get(messageClassName) + 1;
}
totalSentMessagesLastSec.put(messageClassName, counter);
}

public void setRoundTripTime(int roundTripTime) {
Expand Down

0 comments on commit 8c61953

Please sign in to comment.