Add selftest command. Use nice cpu priority.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 26 May 2024 05:30:51 +0000 (08:30 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 26 May 2024 05:30:51 +0000 (08:30 +0300)
doc/index.org
src/main/java/eu/svjatoslav/alyverkko_cli/AiTask.java
src/main/java/eu/svjatoslav/alyverkko_cli/Main.java
src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java [new file with mode: 0644]

index 290c028..03c7da6 100644 (file)
@@ -531,9 +531,6 @@ Ideas to be possibly implemented in the future:
 
 ** System operation
 
-- Implement CPU nice priority for inference processes to minimize the
-  impact on system responsiveness during heavy computations.
-
 - Enable model selection per individual inference task, allowing for
   dynamic adjustment based on task requirements.
 
index 2a7ca34..64baed0 100644 (file)
@@ -142,7 +142,10 @@ public class AiTask {
      */
     private String getCliCommand() {
 
+        int niceValue = 10; // Set the desired niceness level (10 is a common value for background tasks)
+
         return join(" ",
+                "nice", "-n", Integer.toString(niceValue),
                 configuration.getLlamaCppExecutablePath().getAbsolutePath(),
                 "--model " + model.filesystemPath,
                 "--threads " + configuration.getThreadCount(),
index 258a751..049f966 100644 (file)
@@ -2,6 +2,7 @@ package eu.svjatoslav.alyverkko_cli;
 
 import eu.svjatoslav.alyverkko_cli.commands.JoinFilesCommand;
 import eu.svjatoslav.alyverkko_cli.commands.ListModelsCommand;
+import eu.svjatoslav.alyverkko_cli.commands.SelftestCommand;
 import eu.svjatoslav.alyverkko_cli.configuration.Configuration;
 import eu.svjatoslav.alyverkko_cli.commands.MailCorrespondentCommand;
 
@@ -15,7 +16,8 @@ public class Main {
     private final java.util.List<Command> commands = java.util.Arrays.asList(
             new ListModelsCommand(),
             new MailCorrespondentCommand(),
-            new JoinFilesCommand()
+            new JoinFilesCommand(),
+            new SelftestCommand()
     );
 
     public static void main(final String[] args) throws IOException, InterruptedException {
diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/SelftestCommand.java
new file mode 100644 (file)
index 0000000..52843f1
--- /dev/null
@@ -0,0 +1,47 @@
+package eu.svjatoslav.alyverkko_cli.commands;
+
+import eu.svjatoslav.alyverkko_cli.Command;
+import eu.svjatoslav.alyverkko_cli.Main;
+
+import java.io.IOException;
+
+import static eu.svjatoslav.alyverkko_cli.Main.configuration;
+import static eu.svjatoslav.alyverkko_cli.configuration.Configuration.loadConfiguration;
+
+public class SelftestCommand implements Command {
+
+    @Override
+    public String getName() {
+        return "selftest";
+    }
+
+    @Override
+    public void execute(String[] cliArguments) throws IOException {
+        // Perform selftest checks here
+        System.out.println("Starting selftest...");
+
+        configuration = loadConfiguration();
+
+        // Check if the configuration is loaded
+        if (Main.configuration == null) {
+            System.err.println("Configuration not found or invalid.");
+            return;
+        }
+
+        // Validate models directory
+        if (!Main.configuration.getModelsDirectory().exists() || !Main.configuration.getModelsDirectory().isDirectory()) {
+            System.err.println("Models directory does not exist or is not a directory: " + Main.configuration.getModelsDirectory());
+            return;
+        }
+
+        // Validate llama.cpp executable path
+        if (!Main.configuration.getLlamaCppExecutablePath().exists() || !Main.configuration.getLlamaCppExecutablePath().isFile()) {
+            System.err.println("llama.cpp executable not found at: " + Main.configuration.getLlamaCppExecutablePath());
+            return;
+        }
+
+        // Additional checks like model file existence, etc., can be added here
+
+        System.out.println("Selftest completed successfully.");
+    }
+}