From 5db0fa080b7dfee7cb5034729dedb7ecd4c28bb4 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 24 Jun 2022 10:13:36 +0100 Subject: [PATCH] Prune peers every 5 minutes instead of every cycle of the Controller thread. This should reduce the amount of time the allKnownPeers lock is held. --- .../java/org/qortal/controller/Controller.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/qortal/controller/Controller.java b/src/main/java/org/qortal/controller/Controller.java index 67bfbf13..8e806c3c 100644 --- a/src/main/java/org/qortal/controller/Controller.java +++ b/src/main/java/org/qortal/controller/Controller.java @@ -113,6 +113,7 @@ public class Controller extends Thread { private long repositoryBackupTimestamp = startTime; // ms private long repositoryMaintenanceTimestamp = startTime; // ms private long repositoryCheckpointTimestamp = startTime; // ms + private long prunePeersTimestamp = startTime; // ms private long ntpCheckTimestamp = startTime; // ms private long deleteExpiredTimestamp = startTime + DELETE_EXPIRED_INTERVAL; // ms @@ -552,6 +553,7 @@ public class Controller extends Thread { final long repositoryBackupInterval = Settings.getInstance().getRepositoryBackupInterval(); final long repositoryCheckpointInterval = Settings.getInstance().getRepositoryCheckpointInterval(); long repositoryMaintenanceInterval = getRandomRepositoryMaintenanceInterval(); + final long prunePeersInterval = 5 * 60 * 1000L; // Every 5 minutes // Start executor service for trimming or pruning PruneManager.getInstance().start(); @@ -649,10 +651,15 @@ public class Controller extends Thread { } // Prune stuck/slow/old peers - try { - Network.getInstance().prunePeers(); - } catch (DataException e) { - LOGGER.warn(String.format("Repository issue when trying to prune peers: %s", e.getMessage())); + if (now >= prunePeersTimestamp + prunePeersInterval) { + prunePeersTimestamp = now + prunePeersInterval; + + try { + LOGGER.debug("Pruning peers..."); + Network.getInstance().prunePeers(); + } catch (DataException e) { + LOGGER.warn(String.format("Repository issue when trying to prune peers: %s", e.getMessage())); + } } // Delete expired transactions