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

Commit d488a1d

Browse files
committed
Correct cpu load issues
1 parent cc5e8b8 commit d488a1d

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/main/java/com/iota/iri/service/milestone/impl/MilestoneSolidifierImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class MilestoneSolidifierImpl implements MilestoneSolidifier {
3535
/**
3636
* Defines the interval in which solidity checks are issued (in milliseconds).
3737
*/
38-
private static final int SOLIDIFICATION_INTERVAL = 500;
38+
private static final int SOLIDIFICATION_INTERVAL = 100;
3939

4040
/**
4141
* <p>

src/main/java/com/iota/iri/service/validation/impl/TransactionSolidifierImpl.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class TransactionSolidifierImpl implements TransactionSolidifier {
3535
*/
3636
private static final int MAX_SIZE= 10000;
3737

38+
private static final int SOLIDIFICATION_INTERVAL = 100;
39+
3840
private static final IntervalLogger log = new IntervalLogger(TransactionSolidifier.class);
3941

4042
/**
@@ -82,8 +84,8 @@ public TransactionSolidifierImpl(Tangle tangle, SnapshotProvider snapshotProvide
8284
*/
8385
@Override
8486
public void start(){
85-
executorService.silentExecute(this::processTransactionsToSolidify);
86-
87+
executorService.silentScheduleWithFixedDelay(this::processTransactionsToSolidify, 0,
88+
SOLIDIFICATION_INTERVAL, TimeUnit.MILLISECONDS);
8789
}
8890

8991
/**
@@ -100,14 +102,11 @@ public void shutdown() {
100102
@Override
101103
public void addToSolidificationQueue(Hash hash){
102104
try{
103-
if(!transactionsToSolidify.contains(hash)) {
104-
105-
if(transactionsToSolidify.size() >= MAX_SIZE - 1){
106-
transactionsToSolidify.remove();
107-
}
108-
109-
transactionsToSolidify.put(hash);
105+
if (transactionsToSolidify.size() >= MAX_SIZE - 1) {
106+
transactionsToSolidify.remove();
110107
}
108+
109+
transactionsToSolidify.put(hash);
111110
} catch(Exception e){
112111
log.error("Error placing transaction into solidification queue",e);
113112
}
@@ -157,16 +156,14 @@ public void clearFromBroadcastQueue(Set<TransactionViewModel> transactionsBroadc
157156
*/
158157
private void processTransactionsToSolidify(){
159158
Hash hash;
160-
while (!Thread.currentThread().isInterrupted()) {
161-
if((hash = transactionsToSolidify.poll()) != null) {
162-
try {
163-
checkSolidity(hash);
164-
} catch (Exception e) {
165-
log.info(e.getMessage());
166-
}
159+
if((hash = transactionsToSolidify.poll()) != null) {
160+
try {
161+
checkSolidity(hash);
162+
} catch (Exception e) {
163+
log.info(e.getMessage());
167164
}
168-
propagateSolidTransactions();
169165
}
166+
propagateSolidTransactions();
170167
}
171168

172169
/**
@@ -350,12 +347,11 @@ private boolean checkApproovee(TransactionViewModel approovee) throws Exception
350347

351348
@VisibleForTesting
352349
void propagateSolidTransactions() {
353-
Iterator<Hash> cascadeIterator = solidTransactions.iterator();
354350
int cascadeCount = 0;
355-
while(cascadeCount < MAX_SIZE && cascadeIterator.hasNext() && !Thread.currentThread().isInterrupted()) {
351+
while(!Thread.currentThread().isInterrupted() && solidTransactions.peek() != null && cascadeCount < MAX_SIZE) {
356352
try {
357353
cascadeCount += 1;
358-
Hash hash = cascadeIterator.next();
354+
Hash hash = solidTransactions.poll();
359355
TransactionViewModel transaction = fromHash(tangle, hash);
360356
Set<Hash> approvers = transaction.getApprovers(tangle).getHashes();
361357
for(Hash h: approvers) {
@@ -365,7 +361,6 @@ void propagateSolidTransactions() {
365361
tipsViewModel.setSolid(h);
366362
}
367363
}
368-
cascadeIterator.remove();
369364
} catch (Exception e) {
370365
log.error("Error while propagating solidity upwards", e);
371366
}

0 commit comments

Comments
 (0)