mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Add maxConnection parameter to be used for setting the core pool size of the executor in NetworkNode.
We use double the maxConnection size for the core size and 4x for the max pool size. Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
d4b6965348
commit
0dc8d0b2bd
@ -45,6 +45,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
public NetworkNodeProvider(NetworkProtoResolver networkProtoResolver,
|
||||
BridgeAddressProvider bridgeAddressProvider,
|
||||
@Nullable NetworkFilter networkFilter,
|
||||
@Named(Config.MAX_CONNECTIONS) int maxConnections,
|
||||
@Named(Config.USE_LOCALHOST_FOR_P2P) boolean useLocalhostForP2P,
|
||||
@Named(Config.NODE_PORT) int port,
|
||||
@Named(Config.TOR_DIR) File torDir,
|
||||
@ -56,7 +57,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
@Named(Config.TOR_STREAM_ISOLATION) boolean streamIsolation,
|
||||
@Named(Config.TOR_CONTROL_USE_SAFE_COOKIE_AUTH) boolean useSafeCookieAuthentication) {
|
||||
if (useLocalhostForP2P) {
|
||||
networkNode = new LocalhostNetworkNode(port, networkProtoResolver, networkFilter);
|
||||
networkNode = new LocalhostNetworkNode(port, networkProtoResolver, networkFilter, maxConnections);
|
||||
} else {
|
||||
TorMode torMode = getTorMode(bridgeAddressProvider,
|
||||
torDir,
|
||||
@ -66,7 +67,7 @@ public class NetworkNodeProvider implements Provider<NetworkNode> {
|
||||
password,
|
||||
cookieFile,
|
||||
useSafeCookieAuthentication);
|
||||
networkNode = new TorNetworkNode(port, networkProtoResolver, streamIsolation, torMode, networkFilter);
|
||||
networkNode = new TorNetworkNode(port, networkProtoResolver, streamIsolation, torMode, networkFilter, maxConnections);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,9 @@ public class LocalhostNetworkNode extends NetworkNode {
|
||||
|
||||
public LocalhostNetworkNode(int port,
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
super(port, networkProtoResolver, networkFilter);
|
||||
@Nullable NetworkFilter networkFilter,
|
||||
int maxConnections) {
|
||||
super(port, networkProtoResolver, networkFilter, maxConnections);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,6 +72,7 @@ public abstract class NetworkNode implements MessageListener {
|
||||
private final NetworkProtoResolver networkProtoResolver;
|
||||
@Nullable
|
||||
private final NetworkFilter networkFilter;
|
||||
private final int maxConnections;
|
||||
|
||||
private final CopyOnWriteArraySet<InboundConnection> inBoundConnections = new CopyOnWriteArraySet<>();
|
||||
private final CopyOnWriteArraySet<MessageListener> messageListeners = new CopyOnWriteArraySet<>();
|
||||
@ -92,10 +93,12 @@ public abstract class NetworkNode implements MessageListener {
|
||||
|
||||
NetworkNode(int servicePort,
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
@Nullable NetworkFilter networkFilter,
|
||||
int maxConnections) {
|
||||
this.servicePort = servicePort;
|
||||
this.networkProtoResolver = networkProtoResolver;
|
||||
this.networkFilter = networkFilter;
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -437,7 +440,10 @@ public abstract class NetworkNode implements MessageListener {
|
||||
|
||||
void createExecutorService() {
|
||||
if (executorService == null)
|
||||
executorService = Utilities.getListeningExecutorService("NetworkNode-" + servicePort, 15, 30, 60);
|
||||
executorService = Utilities.getListeningExecutorService("NetworkNode-" + servicePort,
|
||||
maxConnections * 2,
|
||||
maxConnections * 4,
|
||||
60);
|
||||
}
|
||||
|
||||
void startServer(ServerSocket serverSocket) {
|
||||
|
@ -78,8 +78,9 @@ public class TorNetworkNode extends NetworkNode {
|
||||
NetworkProtoResolver networkProtoResolver,
|
||||
boolean useStreamIsolation,
|
||||
TorMode torMode,
|
||||
@Nullable NetworkFilter networkFilter) {
|
||||
super(servicePort, networkProtoResolver, networkFilter);
|
||||
@Nullable NetworkFilter networkFilter,
|
||||
int maxConnections) {
|
||||
super(servicePort, networkProtoResolver, networkFilter, maxConnections);
|
||||
this.torMode = torMode;
|
||||
this.streamIsolation = useStreamIsolation;
|
||||
createExecutorService();
|
||||
|
@ -41,7 +41,7 @@ public class LocalhostNetworkNodeTest {
|
||||
@Test
|
||||
public void testMessage() throws InterruptedException, IOException {
|
||||
CountDownLatch msgLatch = new CountDownLatch(2);
|
||||
LocalhostNetworkNode node1 = new LocalhostNetworkNode(9001, TestUtils.getNetworkProtoResolver(), null);
|
||||
LocalhostNetworkNode node1 = new LocalhostNetworkNode(9001, TestUtils.getNetworkProtoResolver(), null, 12);
|
||||
node1.addMessageListener((message, connection) -> {
|
||||
log.debug("onMessage node1 " + message);
|
||||
msgLatch.countDown();
|
||||
@ -69,7 +69,7 @@ public class LocalhostNetworkNodeTest {
|
||||
}
|
||||
});
|
||||
|
||||
LocalhostNetworkNode node2 = new LocalhostNetworkNode(9002, TestUtils.getNetworkProtoResolver(), null);
|
||||
LocalhostNetworkNode node2 = new LocalhostNetworkNode(9002, TestUtils.getNetworkProtoResolver(), null, 12);
|
||||
node2.addMessageListener((message, connection) -> {
|
||||
log.debug("onMessage node2 " + message);
|
||||
msgLatch.countDown();
|
||||
|
@ -56,7 +56,7 @@ public class TorNetworkNodeTest {
|
||||
latch = new CountDownLatch(1);
|
||||
int port = 9001;
|
||||
TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12);
|
||||
node1.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
@ -83,7 +83,7 @@ public class TorNetworkNodeTest {
|
||||
latch = new CountDownLatch(1);
|
||||
int port2 = 9002;
|
||||
TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12);
|
||||
node2.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
@ -141,7 +141,7 @@ public class TorNetworkNodeTest {
|
||||
latch = new CountDownLatch(2);
|
||||
int port = 9001;
|
||||
TorNetworkNode node1 = new TorNetworkNode(port, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12);
|
||||
node1.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
@ -167,7 +167,7 @@ public class TorNetworkNodeTest {
|
||||
|
||||
int port2 = 9002;
|
||||
TorNetworkNode node2 = new TorNetworkNode(port2, TestUtils.getNetworkProtoResolver(), false,
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null);
|
||||
new NewTor(new File("torNode_" + port), null, "", this::getBridgeAddresses), null, 12);
|
||||
node2.start(new SetupListener() {
|
||||
@Override
|
||||
public void onTorNodeReady() {
|
||||
|
Loading…
Reference in New Issue
Block a user