Skip to content

Add request muxer remove jnats#10

Open
skunkworker wants to merge 70 commits into
mxenabled:masterfrom
skunkworker:jb/add_request_muxer_remove_jnats
Open

Add request muxer remove jnats#10
skunkworker wants to merge 70 commits into
mxenabled:masterfrom
skunkworker:jb/add_request_muxer_remove_jnats

Conversation

@skunkworker

@skunkworker skunkworker commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Add request muxer similar to Golang's pattern.
Removed JNats. nats-pure gem is fast enough and similar for CRuby and JRuby.
Thread count does not seem to increase with the increased subscriptions.

EDIT:
June 7th

  • Protobuf::Nats.client_nats_connection.new_inbox is not thread safe, wrapped this in a mutex.sychronize block.
  • Changed break to be next when encountering unexpected messages on the client. This allows for unexpected messages to be quickly moved-on from, rather than breaking out of the outer loop do loop.
  • Added logger instance variable for a few classes for better logging.
  • Added third arity to SuperSubscriptionMananger block, this passes in the subject now, so when the thread is full we can now report the subject of the message that pushed it over the edge. (For the future, we could allow for per-subject different thread_pools)

@skunkworker skunkworker changed the title Jb/add request muxer remove jnats Add request muxer remove jnats Jun 2, 2026
Comment thread lib/protobuf/nats/server.rb Outdated
Comment thread lib/protobuf/nats/server.rb Outdated
Comment thread lib/protobuf/nats/client.rb Outdated

# If time has run out, we must raise a timeout error. This is the
# definitive exit condition for the loop.
raise ::NATS::Timeout if timeout && remaining <= 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We might want to do something like this in the server loop too, for similar reasons

Comment thread lib/protobuf/nats/server.rb Outdated
@pending_queue << existing_pending_queue.pop
end

# how to close this older queue without it blocking!?

@elbowdonkey elbowdonkey Jun 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

probably don't need this, and the following commented line, anymore

Comment thread lib/protobuf/nats/client.rb Outdated
def new_request
token = ::SecureRandom.uuid # nats.new_inbox with nuid is not threadsafe.

@resp_sub.synchronize do

@elbowdonkey elbowdonkey Jun 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If start returns nil (because it can return early with nil in at least two places), @resp_sub could be nil. And if @resp_sub is nil, we'll throw a NoMethodError here. We probably don't want 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.

3 participants