Skip to content

Commit

Permalink
fix stderr exception on ssh connection
Browse files Browse the repository at this point in the history
fix update stat queue contention
change default start param
  • Loading branch information
ortis committed Jul 4, 2018
1 parent 7ea83bc commit f44dd85
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 78 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Mochimo Farm Manager installation:
6. `stopCommand`: stop command of the miner. If not specified, a `kill` command is send
7. `logCommand`: command to retrieve miner's log.
4. *Higly Recommended*: encrypt your configuration file </br> `java -jar mochimo-farm-manager-version.jar encrypt plain_text_config.json encrypted_config.json`
5. Check out the running options `java -jar mochimo-farm-manager-version.jar start -h`
6. Start the manager `java -jar mochimo-farm-manager-version.jar start mining_farm_config.json html`.
5. Check out start option `java -jar mochimo-farm-manager-version.jar start -h`
6. Start the manager `java -jar mochimo-farm-manager-version.jar start mining_farm_config.json html`
7. Access the dashboard http://localhost


Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>farm_manager</name>
<groupId>org.ortis.mochimo</groupId>
<artifactId>mochimo-farm-manager</artifactId>
<version>0.1</version>
<version>0.2</version>
<packaging>jar</packaging>


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ortis/mochimo/farm_manager/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

public class Version
{
public static final String VERSION = "v0.1 beta";
public static final String VERSION = "v0.2 beta";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Paths;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -63,10 +64,10 @@ public class Start implements Callable<Void>
private String hostBind = "127.0.0.1:80";

@Option(names = { "-sp", "--statistics-parallelism" }, paramLabel = "statistics_parallelism", description = "Number of statistics computing thread")
private int statParallelism = 3;
private int statParallelism = 6;

@Option(names = { "-sh", "--statistics-heartbeat" }, paramLabel = "statistics_heartbeat", description = "Delay between statistic computation in seconds")
private int statHeartbeat = 30;
private int statHeartbeat = 60;

@Option(names = { "-hp", "--http-parallelism" }, paramLabel = "http_parallelism", description = "Number of http handler thread")
private int httpParallelism = 5;
Expand Down Expand Up @@ -98,7 +99,7 @@ public LocalDateTime get()
}
};

switch (this.logLevel)
switch (this.logLevel.toUpperCase(Locale.ENGLISH))
{
case "ERROR":
LogFactory.setLevel(Level.SEVERE);
Expand Down
31 changes: 11 additions & 20 deletions src/main/java/org/ortis/mochimo/farm_manager/farm/MiningFarm.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
/*******************************************************************************
* Copyright (C) 2018 Ortis (cao.ortis.org@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
* SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/

package org.ortis.mochimo.farm_manager.farm;

import java.io.IOException;
Expand All @@ -35,10 +28,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -123,15 +114,15 @@ public MiningFarm(final MiningFarmConfig config, final Duration statisticsUpdate
this.miners.add(miner);
}

final BlockingQueue<Miner> statisticsUpdateQueue = new LinkedBlockingQueue<>();
final TaskBoard taskBoard = new TaskBoard(Duration.ofMillis(1000), LogFactory.getLogger("TaskBoard"));
this.statisticUpdateSchedulerThread = new Thread(
new StatisticsUpdateScheduler(this, Duration.ofMillis(Math.max(1000, statisticsUpdateHeartbeat.toMillis() / 10)), statisticsUpdateHeartbeat, statisticsUpdateQueue, this.clock, log));
new StatisticsUpdateScheduler(this, Duration.ofMillis(Math.max(1000, statisticsUpdateHeartbeat.toMillis() / 10)), statisticsUpdateHeartbeat, taskBoard, this.clock, log));
this.statisticUpdateSchedulerThread.setName("StatisticsUpdateScheduler");
this.statisticsPool = Executors.newFixedThreadPool(statisticsParallelism);

for (int i = 0; i < statisticsParallelism; i++)
{
final StatisticsUpdater su = new StatisticsUpdater(statisticsUpdateQueue, log);
final StatisticsUpdater su = new StatisticsUpdater(taskBoard, log);
this.statisticsPool.submit(su);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.function.Supplier;
import java.util.logging.Logger;

Expand All @@ -37,7 +35,7 @@ public class StatisticsUpdateScheduler implements Runnable
private final MiningFarm farm;
private final Duration checkHeartbeat;
private final Duration updateHeartbeat;
private final Queue<Miner> queue;
private final TaskBoard taskBoard;
private final Supplier<LocalDateTime> clock;
private Logger log;

Expand All @@ -53,7 +51,7 @@ public class StatisticsUpdateScheduler implements Runnable
* pending update queue
* @param log
*/
public StatisticsUpdateScheduler(final MiningFarm farm, final Duration checkHeartbeat, final Duration updateHeartbeat, final BlockingQueue<Miner> queue, final Supplier<LocalDateTime> clock,
public StatisticsUpdateScheduler(final MiningFarm farm, final Duration checkHeartbeat, final Duration updateHeartbeat, final TaskBoard taskBoard, final Supplier<LocalDateTime> clock,
final Logger log)
{
this.farm = farm;
Expand All @@ -65,7 +63,7 @@ public StatisticsUpdateScheduler(final MiningFarm farm, final Duration checkHear
if (this.updateHeartbeat.isNegative() || this.updateHeartbeat.isZero())
throw new IllegalArgumentException("Update heartbeat duration must be positive");

this.queue = queue;
this.taskBoard = taskBoard;
this.clock = clock;
this.log = log;

Expand All @@ -84,21 +82,24 @@ public void run()
for (final Miner miner : farm.getMiners())
{

if (this.queue.contains(miner))
if (this.taskBoard.contains(miner))
{
this.log.finest("Statistics update of miner " + miner + " is already pending. Skipping");
this.log.finest("Statistics update task of miner " + miner + " is already pending. Skipping");
continue;
}

if (miner.getStatistics().isDefault() || Duration.between(miner.getStatistics().getTime(), this.clock.get()).compareTo(this.updateHeartbeat) > 0)
final boolean def = miner.getStatistics().isDefault();
final Duration elpased = Duration.between(miner.getStatistics().getTime(), this.clock.get());
if (def || elpased.compareTo(this.updateHeartbeat) > 0)
{

this.log.fine("Requesting update for miner " + miner);
this.queue.add(miner);
this.taskBoard.add(miner);
}

}

this.log.fine("Pending statistics update -> " + this.queue.size());
this.log.fine("Pending statistics update -> " + this.taskBoard.pendingSize());

final long elapsed = System.currentTimeMillis() - start;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

package org.ortis.mochimo.farm_manager.farm;

import java.util.concurrent.Callable;

import org.ortis.mochimo.farm_manager.farm.miner.Miner;

public class StatisticsUpdateTask implements Callable<Void>
{
private final Miner miner;

private Object owner;
private final Object lock = new Object();

public StatisticsUpdateTask(final Miner miner)
{
this.miner = miner;

}

public boolean acquire(final Object bidder)
{
synchronized (this.lock)
{

if (this.owner == null)
{
this.owner = bidder;
return true;
} else
return false;

}
}

@Override
public Void call() throws Exception
{
this.miner.updateStatistics();

return null;
}

public Miner getMiner()
{
return miner;
}

@Override
public int hashCode()
{
return this.miner.hashCode();
}

@Override
public boolean equals(final Object o)
{
if (o == this.miner)
return true;

if (o instanceof StatisticsUpdateTask)
{
final StatisticsUpdateTask task = (StatisticsUpdateTask) o;

return task.getMiner().equals(this.miner);
}

return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
/*******************************************************************************
* Copyright (C) 2018 Ortis (cao.ortis.org@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
* SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/

package org.ortis.mochimo.farm_manager.farm;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import org.ortis.mochimo.farm_manager.farm.miner.Miner;
import org.ortis.mochimo.farm_manager.farm.miner.MinerStatistics;
import org.ortis.mochimo.farm_manager.utils.Utils;

Expand All @@ -38,12 +28,12 @@
public class StatisticsUpdater implements Runnable
{

private final BlockingQueue<Miner> queue;
private final TaskBoard taskBoard;
private final Logger log;

public StatisticsUpdater(final BlockingQueue<Miner> queue, final Logger log)
public StatisticsUpdater(final TaskBoard taskBoard, final Logger log)
{
this.queue = queue;
this.taskBoard = taskBoard;
this.log = log;
}

Expand All @@ -54,24 +44,7 @@ public void run()
try
{
while (!Thread.interrupted())
{

final Miner miner = this.queue.poll(1000, TimeUnit.MILLISECONDS);

if (miner == null)
continue;

this.log.fine("Updating statistics for miner" + miner);

try
{
miner.updateStatistics();
} catch (final Exception e)
{
this.log.severe("Error while updating miner " + miner + " -> " + Utils.formatException(e));
}

}
this.taskBoard.execute();

} catch (final InterruptedException e)
{
Expand Down
Loading

0 comments on commit f44dd85

Please sign in to comment.