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

Added ping #38

Merged
merged 4 commits into from
Feb 26, 2024
Merged

Added ping #38

merged 4 commits into from
Feb 26, 2024

Conversation

mtmk
Copy link
Contributor

@mtmk mtmk commented Feb 22, 2024

Added ping command. Should help with #1.

@mtmk mtmk requested review from Jarema and piotrpio February 22, 2024 07:55
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

Few comments and questions.

Sources/Benchmark/main.swift Outdated Show resolved Hide resolved
for _ in 0..<numMsgs {
try! nats.publish(data, subject: "foo")
}
try! await nats.flush()
_ = try! await nats.ping()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in client benchmarks we do not care for actual performance and when messages arrives to the server, but the client capacity to send them out. Ping is useful if you want to test the system End to End.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the benefit if not measured end to end. maybe I'm missing the point and maybe they are two different benchmarks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

@@ -0,0 +1,19 @@
import NIOConcurrencyHelpers

internal class ConcurrentQueue<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if DispatchQueue is not more straighforward solution here.

@piotrpio WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid GCD unless we have a significant and measurable performance benefit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here. Just prefer using already build concurrent-safe queues instead of making non-concurrent safe, safe by locking.

Especially that most implementations are faster, relying on atomics instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's locking for memory it should be fine here. other option is to use an actor. I don't know how atomics maybe used here. I don't mind. this won't be on a hot path

@@ -103,4 +103,13 @@ extension Client {
return try await connectionHandler.subscribe(subject)

}

public func ping() async throws -> Duration {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this rtt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought other clients called it ping as well. is it called rtt in rust client?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in Go it's called Flush with this description:

// Flush will perform a round trip to the server and return when it
// receives the internal reply.
func (nc *Conn) Flush() error {
	return nc.FlushTimeout(10 * time.Second)
}

Which I think is confusing for anyone used to what flushing usually does.

@@ -127,7 +129,6 @@ class ConnectionHandler: ChannelInboundHandler {
default:
continuation.resume()
}
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing continue here?

Copy link
Contributor Author

@mtmk mtmk Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise it's ignoring the incoming pong

edit: reverted. now ping queue is ignoring first ping-pong

@@ -0,0 +1,24 @@
import NIOCore

internal class PingCommand {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming - RttCommand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Jarema Jarema merged commit eaef1db into main Feb 26, 2024
1 check passed
@Jarema Jarema deleted the add-ping branch February 26, 2024 10:40
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.

None yet

2 participants