Skip to content

Add request muxer remove jnats#10

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

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

Conversation

@skunkworker
Copy link
Copy Markdown
Collaborator

@skunkworker skunkworker commented Jun 2, 2026

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.

@skunkworker skunkworker changed the title Jb/add request muxer remove jnats Add request muxer remove jnats Jun 2, 2026
# existing queue before this queue swap happens seems extremely low, but possible.
while !existing_pending_queue.empty?
puts "found messages when trying to queue_subscribe, shoveling them onto the main @pending_queue"
@pending_queue << existing_pending_queue.pop
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NOTES: from #7

I still don't love this, but I think it's probably fine. We could drop msgs here if ruby performs a long and unhealthy GC between these lines. While not probable, it's possible this happens coming out of a maintenance mode when you're not warm (jruby JITs) and requests are thrashing. But, I don't think there's a clean way to plumb, and it's not worth a thread local context hack...

# Example:

def with_pending_queue(pending_queue:)
  Thread.current[:pending_queue] = @pending_queue 

  yield
ensure
  Thread.current[:pending_queue] = nil
end

module SomethingHorrible
  def initialize
    super 

    @pending_queue = Thread.current[:pending_queue] if Thread.current[:pending_queue].present?
  end
end

class NATS::IO::Subscription
  prepend SomethingHorrible
end

...

with_pending_queue(pending_queue: @pending_queue)
  sub = @nats.subscribe(name, queue: name)

  assert sub.pending_queue == @pending_queue 
end

But... that's pretty nasty 😬


But to be honest I think what you're doing is fine because nats is doing a flush on the sub operation so this will probably get hit often.

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