Add duration log for DaoStateMonitoringService

Creating the daoStateHash is quite expensive (about 20-30 ms/block).
As this happens while parsing it delays the parsing time (parsing is
very fast). We persist t the hashes so it is only done for new blocks.
For 1 month of blocks (4000) it would take about 80-120 seconds.
It is not blocking the user thread as it is done per block and those
are parsed one after another.
This commit is contained in:
chimp1984 2019-09-01 23:24:08 +02:00
parent 9db4d69276
commit 8521164adc
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3

View File

@ -117,6 +117,8 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
);
private boolean checkpointFailed;
private boolean ignoreDevMsg;
private int numCalls;
private long accumulatedDuration;
private final File storageDir;
@ -176,6 +178,12 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
if (!ignoreDevMsg) {
verifyCheckpoints();
}
log.info("ParseBlockChainComplete: Accumulated updateHashChain() calls for {} block took {} ms " +
"({} ms in average / block)",
numCalls,
accumulatedDuration,
(int) ((double) accumulatedDuration / (double) numCalls));
}
@Override
@ -277,6 +285,7 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
///////////////////////////////////////////////////////////////////////////////////////////
private void updateHashChain(Block block) {
long ts = System.currentTimeMillis();
byte[] prevHash;
int height = block.getHeight();
if (daoStateBlockChain.isEmpty()) {
@ -316,6 +325,13 @@ public class DaoStateMonitoringService implements DaoSetupService, DaoStateListe
int delayInSec = 5 + new Random().nextInt(10);
UserThread.runAfter(() -> daoStateNetworkService.broadcastMyStateHash(myDaoStateHash), delayInSec);
}
long duration = System.currentTimeMillis() - ts;
// We don't want to spam the outpu. We log accumulated time after parsing is completed.
log.trace("updateHashChain for block {} took {} ms",
block.getHeight(),
duration);
accumulatedDuration += duration;
numCalls++;
}
private boolean processPeersDaoStateHash(DaoStateHash daoStateHash, Optional<NodeAddress> peersNodeAddress,