mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-20 07:46:05 -04:00
Random delay when sending direct message in network stress test
The delay is always longer than the one that triggers throttling. It makes not much sense for a single sending, but it will within a loop. Also made some ``Connection`` throttle constants package-private so they can be accessed by tests.
This commit is contained in:
parent
da145435a1
commit
c8e3c6d11a
@ -62,10 +62,11 @@ public class Connection implements MessageListener {
|
||||
// Static
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final int MAX_MSG_SIZE = 500 * 1024; // 500 kb
|
||||
// Leaving some constants package-private for tests to know limits.
|
||||
static final int MAX_MSG_SIZE = 500 * 1024; // 500 kb
|
||||
//TODO decrease limits again after testing
|
||||
private static final int MSG_THROTTLE_PER_SEC = 70; // With MAX_MSG_SIZE of 500kb results in bandwidth of 35 mbit/sec
|
||||
private static final int MSG_THROTTLE_PER_10_SEC = 500; // With MAX_MSG_SIZE of 100kb results in bandwidth of 50 mbit/sec for 10 sec
|
||||
static final int MSG_THROTTLE_PER_SEC = 70; // With MAX_MSG_SIZE of 500kb results in bandwidth of 35 mbit/sec
|
||||
static final int MSG_THROTTLE_PER_10_SEC = 500; // With MAX_MSG_SIZE of 100kb results in bandwidth of 50 mbit/sec for 10 sec
|
||||
private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);
|
||||
|
||||
public static int getMaxMsgSize() {
|
||||
|
@ -2,6 +2,7 @@ package io.bitsquare.p2p.network;
|
||||
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.common.Clock;
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.crypto.KeyStorage;
|
||||
import io.bitsquare.common.crypto.PubKeyRing;
|
||||
@ -43,6 +44,7 @@ public class NetworkStressTest {
|
||||
|
||||
/** Numeric identifier of the regtest Bitcoin network. */
|
||||
private static final int REGTEST_NETWORK_ID = 2;
|
||||
|
||||
/** Default number of peers in the test. */
|
||||
private static final int NPEERS_DEFAULT = 4;
|
||||
/** Minimum number of peers for the test to work. */
|
||||
@ -52,6 +54,11 @@ public class NetworkStressTest {
|
||||
/** Environment variable to specify a persistent test data directory. */
|
||||
private static final String TEST_DIR_ENVVAR = "STRESS_TEST_DIR";
|
||||
|
||||
/** Minimum delay between direct messages in milliseconds, 25% larger than throttle limit. */
|
||||
private static long MIN_DIRECT_DELAY_MILLIS = Math.round(1.25 * (1.0 / Connection.MSG_THROTTLE_PER_SEC) * 1000);
|
||||
/** Maximum delay between direct messages in milliseconds, 10 times larger than minimum. */
|
||||
private static long MAX_DIRECT_DELAY_MILLIS = 10 * MIN_DIRECT_DELAY_MILLIS;
|
||||
|
||||
// Instance fields
|
||||
|
||||
/** A directory to (temporarily) hold seed and normal nodes' configuration and state files. */
|
||||
@ -195,12 +202,14 @@ public class NetworkStressTest {
|
||||
receivedDirectLatch.countDown();
|
||||
});
|
||||
|
||||
// Select a random peer and send a direct message to it.
|
||||
// Select a random peer and send a direct message to it after a random delay
|
||||
// not shorter than throttle limits.
|
||||
final int dstPeerIdx = (int) (Math.random() * nPeers);
|
||||
final P2PService dstPeer = peerNodes.get(dstPeerIdx);
|
||||
final NodeAddress dstPeerAddress = dstPeer.getAddress();
|
||||
//print("sending direct message from peer %s to %s", srcPeer.getAddress(), dstPeer.getAddress());
|
||||
srcPeer.sendEncryptedDirectMessage(dstPeerAddress, peerPKRings.get(dstPeerIdx),
|
||||
UserThread.runAfterRandomDelay(() -> srcPeer.sendEncryptedDirectMessage(
|
||||
dstPeerAddress, peerPKRings.get(dstPeerIdx),
|
||||
new StressTestDirectMessage("test/" + dstPeerAddress), new SendDirectMessageListener() {
|
||||
@Override
|
||||
public void onArrived() {
|
||||
@ -212,7 +221,8 @@ public class NetworkStressTest {
|
||||
sentDirectFailed.set(true);
|
||||
sentDirectLatch.countDown();
|
||||
}
|
||||
});
|
||||
}), MIN_DIRECT_DELAY_MILLIS, MAX_DIRECT_DELAY_MILLIS, TimeUnit.MILLISECONDS
|
||||
);
|
||||
}
|
||||
// Since receiving is completed before sending is reported to be complete,
|
||||
// all receiving checks should end before all sending checks to avoid deadlocking.
|
||||
|
Loading…
x
Reference in New Issue
Block a user