A2.
Normally using SSH.NET, when client disconnected before its command has finished, It also stopped.
But I found "nohub" command allows commands keep running after disconnection.
Edit : No, whatever command alone couldn't solve this issue. I solved this eventually by shell class on SSH.NET
So I can reduce number of concurrent connection and FPS of Unity App has recovered.
Checking whether command has finished is other issue. It seems best options is parsing and handle with PID, but I'm using kind of shortcut for now.
A1.
I redesigned entire code and UbuntuWorker(alias) class has seperated to Ubuntu class and Worker class. So I can reduce number of task and I'm still finding optimized number for main machine.
Changed code is like this. (not exact code but simplified)
public class Ubuntu;
public class Worker;
public class Job;
ConCurrentQueue<Ubuntu> ubuntuQueue;
ConCurrentQueue<Job> jobQueue;
int numWorkers = 30; // half of machines
Worker[] workers = new Worker[numWorkers];
LoadUbuntu(ubuntuQueue);
LoadJob(jobQueue);
for (int i = 0; i < numWorkers; ++i)
{
workers[i] = new Worker();
workers[i].task = Task.Run(() =>
{
Ubuntu holder;
while (ubuntuQueue.TryDequeue(out holder))
{
if (holder.job.isDone)
{
SaveResult(holder.job.result);
if (jobQueue.TryDequeue(out holder.job))
{
holder.client.Connect();
using (var shell = holder.client.CreateShellStream("", 0, 0, 0, 0, 0))
{
shell.WriteLine(holder.job.GetCommand + " & disown -a");
await Task.Delay(3000); // give time for launching
}
holder.client.Disconnect();
}
else
continue;
}
ubuntuQueue.Enqueue(holder);
}
});
}
Entire performance has stabilized for now. Still need to prepare for expansion though.
Idea suggested by Dan Puzey (let Ubuntu pull jobs) has not implemented yet because I need to investigate how to make it first. I'm assuming building another C# code on Ubuntu is easiest way so I can reuse SSH.NET APIs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…