From 160e6933d3c6a40fdd9c9f10548bc200cd80e1d0 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 25 Jun 2022 10:19:06 +0100 Subject: [PATCH] Allow disabling pubsub timer to lower cpu usage. (#289) --- config.properties | 2 ++ src/main/java/me/kavin/piped/Main.java | 31 ++++++++++--------- .../java/me/kavin/piped/consts/Constants.java | 3 ++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/config.properties b/config.properties index d0ec253..0feee2d 100644 --- a/config.properties +++ b/config.properties @@ -19,6 +19,8 @@ COMPROMISED_PASSWORD_CHECK:true DISABLE_REGISTRATION:false # Feed Retention Time in Days FEED_RETENTION:30 +# Disable CPU expensive timers (for nodes with low CPU, at least one node should have this disabled) +DISABLE_TIMERS:false # Hibernate properties hibernate.connection.url:jdbc:postgresql://postgres:5432/piped hibernate.connection.driver_class:org.postgresql.Driver diff --git a/src/main/java/me/kavin/piped/Main.java b/src/main/java/me/kavin/piped/Main.java index e097ee6..fc42324 100644 --- a/src/main/java/me/kavin/piped/Main.java +++ b/src/main/java/me/kavin/piped/Main.java @@ -30,6 +30,23 @@ public class Main { Injector.useSpecializer(); + new Timer().scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + try { + System.out.println(String.format("ThrottlingCache: %o entries", YoutubeThrottlingDecrypter.getCacheSize())); + YoutubeThrottlingDecrypter.clearCache(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }, 0, TimeUnit.MINUTES.toMillis(60)); + + new ServerLauncher().launch(args); + + if (Constants.DISABLE_TIMERS) + return; + new Timer().scheduleAtFixedRate(new TimerTask() { @Override public void run() { @@ -83,19 +100,5 @@ public class Main { } }, 0, TimeUnit.MINUTES.toMillis(60)); - new Timer().scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - try { - System.out.println(String.format("ThrottlingCache: %o entries", YoutubeThrottlingDecrypter.getCacheSize())); - YoutubeThrottlingDecrypter.clearCache(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }, 0, TimeUnit.MINUTES.toMillis(60)); - - new ServerLauncher().launch(args); - } } diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index a1a1a2e..6990876 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -47,6 +47,8 @@ public class Constants { public static final int FEED_RETENTION; + public static final boolean DISABLE_TIMERS; + public static final String VERSION; public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class); @@ -72,6 +74,7 @@ public class Constants { COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(getProperty(prop, "COMPROMISED_PASSWORD_CHECK", "true")); DISABLE_REGISTRATION = Boolean.parseBoolean(getProperty(prop, "DISABLE_REGISTRATION", "false")); FEED_RETENTION = Integer.parseInt(getProperty(prop, "FEED_RETENTION", "30")); + DISABLE_TIMERS = Boolean.parseBoolean(getProperty(prop, "DISABLE_TIMERS", "false")); System.getenv().forEach((key, value) -> { if (key.startsWith("hibernate")) hibernateProperties.put(key, value);