Minor performance improvement with lambda-based logging after initial profiling run

This commit is contained in:
catbref 2019-07-02 13:12:18 +01:00
parent 7b51b1e88d
commit a3e6c24a89
5 changed files with 22 additions and 25 deletions

View File

@ -144,7 +144,7 @@ public class Account {
AccountBalanceData accountBalanceData = new AccountBalanceData(this.address, assetId, balance); AccountBalanceData accountBalanceData = new AccountBalanceData(this.address, assetId, balance);
this.repository.getAccountRepository().save(accountBalanceData); this.repository.getAccountRepository().save(accountBalanceData);
LOGGER.trace(this.address + " balance now: " + balance.toPlainString() + " [assetId " + assetId + "]"); LOGGER.trace(() -> String.format("%s balance now %s [assetId %s]", this.address, balance.toPlainString(), assetId));
} }
public void deleteBalance(long assetId) throws DataException { public void deleteBalance(long assetId) throws DataException {
@ -227,7 +227,7 @@ public class Account {
accountData.setDefaultGroupId(defaultGroupId); accountData.setDefaultGroupId(defaultGroupId);
this.repository.getAccountRepository().setDefaultGroupId(accountData); this.repository.getAccountRepository().setDefaultGroupId(accountData);
LOGGER.trace(String.format("Account %s defaultGroupId now %d", accountData.getAddress(), defaultGroupId)); LOGGER.trace(() -> String.format("Account %s defaultGroupId now %d", accountData.getAddress(), defaultGroupId));
} }
// Account flags // Account flags

View File

@ -356,13 +356,13 @@ public class Controller extends Thread {
case NO_BLOCKCHAIN_LOCK: case NO_BLOCKCHAIN_LOCK:
case REPOSITORY_ISSUE: case REPOSITORY_ISSUE:
// These are minor failure results so fine to try again // These are minor failure results so fine to try again
LOGGER.info(String.format("Failed to synchronize with peer %s (%s)", peer, syncResult.name())); LOGGER.debug(() -> String.format("Failed to synchronize with peer %s (%s)", peer, syncResult.name()));
break; break;
case OK: case OK:
updateSysTray(); updateSysTray();
case NOTHING_TO_DO: case NOTHING_TO_DO:
LOGGER.debug(String.format("Synchronized with peer %s (%s)", peer, syncResult.name())); LOGGER.debug(() -> String.format("Synchronized with peer %s (%s)", peer, syncResult.name()));
break; break;
} }
@ -510,7 +510,7 @@ public class Controller extends Thread {
} }
public void onNetworkMessage(Peer peer, Message message) { public void onNetworkMessage(Peer peer, Message message) {
LOGGER.trace(String.format("Processing %s message from %s", message.getType().name(), peer)); LOGGER.trace(() -> String.format("Processing %s message from %s", message.getType().name(), peer));
switch (message.getType()) { switch (message.getType()) {
case HEIGHT: { case HEIGHT: {
@ -624,7 +624,7 @@ public class Controller extends Thread {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
BlockData blockData = repository.getBlockRepository().fromSignature(signature); BlockData blockData = repository.getBlockRepository().fromSignature(signature);
if (blockData == null) { if (blockData == null) {
LOGGER.debug(String.format("Ignoring GET_BLOCK request from peer %s for unknown block %s", peer, Base58.encode(signature))); LOGGER.debug(() -> String.format("Ignoring GET_BLOCK request from peer %s for unknown block %s", peer, Base58.encode(signature)));
// Send no response at all??? // Send no response at all???
break; break;
} }
@ -649,7 +649,7 @@ public class Controller extends Thread {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature); TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature);
if (transactionData == null) { if (transactionData == null) {
LOGGER.debug(String.format("Ignoring GET_TRANSACTION request from peer %s for unknown transaction %s", peer, Base58.encode(signature))); LOGGER.debug(() -> String.format("Ignoring GET_TRANSACTION request from peer %s for unknown transaction %s", peer, Base58.encode(signature)));
// Send no response at all??? // Send no response at all???
break; break;
} }
@ -674,28 +674,28 @@ public class Controller extends Thread {
// Check signature // Check signature
if (!transaction.isSignatureValid()) { if (!transaction.isSignatureValid()) {
LOGGER.trace(String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
break; break;
} }
ValidationResult validationResult = transaction.importAsUnconfirmed(); ValidationResult validationResult = transaction.importAsUnconfirmed();
if (validationResult == ValidationResult.TRANSACTION_ALREADY_EXISTS) { if (validationResult == ValidationResult.TRANSACTION_ALREADY_EXISTS) {
LOGGER.trace(String.format("Ignoring existing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Ignoring existing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
break; break;
} }
if (validationResult == ValidationResult.NO_BLOCKCHAIN_LOCK) { if (validationResult == ValidationResult.NO_BLOCKCHAIN_LOCK) {
LOGGER.trace(String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
break; break;
} }
if (validationResult != ValidationResult.OK) { if (validationResult != ValidationResult.OK) {
LOGGER.trace(String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
break; break;
} }
LOGGER.debug(String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer)); LOGGER.debug(() -> String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
} catch (DataException e) { } catch (DataException e) {
LOGGER.error(String.format("Repository issue while processing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer), e); LOGGER.error(String.format("Repository issue while processing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer), e);
} }
@ -725,7 +725,7 @@ public class Controller extends Thread {
for (byte[] signature : signatures) { for (byte[] signature : signatures) {
// Do we have it already? (Before requesting transaction data itself) // Do we have it already? (Before requesting transaction data itself)
if (repository.getTransactionRepository().exists(signature)) { if (repository.getTransactionRepository().exists(signature)) {
LOGGER.trace(String.format("Ignoring existing transaction %s from peer %s", Base58.encode(signature), peer)); LOGGER.trace(() -> String.format("Ignoring existing transaction %s from peer %s", Base58.encode(signature), peer));
continue; continue;
} }
@ -738,7 +738,7 @@ public class Controller extends Thread {
Message responseMessage = peer.getResponse(getTransactionMessage); Message responseMessage = peer.getResponse(getTransactionMessage);
if (responseMessage == null || !(responseMessage instanceof TransactionMessage)) { if (responseMessage == null || !(responseMessage instanceof TransactionMessage)) {
// Maybe peer no longer has this transaction // Maybe peer no longer has this transaction
LOGGER.trace(String.format("Peer %s didn't send transaction %s", peer, Base58.encode(signature))); LOGGER.trace(() -> String.format("Peer %s didn't send transaction %s", peer, Base58.encode(signature)));
continue; continue;
} }
@ -752,29 +752,29 @@ public class Controller extends Thread {
// Check signature // Check signature
if (!transaction.isSignatureValid()) { if (!transaction.isSignatureValid()) {
LOGGER.trace(String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Ignoring %s transaction %s with invalid signature from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
continue; continue;
} }
ValidationResult validationResult = transaction.importAsUnconfirmed(); ValidationResult validationResult = transaction.importAsUnconfirmed();
if (validationResult == ValidationResult.TRANSACTION_ALREADY_EXISTS) { if (validationResult == ValidationResult.TRANSACTION_ALREADY_EXISTS) {
LOGGER.trace(String.format("Ignoring existing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Ignoring existing transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
continue; continue;
} }
if (validationResult == ValidationResult.NO_BLOCKCHAIN_LOCK) { if (validationResult == ValidationResult.NO_BLOCKCHAIN_LOCK) {
LOGGER.trace(String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Couldn't lock blockchain to import unconfirmed transaction %s from peer %s", Base58.encode(transactionData.getSignature()), peer));
// Some other thread (e.g. Synchronizer) might have blockchain lock for a while so might as well give up for now // Some other thread (e.g. Synchronizer) might have blockchain lock for a while so might as well give up for now
break; break;
} }
if (validationResult != ValidationResult.OK) { if (validationResult != ValidationResult.OK) {
LOGGER.trace(String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer)); LOGGER.trace(() -> String.format("Ignoring invalid (%s) %s transaction %s from peer %s", validationResult.name(), transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
continue; continue;
} }
LOGGER.debug(String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer)); LOGGER.debug(() -> String.format("Imported %s transaction %s from peer %s", transactionData.getType().name(), Base58.encode(transactionData.getSignature()), peer));
// We could collate signatures that are new to us and broadcast them to our peers too // We could collate signatures that are new to us and broadcast them to our peers too
newSignatures.add(signature); newSignatures.add(signature);

View File

@ -842,9 +842,6 @@ public class Network extends Thread {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
List<PeerData> knownPeers = repository.getNetworkRepository().getAllPeers(); List<PeerData> knownPeers = repository.getNetworkRepository().getAllPeers();
for (PeerData peerData : knownPeers)
LOGGER.trace(String.format("Known peer %s", peerData.getAddress()));
// Filter out duplicates // Filter out duplicates
Predicate<PeerAddress> isKnownAddress = peerAddress -> { Predicate<PeerAddress> isKnownAddress = peerAddress -> {
return knownPeers.stream().anyMatch(knownPeerData -> knownPeerData.getAddress().equals(peerAddress)); return knownPeers.stream().anyMatch(knownPeerData -> knownPeerData.getAddress().equals(peerAddress));

View File

@ -345,7 +345,7 @@ public class Peer extends Thread {
return; return;
} }
LOGGER.trace(String.format("Received %s message with ID %d from peer %s", message.getType().name(), message.getId(), this)); LOGGER.trace(() -> String.format("Received %s message with ID %d from peer %s", message.getType().name(), message.getId(), this));
// Find potential blocking queue for this id (expect null if id is -1) // Find potential blocking queue for this id (expect null if id is -1)
BlockingQueue<Message> queue = this.replyQueues.get(message.getId()); BlockingQueue<Message> queue = this.replyQueues.get(message.getId());
@ -401,7 +401,7 @@ public class Peer extends Thread {
try { try {
// Send message // Send message
LOGGER.trace(String.format("Sending %s message with ID %d to peer %s", message.getType().name(), message.getId(), this)); LOGGER.trace(() -> String.format("Sending %s message with ID %d to peer %s", message.getType().name(), message.getId(), this));
synchronized (this.out) { synchronized (this.out) {
this.out.write(message.toBytes()); this.out.write(message.toBytes());

View File

@ -230,7 +230,7 @@ public class HSQLDBRepository implements Repository {
*/ */
public PreparedStatement prepareStatement(String sql) throws SQLException { public PreparedStatement prepareStatement(String sql) throws SQLException {
if (this.debugState) if (this.debugState)
LOGGER.debug(String.format("[%d] %s", this.sessionId, sql)); LOGGER.debug(() -> String.format("[%d] %s", this.sessionId, sql));
if (this.sqlStatements != null) if (this.sqlStatements != null)
this.sqlStatements.add(sql); this.sqlStatements.add(sql);