Skip to content
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

Add latency to RelayConnectionStats #117

Merged
merged 1 commit into from
Aug 25, 2023
Merged

Add latency to RelayConnectionStats #117

merged 1 commit into from
Aug 25, 2023

Conversation

yukibtc
Copy link
Member

@yukibtc yukibtc commented Jun 23, 2023

No description provided.

@yukibtc yukibtc linked an issue Jun 23, 2023 that may be closed by this pull request
@yukibtc yukibtc added this to the Release 0.23 milestone Jun 23, 2023
@ok300
Copy link
Contributor

ok300 commented Jun 23, 2023

LGTM, I can now sort by latency:

latency

@ok300
Copy link
Contributor

ok300 commented Jun 24, 2023

Instead of one thread per relay, maybe it would be better to have one global thread (of the pool?) that checks the latency on all active relays at that moment?

User could add / remove relays, some could go offline or become unresponsive, yet the thread could still query and measure every minute.

@yukibtc
Copy link
Member Author

yukibtc commented Jun 25, 2023

Instead of one thread per relay, maybe it would be better to have one global thread (of the pool?) that checks the latency on all active relays at that moment?

User could add / remove relays, some could go offline or become unresponsive, yet the thread could still query and measure every minute.

The problem is that if there is a connected relay that is unresponsive, that will block the loop. I can set a timeout for get_events_of but this will increase the time needed to calculate the latency.

I don't think there are problems if we use another thread per relay.
Have you noticed about an increment of RAM or CPU utilization?
I just tested the resources utilization with 16 connected relays and the results are: 0% CPU and 8.3 MB RAM

The RAM will increase if some relays are disconnected since the messages/events will be stored in a channel (max 1024), but in general should be very low.

A problem with this implementation could be that the dev will receive events that not requested in client.notifications()/client.handle_notifications(...).

@ok300
Copy link
Contributor

ok300 commented Jun 25, 2023

No, I didn't see any performance impact of 1 extra thread per relay. I was only wondering if it can be further optimized, but as you said, an unresponsive relay could complicate things if one thread is checking all relays. So then I agree, 1 thread per relay is probably the best approach.

A problem with this implementation could be that the dev will receive events that not requested in client.notifications()/client.handle_notifications(...).

Very good point. Then I suppose the NIP-11 Relay Info Document is the least intrusive, since the reply doesn't come as an event? In that case, the latency check would belong behind the nip-11 feature flag.

@yukibtc yukibtc merged commit bfecac7 into master Aug 25, 2023
27 checks passed
@yukibtc yukibtc deleted the latency branch August 25, 2023 15:37
@ok300
Copy link
Contributor

ok300 commented Aug 25, 2023

Thanks!

@yukibtc
Copy link
Member Author

yukibtc commented Aug 25, 2023

I found an alternative way to ping relays, but unfortunately is not supported on WASM (so no latency stat for WASM).
I'll try to search a solution for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible to track relay latency?
2 participants