Skip to content

Commit

Permalink
Revert "#6455 Introduce SyncConfig (#7232)"
Browse files Browse the repository at this point in the history
This reverts commit 57057c5.
  • Loading branch information
povolev15 committed Jun 27, 2023
1 parent 6b55ae0 commit 6845ee1
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
* @param delayShuffle
* the working state (stateWork) resets to a copy of the consensus state (stateCons) (which is called a shuffle)
* when its queue is empty and the two are equal, but never twice within this many milliseconds
* @param callerSkipsBeforeSleep
* sleep sleepCallerSkips ms after the caller fails this many times to call a random member
* @param sleepCallerSkips
* caller sleeps this many milliseconds if it failed to connect to callerSkipsBeforeSleep in a row
* @param statsSkipSeconds
* number of seconds that the "all" history window skips at the start
* @param threadPrioritySync
Expand Down Expand Up @@ -136,6 +140,14 @@
* The value for the event intake queue at which the node should stop syncing
* @param transactionMaxBytes
* maximum number of bytes allowed in a transaction
* @param maxIncomingSyncsInc
* maximum number of simultaneous incoming syncs initiated by others, minus maxOutgoingSyncs. If there is a moment
* where each member has maxOutgoingSyncs outgoing syncs in progress, then a fraction of at least:
* (1 / (maxOutgoingSyncs + maxIncomingSyncsInc)) members will be willing to accept another incoming sync. So
* even in the worst case, it should be possible to find a partner to sync with in about (maxOutgoingSyncs +
* maxIncomingSyncsInc) tries, on average.
* @param maxOutgoingSyncs
* maximum number of simultaneous outgoing syncs initiated by me
* @param logPath
* path to log4j2.xml (which might not exist)
* @param hangingThreadDuration
Expand Down Expand Up @@ -165,6 +177,8 @@ public record BasicConfig(
@ConfigProperty(defaultValue = "true") boolean logStack,
@ConfigProperty(defaultValue = "500") int sleepHeartbeat,
@ConfigProperty(defaultValue = "200") long delayShuffle,
@ConfigProperty(defaultValue = "30") long callerSkipsBeforeSleep,
@ConfigProperty(defaultValue = "50") long sleepCallerSkips,
@ConfigProperty(defaultValue = "60") double statsSkipSeconds,
@ConfigProperty(defaultValue = "5") int threadPrioritySync,
@ConfigProperty(defaultValue = "5") int threadPriorityNonSync,
Expand Down Expand Up @@ -193,6 +207,8 @@ public record BasicConfig(
@ConfigProperty(defaultValue = "5") int staleEventPreventionThreshold,
@ConfigProperty(defaultValue = "1000") int eventIntakeQueueThrottleSize,
@ConfigProperty(defaultValue = "6144") int transactionMaxBytes,
@ConfigProperty(defaultValue = "1") int maxIncomingSyncsInc,
@ConfigProperty(defaultValue = "2") int maxOutgoingSyncs,
@ConfigProperty(defaultValue = "log4j2.xml") Path logPath,
@ConfigProperty(defaultValue = "60s") Duration hangingThreadDuration,
@ConfigProperty(defaultValue = "data/saved") String emergencyRecoveryFileLoadDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void testPrint() throws IOException {
// Verify properties in file are listed
assertContains(regexForLine("verifyEventSigs", "false", true), lines);
assertContains(regexForLine("showInternalStats", "true", true), lines);
assertContains(regexForLine("maxOutgoingSyncs", "1", true), lines);
assertContains(regexForLine("state.saveStatePeriod", "0", true), lines);
assertContains(regexForLine("loadKeysFromPfxFiles", "false", true), lines);
assertContains(regexForLine("madeUpSetting", "0", false), lines);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ private Browser(@NonNull final Set<NodeId> localNodesToStart) throws IOException
Settings.populateSettingsCommon();

// Update Settings based on config.txt
configurationProperties.maxSyncs().ifPresent(value -> Settings.getInstance()
.setMaxOutgoingSyncs(value));
configurationProperties.transactionMaxBytes().ifPresent(value -> Settings.getInstance()
.setTransactionMaxBytes(value));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ public final class SettingConstants {
/** name of the settings used file */
static final String SETTING_USED_FILENAME = "settingsUsed.txt";

static final String DATA_STRING = "data";
static final String SAVED_STRING = "saved";
static final int NUM_CRYPTO_THREADS_DEFAULT_VALUE = 32;
static final int THROTTLE_TRANSACTION_QUEUE_SIZE_DEFAULT_VALUE = 100_000;
static final int MAX_OUTGOING_SYNCS_DEFAULT_VALUE = 2;
static final int MAX_INCOMING_SYNCS_INC_DEFAULT_VALUE = 1;
static final int DEADLOCK_CHECK_PERIOD_DEFAULT_VALUE = 1000;
static final boolean VERIFY_EVENT_SIGS_DEFAULT_VALUE = true;
static final boolean SHOW_INTERNAL_STATS_DEFAULT_VALUE = false;
static final boolean VERBOSE_STATISTICS_DEFAULT_VALUE = false;
static final int CALLER_SKIPS_BEFORE_SLEEP_DEFAULT_VALUE = 30;
static final int SLEEP_CALLER_SKIPS_DEFAULT_VALUE = 50;
static final int STATS_BUFFER_SIZE_DEFAULT_VALUE = 100;
static final int STATS_RECENT_SECONDS_DEFAULT_VALUE = 63;
static final int TRANSACTION_MAX_BYTES_DEFAULT_VALUES = 6144;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
import static com.swirlds.common.settings.ParsingUtils.parseDuration;
import static com.swirlds.logging.LogMarker.EXCEPTION;
import static com.swirlds.logging.LogMarker.STARTUP;
import static com.swirlds.platform.SettingConstants.CALLER_SKIPS_BEFORE_SLEEP_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.DEADLOCK_CHECK_PERIOD_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.LOAD_KEYS_FROM_PFX_FILES_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.MAX_ADDRESS_SIZE_ALLOWED_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.MAX_INCOMING_SYNCS_INC_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.MAX_OUTGOING_SYNCS_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.MAX_TRANSACTION_BYTES_PER_EVENT_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.MAX_TRANSACTION_COUNT_PER_EVENT_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.NUM_CRYPTO_THREADS_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.SHOW_INTERNAL_STATS_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.SLEEP_CALLER_SKIPS_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.STATS_BUFFER_SIZE_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.STATS_RECENT_SECONDS_DEFAULT_VALUE;
import static com.swirlds.platform.SettingConstants.THREAD_DUMP_LOG_DIR_DEFAULT_VALUE;
Expand Down Expand Up @@ -118,8 +122,26 @@ public class Settings {
* many.
*/
private int throttleTransactionQueueSize = THROTTLE_TRANSACTION_QUEUE_SIZE_DEFAULT_VALUE;
/** maximum number of simultaneous outgoing syncs initiated by me */
private int maxOutgoingSyncs = MAX_OUTGOING_SYNCS_DEFAULT_VALUE;
/**
* maximum number of simultaneous incoming syncs initiated by others, minus maxOutgoingSyncs. If there is a moment
* where each member has maxOutgoingSyncs outgoing syncs in progress, then a fraction of at least:
*
* <pre>
* (1 / (maxOutgoingSyncs + maxIncomingSyncsInc))
* </pre>
* <p>
* members will be willing to accept another incoming sync. So even in the worst case, it should be possible to find
* a partner to sync with in about (maxOutgoingSyncs + maxIncomingSyncsInc) tries, on average.
*/
private int maxIncomingSyncsInc = MAX_INCOMING_SYNCS_INC_DEFAULT_VALUE;
/** check for deadlocks every this many milliseconds (-1 for never) */
private int deadlockCheckPeriod = DEADLOCK_CHECK_PERIOD_DEFAULT_VALUE;
/** sleep sleepCallerSkips ms after the caller fails this many times to call a random member */
private long callerSkipsBeforeSleep = CALLER_SKIPS_BEFORE_SLEEP_DEFAULT_VALUE;
/** caller sleeps this many milliseconds if it failed to connect to callerSkipsBeforeSleep in a row */
private long sleepCallerSkips = SLEEP_CALLER_SKIPS_DEFAULT_VALUE;
/** number of bins to store for the history (in StatsBuffer etc.) */
private int statsBufferSize = STATS_BUFFER_SIZE_DEFAULT_VALUE;
/** number of seconds covered by "recent" history (in StatsBuffer etc.) */
Expand Down Expand Up @@ -476,10 +498,34 @@ public int getThrottleTransactionQueueSize() {
return throttleTransactionQueueSize;
}

public int getMaxOutgoingSyncs() {
return maxOutgoingSyncs;
}

public void setMaxOutgoingSyncs(final int maxOutgoingSyncs) {
this.maxOutgoingSyncs = maxOutgoingSyncs;
}

public int getMaxIncomingSyncsInc() {
return maxIncomingSyncsInc;
}

public void setMaxIncomingSyncsInc(final int maxIncomingSyncsInc) {
this.maxIncomingSyncsInc = maxIncomingSyncsInc;
}

public int getDeadlockCheckPeriod() {
return deadlockCheckPeriod;
}

public long getCallerSkipsBeforeSleep() {
return callerSkipsBeforeSleep;
}

public long getSleepCallerSkips() {
return sleepCallerSkips;
}

public int getThreadPrioritySync() {
return threadPrioritySync;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ private ConfigMappings() {}
new ConfigMapping("socket.doUpnp", "doUpnp"),
new ConfigMapping("socket.useLoopbackIp", "useLoopbackIp"),
new ConfigMapping("socket.tcpNoDelay", "tcpNoDelay"),
new ConfigMapping("socket.deadlockCheckPeriod", "deadlockCheckPeriod"),
new ConfigMapping("sync.maxOutgoingSyncs", "maxOutgoingSyncs"),
new ConfigMapping("sync.maxIncomingSyncsInc", "maxIncomingSyncsInc"),
new ConfigMapping("sync.callerSkipsBeforeSleep", "callerSkipsBeforeSleep"),
new ConfigMapping("sync.sleepCallerSkips", "sleepCallerSkips"));
new ConfigMapping("socket.deadlockCheckPeriod", "deadlockCheckPeriod"));

/**
* Add all known aliases to the provided config source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import com.swirlds.platform.gossip.shadowgraph.ShadowGraph;
import com.swirlds.platform.gossip.shadowgraph.ShadowGraphSynchronizer;
import com.swirlds.platform.gossip.shadowgraph.SimultaneousSyncThrottle;
import com.swirlds.platform.gossip.sync.config.SyncConfig;
import com.swirlds.platform.metrics.EventIntakeMetrics;
import com.swirlds.platform.network.unidirectional.HeartbeatProtocolResponder;
import com.swirlds.platform.network.unidirectional.HeartbeatSender;
Expand Down Expand Up @@ -176,9 +175,8 @@ public LegacySyncGossip(

sharedConnectionLocks = new SharedConnectionLocks(topology, connectionManagers);

final SyncConfig syncConfig = platformContext.getConfiguration().getConfigData(SyncConfig.class);
simultaneousSyncThrottle = new SimultaneousSyncThrottle(
platformContext.getMetrics(), syncConfig.maxIncomingSyncsInc() + syncConfig.maxOutgoingSyncs());
platformContext.getMetrics(), settings.getMaxIncomingSyncsInc() + settings.getMaxOutgoingSyncs());

final ReconnectConfig reconnectConfig =
platformContext.getConfiguration().getConfigData(ReconnectConfig.class);
Expand Down Expand Up @@ -228,7 +226,7 @@ public LegacySyncGossip(
}

// create and start threads to call other members
for (int i = 0; i < syncConfig.maxOutgoingSyncs(); i++) {
for (int i = 0; i < settings.getMaxOutgoingSyncs(); i++) {
spawnSyncCaller(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import com.swirlds.common.threading.locks.locked.MaybeLocked;
import com.swirlds.common.threading.locks.locked.MaybeLockedResource;
import com.swirlds.logging.payloads.ReconnectPeerInfoPayload;
import com.swirlds.platform.Settings;
import com.swirlds.platform.components.EventTaskCreator;
import com.swirlds.platform.gossip.shadowgraph.ShadowGraphSynchronizer;
import com.swirlds.platform.gossip.shadowgraph.SimultaneousSyncThrottle;
import com.swirlds.platform.gossip.sync.config.SyncConfig;
import com.swirlds.platform.network.Connection;
import com.swirlds.platform.network.ConnectionManager;
import com.swirlds.platform.network.NetworkUtils;
Expand Down Expand Up @@ -71,7 +71,6 @@ public class SyncCaller implements Runnable {
private final EventTaskCreator eventTaskCreator;
private final Runnable updatePlatformStatus;
private ShadowGraphSynchronizer syncShadowgraphSynchronizer;
private final SyncConfig syncConfig;

private static final SpeedometerMetric.Config SLEEP_1_PER_SECOND_CONFIG = new SpeedometerMetric.Config(
INTERNAL_CATEGORY, "sleep1/sec")
Expand Down Expand Up @@ -109,8 +108,6 @@ public SyncCaller(
@NonNull final EventTaskCreator eventTaskCreator,
@NonNull final Runnable updatePlatformStatus,
@NonNull final ShadowGraphSynchronizer syncShadowgraphSynchronizer) {
Objects.requireNonNull(platformContext);

this.addressBook = Objects.requireNonNull(addressBook);
this.selfId = Objects.requireNonNull(selfId);
this.callerNumber = callerNumber;
Expand All @@ -124,7 +121,6 @@ public SyncCaller(
this.syncShadowgraphSynchronizer = Objects.requireNonNull(syncShadowgraphSynchronizer);

sleep1perSecond = platformContext.getMetrics().getOrCreate(SLEEP_1_PER_SECOND_CONFIG);
syncConfig = platformContext.getConfiguration().getConfigData(SyncConfig.class);
}

/**
Expand All @@ -141,11 +137,11 @@ public void run() {
failedAttempts = 0;
} else {
failedAttempts++;
if (failedAttempts >= syncConfig.callerSkipsBeforeSleep()) {
if (failedAttempts >= Settings.getInstance().getCallerSkipsBeforeSleep()) {
failedAttempts = 0;
try {
// Necessary to slow down the attempts after N failures
Thread.sleep(syncConfig.sleepCallerSkips());
Thread.sleep(Settings.getInstance().getSleepCallerSkips());
sleep1perSecond.cycle();
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,17 @@
/**
* Configuration of the sync gossip algorithm
*
* @param syncAsProtocolEnabled
* if true, perform the sync gossip algorithm as a negotiated protocol using bidirectional connections.
* @param syncSleepAfterFailedNegotiation
* the number of milliseconds to sleep after a failed negotiation when running the sync-as-a-protocol algorithm
* @param syncProtocolPermitCount
* the number of permits to use when running the sync-as-a-protocol algorithm
* @param syncProtocolHeartbeatPeriod
* the period at which the heartbeat protocol runs when the sync-as-a-protocol algorithm is active (milliseconds)
* @param maxOutgoingSyncs
* maximum number of simultaneous outgoing syncs initiated by me
* @param maxIncomingSyncsInc
* maximum number of simultaneous incoming syncs initiated by others, minus maxOutgoingSyncs. If there is a moment
* where each member has maxOutgoingSyncs outgoing syncs in progress, then a fraction of at least:
* (1 / (maxOutgoingSyncs + maxIncomingSyncsInc)) members will be willing to accept another incoming sync. So
* even in the worst case, it should be possible to find a partner to sync with in about (maxOutgoingSyncs +
* maxIncomingSyncsInc) tries, on average.
* @param callerSkipsBeforeSleep
* sleep sleepCallerSkips ms after the caller fails this many times to call a random member
* @param sleepCallerSkips
* caller sleeps this many milliseconds if it failed to connect to callerSkipsBeforeSleep in a row *
* @param syncAsProtocolEnabled if true, perform the sync gossip algorithm as a negotiated protocol using
* bidirectional connections.
* @param syncSleepAfterFailedNegotiation the number of milliseconds to sleep after a failed negotiation when running
* the sync-as-a-protocol algorithm
* @param syncProtocolPermitCount the number of permits to use when running the sync-as-a-protocol algorithm
* @param syncProtocolHeartbeatPeriod the period at which the heartbeat protocol runs when the sync-as-a-protocol
* algorithm is active (milliseconds)
*/
@ConfigData("sync")
public record SyncConfig(
@ConfigProperty(defaultValue = "false") boolean syncAsProtocolEnabled,
@ConfigProperty(defaultValue = "25") int syncSleepAfterFailedNegotiation,
@ConfigProperty(defaultValue = "17") int syncProtocolPermitCount,
@ConfigProperty(defaultValue = "1000") int syncProtocolHeartbeatPeriod,
@ConfigProperty(defaultValue = "2") int maxOutgoingSyncs,
@ConfigProperty(defaultValue = "1") int maxIncomingSyncsInc,
@ConfigProperty(defaultValue = "30") long callerSkipsBeforeSleep,
@ConfigProperty(defaultValue = "50") long sleepCallerSkips) {}
@ConfigProperty(defaultValue = "1000") int syncProtocolHeartbeatPeriod) {}
Loading

0 comments on commit 6845ee1

Please sign in to comment.