Skip to content

Commit

Permalink
#5 add optional plot-drive info output ;
Browse files Browse the repository at this point in the history
#4 eff.read is more likely the average read speed;
fixed reader and network thread prio from low to normal;
bugfixes in handling ReaderStoppedEvent;
  • Loading branch information
de-luxe committed Feb 15, 2016
1 parent 55ff7bd commit 2da67d3
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 34 deletions.
5 changes: 4 additions & 1 deletion jminer.default.properties
Expand Up @@ -158,6 +158,9 @@ connectionTimeout=12000
readProgressPerRound=9

# (default:true) switch between decimal units: TB/GB/MB (divided by 1000), or binary units TiB/GiB/MiB (divided by 1024) - https://en.wikipedia.org/wiki/Byte
sizeUnitsDecimal=true
byteUnitDecimal=true

# (default:false) shows info about every drive on finish reading it, useful to find the slow ones ...
showDriveInfo=false


3 changes: 1 addition & 2 deletions pom.xml
Expand Up @@ -14,15 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.8.RELEASE</version>
<version>1.3.2.RELEASE</version>
<relativePath/>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>burstcoin.jminer.CommandLineRunner</start-class>
<java.version>1.8</java.version>
<spring.version>4.2.4.RELEASE</spring.version>
<jetty.version>9.3.7.RC1</jetty.version>
<jocl.version>0.2.0-RC00</jocl.version>
<saphir-hash.version>3.0.1</saphir-hash.version>
Expand Down
67 changes: 49 additions & 18 deletions src/main/java/burstcoin/jminer/CommandLineRunner.java
Expand Up @@ -31,6 +31,7 @@
import burstcoin.jminer.core.network.event.NetworkStateChangeEvent;
import burstcoin.jminer.core.network.model.DevPoolResult;
import burstcoin.jminer.core.reader.event.ReaderCorruptFileEvent;
import burstcoin.jminer.core.reader.event.ReaderDriveFinishEvent;
import burstcoin.jminer.core.reader.event.ReaderProgressChangedEvent;
import burstcoin.jminer.core.round.Round;
import burstcoin.jminer.core.round.event.RoundFinishedEvent;
Expand All @@ -50,22 +51,23 @@
import java.util.Timer;
import java.util.TimerTask;


@SpringBootApplication
public class CommandLineRunner
{
private static final Logger LOG = LoggerFactory.getLogger(CommandLineRunner.class);

private static final int NUMBER_OF_PROGRESS_LOGS_PER_ROUND = CoreProperties.getReadProgressPerRound();
private static final int SIZE_DIVISOR = CoreProperties.isSizeUnitsDecimal() ? 1000 : 1024;
private static final String T_UNIT = CoreProperties.isSizeUnitsDecimal() ? "TB" : "TiB";
private static final String G_UNIT = CoreProperties.isSizeUnitsDecimal() ? "GB" : "GiB";
private static final int SIZE_DIVISOR = CoreProperties.isByteUnitDecimal() ? 1000 : 1024;
private static final String T_UNIT = CoreProperties.isByteUnitDecimal() ? "TB" : "TiB";
private static final String G_UNIT = CoreProperties.isByteUnitDecimal() ? "GB" : "GiB";

private static final String M_UNIT = CoreProperties.isSizeUnitsDecimal() ? "MB" : "MiB";
private static final String M_UNIT = CoreProperties.isByteUnitDecimal() ? "MB" : "MiB";
private static ConfigurableApplicationContext context;
private static boolean roundFinished = true;
private static long blockNumber;
private static int progressLogStep;
private static long previousRemainingCapacity = 0;
private static long previousElapsedTime = 0;

public static void main(String[] args)
{
Expand Down Expand Up @@ -115,6 +117,8 @@ public void run()
public void onApplicationEvent(RoundFinishedEvent event)
{
roundFinished = true;
previousRemainingCapacity = 0;
previousElapsedTime = 0;

long s = event.getRoundTime() / 1000;
long ms = event.getRoundTime() % 1000;
Expand All @@ -132,6 +136,8 @@ public void onApplicationEvent(RoundFinishedEvent event)
public void onApplicationEvent(RoundStoppedEvent event)
{
roundFinished = true;
previousRemainingCapacity = 0;
previousElapsedTime = 0;

long s = event.getElapsedTime() / 1000;
long ms = event.getElapsedTime() % 1000;
Expand All @@ -143,9 +149,9 @@ public void onApplicationEvent(RoundStoppedEvent event)
percentage = percentage > 100 ? 100 : percentage;

String bestDeadline = Long.MAX_VALUE == event.getBestCommittedDeadline() ? "N/A" : String.valueOf(event.getBestCommittedDeadline());
LOG.info("NOT FINISHED block '" + event.getBlockNumber() + "', "
LOG.info("STOP block '" + event.getBlockNumber() + "', " + String.valueOf(percentage) + "% done, "
+ "best deadline '" + bestDeadline + "', "
+ "elapsed time '" + s + "s " + ms + "ms', " + String.valueOf(percentage) + "% done!");
+ "elapsed time '" + s + "s " + ms + "ms'");
}
});

Expand Down Expand Up @@ -209,17 +215,32 @@ public void onApplicationEvent(ReaderProgressChangedEvent event)
int percentage = (int) Math.ceil(progress.doubleValue() * 100);
percentage = percentage > 100 ? 100 : percentage;

// calculate capacity
long effMBPerSec = 0;
if(previousRemainingCapacity > 0)
{
long effDoneBytes = previousRemainingCapacity - event.getRemainingCapacity();

// calculate current reading speed (since last info)
long effBytesPerMs = (effDoneBytes / 4096) / (event.getElapsedTime()-previousElapsedTime);
effMBPerSec = (effBytesPerMs * 1000) / SIZE_DIVISOR / SIZE_DIVISOR;
}

// calculate capacity
long doneBytes = event.getCapacity() - event.getRemainingCapacity();
long doneTB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR;
long doneGB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR % SIZE_DIVISOR;

// calculate reading speed
long effectiveBytesPerMs = (doneBytes / 4096) / event.getElapsedTime();
long effectiveMBPerSec = (effectiveBytesPerMs * 1000) / SIZE_DIVISOR / SIZE_DIVISOR;
// calculate reading speed (average)
long averageBytesPerMs = (doneBytes / 4096) / event.getElapsedTime();
long averageMBPerSec = (averageBytesPerMs * 1000) / SIZE_DIVISOR / SIZE_DIVISOR;

previousRemainingCapacity = event.getRemainingCapacity();
previousElapsedTime = event.getElapsedTime();

LOG.info(
String.valueOf(percentage) + "% done (" + doneTB + T_UNIT + " " + doneGB + G_UNIT + "), eff.read '" + effectiveMBPerSec + " " + M_UNIT + "/s'");
String.valueOf(percentage) + "% done (" + doneTB + T_UNIT + " " + doneGB + G_UNIT + "), avg.'" + averageMBPerSec + " " + M_UNIT + "/s'" +
(effMBPerSec > 0 ? ", eff.'" + effMBPerSec + " " + M_UNIT + "/s'" : ""));
}
}
});
Expand Down Expand Up @@ -287,14 +308,24 @@ public void onApplicationEvent(ReaderCorruptFileEvent event)
}
});

context.addApplicationListener(new ApplicationListener<ReaderDriveFinishEvent>()
{
@Override
public void onApplicationEvent(ReaderDriveFinishEvent event)
{
// calculate capacity
long doneBytes = event.getSize();
long doneTB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR;
long doneGB = doneBytes / SIZE_DIVISOR / SIZE_DIVISOR / SIZE_DIVISOR % SIZE_DIVISOR;

long s = event.getTime() / 1000;
long ms = event.getTime() % 1000;

LOG.info("read '"+event.getDirectory()+ "' (" + doneTB + T_UNIT + " " + doneGB + G_UNIT + ") in '" + s + "s " + ms + "ms'");
}
});

LOG.info("");
// LOG.info("::::::::: ::: ::: ::::::::: :::::::: ::::::::::::");
// LOG.info(":+: :+: :+: :+: :+: :+: :+: :+:");
// LOG.info("+#++:++#+ +#+ +:+ +#++:++#: +#++:++#++ +#+");
// LOG.info("+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+");
// LOG.info("#+# #+# #+# #+# #+# #+# #+# #+#");
// LOG.info("######### ######## ### ### BURSTCOIN ###");
// LOG.info("::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
LOG.info(" Burstcoin (BURST)");
LOG.info(" __ __ GPU assisted PoC-Miner");
LOG.info(" |__| _____ |__| ____ ___________ ");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/burstcoin/jminer/core/CoreConfig.java
Expand Up @@ -49,7 +49,8 @@ public class CoreConfig
public ThreadPoolTaskExecutor readerPool()
{
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
pool.setThreadPriority(2);
pool.setThreadPriority(Thread.NORM_PRIORITY);
// tasks will interrupt them self and stop fast.
pool.setWaitForTasksToCompleteOnShutdown(true);
return pool;
}
Expand All @@ -64,7 +65,7 @@ public ThreadPoolTaskExecutor networkPool()
{
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
pool.setMaxPoolSize(2);
pool.setThreadPriority(1);
pool.setThreadPriority(Thread.NORM_PRIORITY + 1);
pool.setWaitForTasksToCompleteOnShutdown(true);
return pool;
}
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/burstcoin/jminer/core/CoreProperties.java
Expand Up @@ -59,8 +59,9 @@ public class CoreProperties
private static final int DEFAULT_WINNER_RETRY_INTERVAL_IN_MS = 500;
private static final boolean DEFAULT_SCAN_PATHS_EVERY_ROUND = false;
private static final int DEFAULT_DEV_POOL_COMMITS_PER_ROUND = 3;
private static final boolean DEFAULT_SIZE_UNITS_DECIMAL = true;
private static final boolean DEFAULT_BYTE_UNIT_DECIMAL = true;
private static final boolean DEFAULT_LIST_PLOT_FILES = false;
private static final boolean DEFAULT_SHOW_DRIVE_INFO = false;
// there seams to be a issue on checker
private static final boolean DEFAULT_OPT_DEV_POOL = false;

Expand Down Expand Up @@ -98,8 +99,9 @@ public class CoreProperties
private static String soloServer;
private static String passPhrase;
private static String poolServer;
private static Boolean sizeUnitsDecimal;
private static Boolean byteUnitDecimal;
private static Boolean listPlotFiles;
private static Boolean showDriveInfo;

private CoreProperties()
{
Expand Down Expand Up @@ -430,13 +432,13 @@ public static long getChunkPartNonces()
return chunkPartNonces;
}

public static boolean isSizeUnitsDecimal()
public static boolean isByteUnitDecimal()
{
if(sizeUnitsDecimal == null)
if(byteUnitDecimal == null)
{
sizeUnitsDecimal = asBoolean("sizeUnitsDecimal", DEFAULT_SIZE_UNITS_DECIMAL);
byteUnitDecimal = asBoolean("byteUnitDecimal", DEFAULT_BYTE_UNIT_DECIMAL);
}
return sizeUnitsDecimal;
return byteUnitDecimal;
}

public static boolean isListPlotFiles()
Expand All @@ -448,6 +450,15 @@ public static boolean isListPlotFiles()
return listPlotFiles;
}

public static boolean isShowDriveInfo()
{
if(showDriveInfo == null)
{
showDriveInfo = asBoolean("showDriveInfo", DEFAULT_SHOW_DRIVE_INFO);
}
return showDriveInfo;
}

private static Boolean asBoolean(String key, boolean defaultValue)
{
String booleanProperty = PROPS.containsKey(key) ? String.valueOf(PROPS.getProperty(key)) : null;
Expand Down
@@ -0,0 +1,58 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
*
* 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 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 burstcoin.jminer.core.reader.event;


import org.springframework.context.ApplicationEvent;

public class ReaderDriveFinishEvent
extends ApplicationEvent
{
private String directory;
private long size;
private long time;

public ReaderDriveFinishEvent(String directory, long size, long time)
{
super(directory);

this.directory = directory;
this.size = size;
this.time = time;
}

public long getTime()
{
return time;
}

public String getDirectory()
{
return directory;
}

public long getSize()
{
return size;
}
}
Expand Up @@ -23,8 +23,10 @@
package burstcoin.jminer.core.reader.task;


import burstcoin.jminer.core.CoreProperties;
import burstcoin.jminer.core.reader.data.PlotDrive;
import burstcoin.jminer.core.reader.data.PlotFile;
import burstcoin.jminer.core.reader.event.ReaderDriveFinishEvent;
import burstcoin.jminer.core.reader.event.ReaderLoadedPartEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -41,13 +43,13 @@
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.StandardOpenOption;
import java.util.Date;
import java.util.EnumSet;


/**
* The type Reader load drive task.
* Executed once for every block ... reads scoops of drive plots
*/
/* executed once for every block ... reads scoops of drive plots */
@Component
@Scope("prototype")
public class ReaderLoadDriveTask
Expand All @@ -61,25 +63,30 @@ public class ReaderLoadDriveTask
private PlotDrive plotDrive;
private int scoopNumber;
private long blockNumber;
private boolean showDriveInfo;

/**
* Init void.
*
* @param scoopNumber the scoop number
* @param blockNumber the block number
* @param plotDrive the plot drive
* @param plotDrive the plot drive
*/
public void init(int scoopNumber, long blockNumber, PlotDrive plotDrive)
{
this.scoopNumber = scoopNumber;
this.blockNumber = blockNumber;

this.plotDrive = plotDrive;

showDriveInfo = CoreProperties.isShowDriveInfo();
}

@Override
public void run()
{
long startTime = showDriveInfo ? new Date().getTime() : 0;

for(PlotFile plotPathInfo : plotDrive.getPlotFiles())
{
if(plotPathInfo.getStaggeramt() % plotPathInfo.getNumberOfParts() > 0)
Expand All @@ -90,6 +97,11 @@ public void run()
}
load(plotPathInfo);
}

if(showDriveInfo)
{
publisher.publishEvent(new ReaderDriveFinishEvent(plotDrive.getDirectory(), plotDrive.getSize(), new Date().getTime() - startTime));
}
}

private void load(PlotFile plotFile)
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/burstcoin/jminer/core/round/Round.java
Expand Up @@ -371,8 +371,7 @@ public void handleMessage(NetworkResultErrorEvent event)
@EventListener
public void handleMessage(ReaderStoppedEvent event)
{
finishedBlockNumber = event.getBlockNumber();
System.gc();
triggerGarbageCollection();
fireEvent(new RoundStoppedEvent(event.getBlockNumber(), event.getLastBestCommittedDeadline(), event.getCapacity(), event.getRemainingCapacity(),
event.getElapsedTime()));
}
Expand Down

0 comments on commit 2da67d3

Please sign in to comment.