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

Client response muxer #2

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Client response muxer #2

wants to merge 12 commits into from

Conversation

film42
Copy link
Contributor

@film42 film42 commented Jan 5, 2023

This adds a single subscription response router. This means all client RPC requests will share one single subscription. This works by subscribing to <base-uuid>.*. Every time we send an RPC request, we store a new random <request-uuid> in a map, and set the reply inbox as <base-uuid>.<request-uuid>. Now, a single thread can pull messages from the wildcard subscription and signal to other waiting threads that their message is ready to be consumed.

There is a bit more plumbing required to make this work, but if this work successfully and fast on both jruby and MRI, we can remove our jruby specific jnats client and the custom subscription pool stuff that we added a few years back. That would be a huge win.

Old jruby client single threaded test:

$ PB_NATS_CLIENT_SUBSCRIPTION_POOL_SIZE=512 bx ruby -I lib bench/real_client.rb           
I, [2023-01-05T07:50:13.022476 #57405]  INFO -- : Using Protobuf::Nats::JNats to connect
Warming up --------------------------------------
single threaded performance
                         5.000  i/100ms
Calculating -------------------------------------
single threaded performance
                         26.230  (±118.2%) i/s -    110.000  in  10.732526s

New muxed client on jruby (not using jnats):

$ PB_NATS_DISABLE_JNATS=1 bx ruby -I lib bench/real_client.rb
I, [2023-01-05T07:49:17.535747 #57225]  INFO -- : Using NATS::Client to connect
Warming up --------------------------------------
single threaded performance
                        66.000  i/100ms
Calculating -------------------------------------
single threaded performance
                          3.101k (±13.4%) i/s -     30.294k in  10.007279s

I'm not entirely sure where the magical speedup is coming from at this point. I guess it's good to know that things appear to be working well on jruby without jnats.

MRI:

Old version:

$ bx ruby -I lib bench/real_client.rb             
I, [2023-01-05T07:54:14.300803 #57856]  INFO -- : Using NATS::IO::Client to connect
Warming up --------------------------------------
single threaded performance
                       304.000  i/100ms
Calculating -------------------------------------
single threaded performance
                          3.232k (± 7.8%) i/s -     32.224k in  10.074739s

New version:

$ bx ruby -I lib bench/real_client.rb
I, [2023-01-05T07:54:46.990533 #57930]  INFO -- : Using NATS::Client to connect
Warming up --------------------------------------
single threaded performance
                       294.000  i/100ms
Calculating -------------------------------------
single threaded performance
                          3.128k (±10.0%) i/s -     30.870k in  10.037075s

New version is reporting a little slower, but I don't think it's a substantial impact. I guess I'm more confused by the bench results than anything.

Few other things:

  1. The test suite is mocked out (my fault), so there are some changes to make it work for MRI and jruby.
  2. Added a new platform.rb file to make it easier to detect jruby in a single place (DRY) but also to disable the jnats loader (using the upgraded pure ruby client instead). By default there are no breaking changes.

@film42
Copy link
Contributor Author

film42 commented Jan 6, 2023

Released as v0.12.0.pre0 for beta testing.

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