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 lightweight toUnary client runtime #506

Merged
merged 3 commits into from
Feb 26, 2022

Conversation

naoh87
Copy link
Contributor

@naoh87 naoh87 commented Feb 20, 2022

What this PR do?

This PR eliminate using Dispatcher[F] from toUnary client runtime.

Benchmark

50 pararell request in 30sec with 2core from MBP to other server

IO.defer(client.sayHello(msg, new Metadata()))
  .foreverM
  .parReplicateA(50)
  .timeout(30.seconds)

This PR

count: 885665 in 30sec
rps: 29522
avg: 1692625 nanoseconds
min: 188387 nanoseconds
25%: 945601 nanoseconds
50%: 1128934 nanoseconds
75%: 1474530 nanoseconds
95%: 2677452 nanoseconds
99%: 10760997 nanoseconds
max: 277718411 nanoseconds

main

count: 420181 in 30sec
rps: 14006
avg: 3566715 nanoseconds
min: 413625 nanoseconds
25%: 1161330 nanoseconds
50%: 1448318 nanoseconds
75%: 1968762 nanoseconds
95%: 3918554 nanoseconds
99%: 60713069 nanoseconds
max: 227741517 nanoseconds

@naoh87 naoh87 force-pushed the add_unary_client branch 3 times, most recently from 6002735 to b552e9e Compare February 20, 2022 18:49
object ReceiveState {
def init[F[_]: Sync, R](
callback: Either[Throwable, R] => Unit,
pf: PartialFunction[StatusRuntimeException, Exception]
Copy link
Collaborator

Choose a reason for hiding this comment

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

error adapter is Throwable. I will take a look tomorrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, then we are good. I thought I noticed a Throwable signature somewhere

@naoh87 naoh87 force-pushed the add_unary_client branch 2 times, most recently from 7380a60 to 542ee92 Compare February 21, 2022 22:07
@naoh87 naoh87 force-pushed the add_unary_client branch 2 times, most recently from 19dd92c to 90fe995 Compare February 22, 2022 10:20
import fs2.grpc.client.ClientOptions
import io.grpc._

object Fs2UnaryCallHandler {
Copy link
Collaborator

@ahjohannessen ahjohannessen Feb 25, 2022

Choose a reason for hiding this comment

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

Suggested change
object Fs2UnaryCallHandler {
private[client] object Fs2UnaryCallHandler {

def sendError(error: Throwable): SyncIO[ReceiveState[R]] =
SyncIO(callback(Left(error))).as(new Done[R])

def done(): SyncIO[ReceiveState[R]] = SyncIO(callback(Right(message))).as(new Done[R])
Copy link
Collaborator

@ahjohannessen ahjohannessen Feb 25, 2022

Choose a reason for hiding this comment

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

Suggested change
def done(): SyncIO[ReceiveState[R]] = SyncIO(callback(Right(message))).as(new Done[R])
def done: SyncIO[ReceiveState[R]] = SyncIO(callback(Right(message))).as(new Done[R])

Ref.in(new PendingMessage[R]({
case r: Right[Throwable, R] => callback(r)
case Left(e: StatusRuntimeException) => callback(Left(pf.lift(e).getOrElse(e)))
case l: Left[Throwable, R] => callback(l)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps Left(NonFatal(e)) => callback(e)?

Copy link
Contributor Author

@naoh87 naoh87 Feb 26, 2022

Choose a reason for hiding this comment

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

Never happens fatal error because this callback is called by ClientCall.Listener.

override def onClose(status: Status, trailers: Metadata): Unit = {
if (status.isOk) {
state.get.flatMap {
case expected: PendingHalfClose[Response] => expected.done().flatMap(state.set)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
case expected: PendingHalfClose[Response] => expected.done().flatMap(state.set)
case expected: PendingHalfClose[Response] =>
expected.done().flatMap(state.set)

@ahjohannessen ahjohannessen merged commit 6684a90 into typelevel:main Feb 26, 2022
@naoh87 naoh87 mentioned this pull request Feb 27, 2022
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.

2 participants