Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
Correct cpu load issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DyrellC committed Feb 26, 2020
1 parent cc5e8b8 commit d488a1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MilestoneSolidifierImpl implements MilestoneSolidifier {
/**
* Defines the interval in which solidity checks are issued (in milliseconds).
*/
private static final int SOLIDIFICATION_INTERVAL = 500;
private static final int SOLIDIFICATION_INTERVAL = 100;

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class TransactionSolidifierImpl implements TransactionSolidifier {
*/
private static final int MAX_SIZE= 10000;

private static final int SOLIDIFICATION_INTERVAL = 100;

private static final IntervalLogger log = new IntervalLogger(TransactionSolidifier.class);

/**
Expand Down Expand Up @@ -82,8 +84,8 @@ public TransactionSolidifierImpl(Tangle tangle, SnapshotProvider snapshotProvide
*/
@Override
public void start(){
executorService.silentExecute(this::processTransactionsToSolidify);

executorService.silentScheduleWithFixedDelay(this::processTransactionsToSolidify, 0,
SOLIDIFICATION_INTERVAL, TimeUnit.MILLISECONDS);
}

/**
Expand All @@ -100,14 +102,11 @@ public void shutdown() {
@Override
public void addToSolidificationQueue(Hash hash){
try{
if(!transactionsToSolidify.contains(hash)) {

if(transactionsToSolidify.size() >= MAX_SIZE - 1){
transactionsToSolidify.remove();
}

transactionsToSolidify.put(hash);
if (transactionsToSolidify.size() >= MAX_SIZE - 1) {
transactionsToSolidify.remove();
}

transactionsToSolidify.put(hash);
} catch(Exception e){
log.error("Error placing transaction into solidification queue",e);
}
Expand Down Expand Up @@ -157,16 +156,14 @@ public void clearFromBroadcastQueue(Set<TransactionViewModel> transactionsBroadc
*/
private void processTransactionsToSolidify(){
Hash hash;
while (!Thread.currentThread().isInterrupted()) {
if((hash = transactionsToSolidify.poll()) != null) {
try {
checkSolidity(hash);
} catch (Exception e) {
log.info(e.getMessage());
}
if((hash = transactionsToSolidify.poll()) != null) {
try {
checkSolidity(hash);
} catch (Exception e) {
log.info(e.getMessage());
}
propagateSolidTransactions();
}
propagateSolidTransactions();
}

/**
Expand Down Expand Up @@ -350,12 +347,11 @@ private boolean checkApproovee(TransactionViewModel approovee) throws Exception

@VisibleForTesting
void propagateSolidTransactions() {
Iterator<Hash> cascadeIterator = solidTransactions.iterator();
int cascadeCount = 0;
while(cascadeCount < MAX_SIZE && cascadeIterator.hasNext() && !Thread.currentThread().isInterrupted()) {
while(!Thread.currentThread().isInterrupted() && solidTransactions.peek() != null && cascadeCount < MAX_SIZE) {
try {
cascadeCount += 1;
Hash hash = cascadeIterator.next();
Hash hash = solidTransactions.poll();
TransactionViewModel transaction = fromHash(tangle, hash);
Set<Hash> approvers = transaction.getApprovers(tangle).getHashes();
for(Hash h: approvers) {
Expand All @@ -365,7 +361,6 @@ void propagateSolidTransactions() {
tipsViewModel.setSolid(h);
}
}
cascadeIterator.remove();
} catch (Exception e) {
log.error("Error while propagating solidity upwards", e);
}
Expand Down

0 comments on commit d488a1d

Please sign in to comment.