refactor: optimize the bot even more!!!
it improved a lot, memory usage is pretty good now, just reducing the amount of threads for each executor and adding some more delay to the filtering stuff
This commit is contained in:
@@ -27,11 +27,11 @@ public class Main {
|
||||
public static final List<Bot> bots = new ArrayList<>();
|
||||
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
Math.max(1, Runtime.getRuntime().availableProcessors() / 2),
|
||||
new ThreadFactoryBuilder().setNameFormat("ExecutorService #%d").build()
|
||||
);
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
Math.max(1, Runtime.getRuntime().availableProcessors() / 2),
|
||||
new ThreadFactoryBuilder().setNameFormat("ScheduledExecutorService #%d").build()
|
||||
);
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import java.util.concurrent.Executors;
|
||||
public class DatabasePlugin {
|
||||
// is it OK to have a completely separate ExecutorService to do the executions?
|
||||
public static final ExecutorService executorService = Executors.newFixedThreadPool(
|
||||
Runtime.getRuntime().availableProcessors(),
|
||||
new ThreadFactoryBuilder().setNameFormat("ExecutorService (database) #%d").build()
|
||||
1,
|
||||
new ThreadFactoryBuilder().setNameFormat("ExecutorService (database)").build()
|
||||
);
|
||||
|
||||
public Connection connection;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class IPFilterPlugin extends PlayersPlugin.Listener {
|
||||
}
|
||||
});
|
||||
|
||||
Main.executor.scheduleAtFixedRate(IPFilterPlugin::list, 3, 5, TimeUnit.SECONDS);
|
||||
Main.executor.scheduleAtFixedRate(IPFilterPlugin::list, 5, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PlayerFilterPlugin extends PlayersPlugin.Listener {
|
||||
}
|
||||
});
|
||||
|
||||
Main.executor.scheduleAtFixedRate(PlayerFilterPlugin::list, 3, 5, TimeUnit.SECONDS);
|
||||
Main.executor.scheduleAtFixedRate(PlayerFilterPlugin::list, 5, 30, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package me.chayapak1.chomens_bot.util;
|
||||
|
||||
import me.chayapak1.chomens_bot.Main;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -11,6 +14,7 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@@ -29,7 +33,11 @@ public class FileLoggerUtilities {
|
||||
public static String prevEntry = "";
|
||||
public static int duplicateCounter = 1;
|
||||
|
||||
public static final ScheduledExecutorService executor = Main.executor;
|
||||
// we want a completely separate executor from the main one
|
||||
public static final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(
|
||||
new ThreadFactoryBuilder().setNameFormat("ScheduledExecutorService (logger)").build()
|
||||
);
|
||||
|
||||
public static int spamLevel = 0;
|
||||
public static long freezeTime = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user