-
Notifications
You must be signed in to change notification settings - Fork 685
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
p2p: Track/log peer uptime and received msg stats #1057
Conversation
I ran a mainnet node with this for a few minutes and saw some bursts of Transaction messages from a few peers that caused the ChainSyncer's msg queue to fill up and cause msgs to be dropped. As shown below, some peers sent us 23k Transaction msgs in less than 10 minutes. Don't know if this is normal, but something to consider when addressing #1052
|
p2p/peer.py
Outdated
@@ -334,6 +348,8 @@ def is_closing(self) -> bool: | |||
# though, otherwise asyncio's event loop can't run and we can't keep up with other peers. | |||
decoded_msg = cast(Dict[str, Any], cmd.decode(msg)) | |||
self.logger.trace("Successfully decoded %s msg: %s", cmd, decoded_msg) | |||
count = self.received_msgs.get(cmd, 0) | |||
self.received_msgs[cmd] = count + 1 |
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.
If you make received_msgs
a collections.defaultdict(int)
then you can make this a one-liner as self.received_msgs[cmd] += 1
p2p/peer.py
Outdated
def uptime(self) -> str: | ||
delta = datetime.now() - self.start_time | ||
hours, remainder = divmod(delta.seconds, 3600) | ||
minutes, seconds = divmod(remainder, 60) |
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.
Strikes me as a good utility function, maybe returning a named tuple of days, hours, minutes, seconds, microseconds
p2p/peer.py
Outdated
@property | ||
def uptime(self) -> str: | ||
delta = datetime.now() - self.start_time | ||
hours, remainder = divmod(delta.seconds, 3600) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
p2p/peer.py
Outdated
@@ -9,6 +9,7 @@ | |||
ABC, | |||
abstractmethod | |||
) | |||
from datetime import datetime |
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.
Can you adjust this to just be import datetime
see https://github.com/pipermerriam/ethereum-dev-tactical-manual/blob/master/style-guide.md#dont-use-from-datetime-import-datetime for the why.
p2p/peer.py
Outdated
delta = datetime.now() - self.start_time | ||
hours, remainder = divmod(delta.seconds, 3600) | ||
minutes, seconds = divmod(remainder, 60) | ||
return '%d:%02d:%02d:%02d' % (delta.days, hours, minutes, seconds) |
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.
@pipermerriam days
was included down here as delta.days
, which is why just delta.seconds
works above (it's the remainder of seconds after dividing out the full days). eg~ https://stackoverflow.com/a/10981895/8412986
No description provided.