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

Seednode optimizations #2501

Merged
merged 3 commits into from
Jul 8, 2019
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
65 changes: 24 additions & 41 deletions p2p/src/main/java/bisq/network/p2p/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import bisq.common.proto.ProtobufferException;
import bisq.common.proto.network.NetworkEnvelope;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.util.Tuple2;
import bisq.common.util.Utilities;

import io.bisq.generated.protobuffer.PB;
Expand Down Expand Up @@ -77,7 +76,6 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import java.lang.ref.WeakReference;

Expand Down Expand Up @@ -162,7 +160,7 @@ public static int getPermittedMessageSize() {
private PeerType peerType = PeerType.PEER;
@Getter
private final ObjectProperty<NodeAddress> peersNodeAddressProperty = new SimpleObjectProperty<>();
private final List<Tuple2<Long, String>> messageTimeStamps = new ArrayList<>();
private final List<Long> messageTimeStamps = new ArrayList<>();
private final CopyOnWriteArraySet<MessageListener> messageListeners = new CopyOnWriteArraySet<>();
private volatile long lastSendTimeStamp = 0;
private final CopyOnWriteArraySet<WeakReference<SupportedCapabilitiesListener>> capabilitiesListeners = new CopyOnWriteArraySet<>();
Expand Down Expand Up @@ -342,47 +340,33 @@ public void addWeakCapabilitiesListener(SupportedCapabilitiesListener listener)
capabilitiesListeners.add(new WeakReference<>(listener));
}

// TODO either use the argument or delete it
private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) {
private boolean violatesThrottleLimit() {
long now = System.currentTimeMillis();
boolean violated = false;
//TODO remove message storage after network is tested stable
if (messageTimeStamps.size() >= msgThrottlePerSec) {
// check if we got more than 200 (MSG_THROTTLE_PER_SEC) msg per sec.
long compareValue = messageTimeStamps.get(messageTimeStamps.size() - msgThrottlePerSec).first;
// if duration < 1 sec we received too much network_messages
violated = now - compareValue < TimeUnit.SECONDS.toMillis(1);
if (violated) {
log.error("violatesThrottleLimit MSG_THROTTLE_PER_SEC ");
log.error("elapsed " + (now - compareValue));
log.error("messageTimeStamps: \n\t" + messageTimeStamps.stream()
.map(e -> "\n\tts=" + e.first.toString() + " message=" + e.second)
.collect(Collectors.toList()).toString());
}
}

if (messageTimeStamps.size() >= msgThrottlePer10Sec) {
if (!violated) {
// check if we got more than 50 msg per 10 sec.
long compareValue = messageTimeStamps.get(messageTimeStamps.size() - msgThrottlePer10Sec).first;
// if duration < 10 sec we received too much network_messages
violated = now - compareValue < TimeUnit.SECONDS.toMillis(10);

if (violated) {
log.error("violatesThrottleLimit MSG_THROTTLE_PER_10_SEC ");
log.error("elapsed " + (now - compareValue));
log.error("messageTimeStamps: \n\t" + messageTimeStamps.stream()
.map(e -> "\n\tts=" + e.first.toString() + " message=" + e.second)
.collect(Collectors.toList()).toString());
}
messageTimeStamps.add(now);

// clean list
while(messageTimeStamps.size() > msgThrottlePer10Sec)
messageTimeStamps.remove(0);

return violatesThrottleLimit(now,1, msgThrottlePerSec) || violatesThrottleLimit(now,10, msgThrottlePer10Sec);
}

private boolean violatesThrottleLimit(long now, int seconds, int messageCountLimit) {
if (messageTimeStamps.size() >= messageCountLimit) {

// find the entry in the message timestamp history which determines whether we overshot the limit or not
long compareValue = messageTimeStamps.get(messageTimeStamps.size() - messageCountLimit);

// if duration < seconds sec we received too much network_messages
if(now - compareValue < TimeUnit.SECONDS.toMillis(seconds)) {
log.error("violatesThrottleLimit {}/{} second(s)", messageCountLimit, seconds);

return true;
}
}
// we limit to max 1000 (MSG_THROTTLE_PER_10SEC) entries
while (messageTimeStamps.size() > msgThrottlePer10Sec)
messageTimeStamps.remove(0);

messageTimeStamps.add(new Tuple2<>(now, networkEnvelope.getClass().getName()));
return violated;
return false;
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -747,8 +731,7 @@ public void run() {
return;
}

if (violatesThrottleLimit(networkEnvelope)
&& reportInvalidRequest(RuleViolation.THROTTLE_LIMIT_EXCEEDED))
if (violatesThrottleLimit() && reportInvalidRequest(RuleViolation.THROTTLE_LIMIT_EXCEEDED))
return;

// Check P2P network ID
Expand Down
19 changes: 19 additions & 0 deletions seednode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Bisq Seed Node

The distribution ships with a systemd .desktop file. Validate/change the executable/config paths within the shipped `bisq-seednode.service` file and copy/move the file to your systemd directory (something along `/usr/lib/systemd/system/`). Now you can control your *Seed Node* via the usual systemd start/stop commands

```
systemctl start bisq-seednode.service
systemctl stop bisq-seednode.service
```
and
```
systemctl enable bisq-seednode.service
systemctl disable bisq-seednode.service
```

Follow the logs created by the service by inspecting

```
journalctl --unit bisq-seednode --follow
```
14 changes: 14 additions & 0 deletions seednode/bisq-seednode.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Bisq Seed Node
After=network.target

[Service]
Environment="JAVA_OPTS=-Xms800M -Xmx800M"
ExecStart=/home/bisq/bisq/bisq-seednode --appName=seed_BTC_MAINNET --nodePort=8000 --userDataDir=/home/bisq/ --maxConnections=50 --baseCurrencyNetwork=BTC_MAINNET
Restart=on-failure

User=bisq
Group=bisq

[Install]
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static void main(String[] args) throws Exception {
protected void doExecute(OptionSet options) {
super.doExecute(options);

checkMemory(bisqEnvironment, this);
freimair marked this conversation as resolved.
Show resolved Hide resolved
CommonSetup.setup(this);

keepRunning();
Expand Down