Skip to content

Commit

Permalink
#67 No accurate read speed on poc version that needs to be converted.
Browse files Browse the repository at this point in the history
  • Loading branch information
de-luxe committed May 27, 2018
1 parent 72a1cc0 commit 0a65c42
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 41 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<!-- add for older gpu -->
<!--<dependency>-->
<!--<groupId>org.jocl</groupId>-->
Expand Down Expand Up @@ -84,6 +89,12 @@
<artifactId>jackson-annotations</artifactId>
</dependency>

<!--<dependency>-->
<!--<groupId>junit</groupId>-->
<!--<artifactId>junit</artifactId>-->
<!--<scope>test</scope>-->
<!--</dependency>-->

</dependencies>

<build>
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/burstcoin/jminer/JMinerCommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,34 +220,38 @@ public void onApplicationEvent(ReaderProgressChangedEvent event)
{
progressLogStep--;

// done nonces percentage
BigDecimal totalCapacity = new BigDecimal(event.getCapacity());
BigDecimal factor = BigDecimal.ONE.divide(totalCapacity, MathContext.DECIMAL32);
BigDecimal progress = factor.multiply(new BigDecimal(event.getCapacity() - event.getRemainingCapacity()));
int percentage = (int) Math.ceil(progress.doubleValue() * 100);
percentage = percentage > 100 ? 100 : percentage;

// calculate capacity
// done nonce 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;


// read speed
long effMBPerSec = 0;
if(previousRemainingCapacity > 0)
{
long effDoneBytes = previousRemainingCapacity - event.getRemainingCapacity();
long effDoneBytes = previousRemainingCapacity - event.getRealRemainingCapacity();

// calculate current reading speed (since last info)
long elapsedTime = event.getElapsedTime() - previousElapsedTime;
long effBytesPerMs = (effDoneBytes / 4096) / (elapsedTime == 0 /*do not divide by zero*/ ? 1 : elapsedTime);
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;
long realDoneBytes = event.getRealCapacity() - event.getRealRemainingCapacity();

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

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

LOG.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

package burstcoin.jminer.core.network.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.io.Serializable;

/**
* The type Mining info response.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class MiningInfoResponse
implements Serializable
{
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/burstcoin/jminer/core/reader/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -87,9 +88,15 @@ public class Reader
public static volatile long blockNumber;
public static volatile byte[] generationSignature;
private Plots plots;

private Map<BigInteger, Long> realCapacityLookup;
private long realRemainingCapacity;
private long realCapacity;

private Map<BigInteger, Long> capacityLookup;
private long remainingCapacity;
private long capacity;

private long readerStartTime;
private int readerThreads;

Expand Down Expand Up @@ -133,6 +140,7 @@ protected void postConstruct()
scanPathsEveryRound = CoreProperties.isScanPathsEveryRound();
readerThreads = CoreProperties.getReaderThreads();
capacityLookup = new HashMap<>();
realCapacityLookup = new HashMap<>();

if(CoreProperties.isListPlotFiles())
{
Expand Down Expand Up @@ -175,12 +183,30 @@ public void read(long previousBlockNumber, long blockNumber, byte[] generationSi
capacityLookup.clear();
capacityLookup.putAll(plots.getChunkPartStartNonces());

realCapacityLookup.clear();
realCapacity = 0;
for(BigInteger chunkPartNonces : capacityLookup.keySet())
{
PlotFile plotFile = plots.getPlotFileByChunkPartStartNonce(chunkPartNonces);
long realChunkPartNoncesCapacity = isCompatibleWithCurrentPoc(blockNumber, plotFile.getPocVersion())
? capacityLookup.get(chunkPartNonces)
: 2 * capacityLookup.get(chunkPartNonces);
realCapacityLookup.put(chunkPartNonces, realChunkPartNoncesCapacity);
realCapacity+=realChunkPartNoncesCapacity;
}

remainingCapacity = plots.getSize();
capacity = plots.getSize();

realRemainingCapacity = realCapacity;
readerStartTime = new Date().getTime();

for(PlotDrive plotDrive : plots.getPlotDrives())
// order by slowest and biggest drives first
List<PlotDrive> orderedPlotDrives = new ArrayList<>(plots.getPlotDrives());
orderedPlotDrives.sort((o1, o2) -> Long.compare(o2.getSize(), o1.getSize())); // order by size
orderedPlotDrives.sort(Comparator.comparing(o -> isCompatibleWithCurrentPoc(blockNumber, o.getDrivePocVersion()))); // order by poc version

for(PlotDrive plotDrive : orderedPlotDrives)
{
PocVersion drivePocVersion = plotDrive.getDrivePocVersion();
if(drivePocVersion == null)
Expand Down Expand Up @@ -248,11 +274,14 @@ public void handleMessage(ReaderLoadedPartEvent event)
{
// update progress
Long removedCapacity = capacityLookup.remove(event.getChunkPartStartNonce());
Long realRemovedCapacity = realCapacityLookup.remove(event.getChunkPartStartNonce());
if(removedCapacity != null)
{
remainingCapacity -= removedCapacity;
realRemainingCapacity -= realRemovedCapacity;
long elapsedTime = new Date().getTime() - readerStartTime;
context.publishEvent(new ReaderProgressChangedEvent(this, event.getBlockNumber(), capacity, remainingCapacity, elapsedTime));
context.publishEvent(new ReaderProgressChangedEvent(this, event.getBlockNumber(), capacity, remainingCapacity,
realCapacity, realRemainingCapacity, elapsedTime));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Map<BigInteger, Long> getChunkPartStartNonces()
return chunkPartStartNonces;
}

PocVersion getPocVersion()
public PocVersion getPocVersion()
{
return pocVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,64 +34,50 @@ public class ReaderProgressChangedEvent
private long blockNumber;
private long capacity;
private long remainingCapacity;
private long realCapacity;
private long realRemainingCapacity;
private long elapsedTime;

/**
* Instantiates a new Reader progress changed event.
*
* @param source the source
* @param blockNumber the block number
* @param capacity the capacity
* @param remainingCapacity the remaining capacity
* @param elapsedTime the elapsed time
*/
public ReaderProgressChangedEvent(Reader source, long blockNumber, long capacity, long remainingCapacity, long elapsedTime)
public ReaderProgressChangedEvent(Reader source, long blockNumber, long capacity, long remainingCapacity,long realCapacity, long realRemainingCapacity,
long elapsedTime)
{
super(source);

this.blockNumber = blockNumber;
this.capacity = capacity;
this.remainingCapacity = remainingCapacity;
this.realCapacity = realCapacity;
this.realRemainingCapacity = realRemainingCapacity;
this.elapsedTime = elapsedTime;
}

/**
* Gets block number.
*
* @return the block number
*/
public long getBlockNumber()
{
return blockNumber;
}

/**
* Gets remaining capacity.
*
* @return the remaining capacity
*/
public long getRemainingCapacity()
{
return remainingCapacity;
}

/**
* Gets capacity.
*
* @return the capacity
*/
public long getCapacity()
{
return capacity;
}

/**
* Gets elapsed time.
*
* @return the elapsed time
*/
public long getElapsedTime()
{
return elapsedTime;
}

public long getRealCapacity()
{
return realCapacity;
}

public long getRealRemainingCapacity()
{
return realRemainingCapacity;
}
}

0 comments on commit 0a65c42

Please sign in to comment.