-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize some hotspots #3214
Optimize some hotspots #3214
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -704,9 +704,10 @@ public void run() { | |||||
long now = System.currentTimeMillis(); | ||||||
long elapsed = now - lastReadTimeStamp; | ||||||
if (elapsed < 10) { | ||||||
log.debug("We got 2 network_messages received in less than 10 ms. We set the thread to sleep " + | ||||||
"for 20 ms to avoid getting flooded by our peer. lastReadTimeStamp={}, now={}, elapsed={}", | ||||||
lastReadTimeStamp, now, elapsed); | ||||||
if (log.isDebugEnabled()) | ||||||
log.debug("We got 2 network_messages received in less than 10 ms. We set the thread to sleep " + | ||||||
"for 20 ms to avoid getting flooded by our peer. lastReadTimeStamp={}, now={}, elapsed={}", | ||||||
lastReadTimeStamp, now, elapsed); | ||||||
Thread.sleep(20); | ||||||
} | ||||||
|
||||||
|
@@ -724,7 +725,8 @@ public void run() { | |||||
|
||||||
NetworkEnvelope networkEnvelope = networkProtoResolver.fromProto(proto); | ||||||
lastReadTimeStamp = now; | ||||||
log.debug("<< Received networkEnvelope of type: " + networkEnvelope.getClass().getSimpleName()); | ||||||
if (log.isDebugEnabled()) | ||||||
log.debug("<< Received networkEnvelope of type: " + networkEnvelope.getClass().getSimpleName()); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would instead suggest:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok that will still do the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far I understand it does it only at debug log level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it will have to do that call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i already changed it to his suggestion |
||||||
int size = proto.getSerializedSize(); | ||||||
// We comment out that part as only debug and trace log level is used. For debugging purposes | ||||||
|
@@ -761,7 +763,8 @@ public void run() { | |||||
boolean exceeds; | ||||||
if (networkEnvelope instanceof ExtendedDataSizePermission) { | ||||||
exceeds = size > MAX_PERMITTED_MESSAGE_SIZE; | ||||||
log.debug("size={}; object={}", size, Utilities.toTruncatedString(proto, 100)); | ||||||
if (log.isDebugEnabled()) | ||||||
log.debug("size={}; object={}", size, Utilities.toTruncatedString(proto, 100)); | ||||||
} else { | ||||||
exceeds = size > PERMITTED_MESSAGE_SIZE; | ||||||
} | ||||||
|
@@ -819,7 +822,8 @@ && reportInvalidRequest(RuleViolation.WRONG_NETWORK_ID)) { | |||||
|
||||||
if (networkEnvelope instanceof CloseConnectionMessage) { | ||||||
// If we get a CloseConnectionMessage we shut down | ||||||
log.debug("CloseConnectionMessage received. Reason={}\n\t" + | ||||||
if (log.isDebugEnabled()) | ||||||
log.debug("CloseConnectionMessage received. Reason={}\n\t" + | ||||||
"connection={}", proto.getCloseConnectionMessage().getReason(), this); | ||||||
if (CloseConnectionReason.PEER_BANNED.name().equals(proto.getCloseConnectionMessage().getReason())) { | ||||||
log.warn("We got shut down because we are banned by the other peer. (InputHandler.run CloseConnectionMessage)"); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,8 @@ public abstract class NetworkNode implements MessageListener { | |
|
||
public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddress, | ||
NetworkEnvelope networkEnvelope) { | ||
log.debug("sendMessage: peersNodeAddress=" + peersNodeAddress + "\n\tmessage=" + Utilities.toTruncatedString(networkEnvelope)); | ||
if (log.isDebugEnabled()) | ||
log.debug("sendMessage: peersNodeAddress=" + peersNodeAddress + "\n\tmessage=" + Utilities.toTruncatedString(networkEnvelope)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use the {} syntax instead of + There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point but it has no perfomance implications in that case. maybe + is even faster if we already checked for |
||
checkNotNull(peersNodeAddress, "peerAddress must not be null"); | ||
|
||
Connection connection = getOutboundConnection(peersNodeAddress); | ||
|
@@ -123,11 +124,13 @@ public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddr | |
try { | ||
// can take a while when using tor | ||
long startTs = System.currentTimeMillis(); | ||
log.debug("Start create socket to peersNodeAddress {}", peersNodeAddress.getFullAddress()); | ||
if (log.isDebugEnabled()) | ||
log.debug("Start create socket to peersNodeAddress {}", peersNodeAddress.getFullAddress()); | ||
Socket socket = createSocket(peersNodeAddress); | ||
long duration = System.currentTimeMillis() - startTs; | ||
log.debug("Socket creation to peersNodeAddress {} took {} ms", peersNodeAddress.getFullAddress(), | ||
duration); | ||
if (log.isDebugEnabled()) | ||
log.debug("Socket creation to peersNodeAddress {} took {} ms", peersNodeAddress.getFullAddress(), | ||
duration); | ||
|
||
if (duration > CREATE_SOCKET_TIMEOUT) | ||
throw new TimeoutException("A timeout occurred when creating a socket."); | ||
|
@@ -139,7 +142,8 @@ public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddr | |
existingConnection = getOutboundConnection(peersNodeAddress); | ||
|
||
if (existingConnection != null) { | ||
log.debug("We found in the meantime a connection for peersNodeAddress {}, " + | ||
if (log.isDebugEnabled()) | ||
log.debug("We found in the meantime a connection for peersNodeAddress {}, " + | ||
"so we use that for sending the message.\n" + | ||
"That can happen if Tor needs long for creating a new outbound connection.\n" + | ||
"We might have got a new inbound or outbound connection.", | ||
|
@@ -184,13 +188,14 @@ public void onError(Throwable throwable) { | |
peersNodeAddress, | ||
networkProtoResolver); | ||
|
||
log.debug("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + | ||
"NetworkNode created new outbound connection:" | ||
+ "\nmyNodeAddress=" + getNodeAddress() | ||
+ "\npeersNodeAddress=" + peersNodeAddress | ||
+ "\nuid=" + outboundConnection.getUid() | ||
+ "\nmessage=" + networkEnvelope | ||
+ "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); | ||
if (log.isDebugEnabled()) | ||
log.debug("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + | ||
"NetworkNode created new outbound connection:" | ||
+ "\nmyNodeAddress=" + getNodeAddress() | ||
+ "\npeersNodeAddress=" + peersNodeAddress | ||
+ "\nuid=" + outboundConnection.getUid() | ||
+ "\nmessage=" + networkEnvelope | ||
+ "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"); | ||
|
||
// can take a while when using tor | ||
outboundConnection.sendMessage(networkEnvelope); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been in the believe that this is exactly what
log.debug("{}", a)
does before the string is assembled?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as well that the expression is only executed if log level matches. the static string does not has much cost