Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
81439c6
Sketch out a client side muxer with a wildcard subscription
film42 Jan 5, 2023
ee14969
Fix up a few things with the new ruby pure client
film42 Jan 5, 2023
f85d4dc
Fix up tests.. mocks are not great
film42 Jan 5, 2023
bec0a79
Add a working global response muxer
film42 Jan 5, 2023
73f0fa0
Reset the muxer between each test (as the client changes)
film42 Jan 5, 2023
fbec836
Add error handler when client response muxer handler fails
film42 Jan 5, 2023
010028d
Fork jruby/mri code as needed and remove old mri client impl
film42 Jan 5, 2023
349744b
Fix bugs + move platform to specific file
film42 Jan 5, 2023
3e7ced5
Add new flag to readme
film42 Jan 5, 2023
4684de8
Remove dead code
film42 Jan 5, 2023
dafddfc
Add a pre-release to the branch
film42 Jan 6, 2023
1f2e9a0
Bump to an unused pre-release version
film42 Jan 6, 2023
a976595
muxer, and ruby version upgrade, also added circleci
skunkworker Jun 1, 2026
91d7ab4
merge master
skunkworker Jun 1, 2026
3eb9af4
ripped out jnats
skunkworker Jun 1, 2026
001bac9
Added better tuned jruby_opts for testing.
skunkworker Jun 1, 2026
2515c76
more work
skunkworker Jun 2, 2026
05768be
added notes
skunkworker Jun 2, 2026
5f3b97d
Cleaning up more
skunkworker Jun 2, 2026
ff9f6fc
more cleanup work
skunkworker Jun 2, 2026
d57aa97
comment out code
skunkworker Jun 2, 2026
1405ecc
fix specs
skunkworker Jun 2, 2026
b65544d
more
skunkworker Jun 2, 2026
a40cc13
more
skunkworker Jun 2, 2026
3970af6
more
skunkworker Jun 2, 2026
02c8464
more
skunkworker Jun 2, 2026
cb8973c
added changelog.md
skunkworker Jun 2, 2026
cb9a55e
more
skunkworker Jun 5, 2026
a9a22b4
add logging when we see an unexpected message
skunkworker Jun 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ jobs:
environment:
JRUBY_OPTS: "-J-Xmx1024m"
RAILS_ENV: test
NATS_URL: "changeme"

# 2. The Service Container (runs in the background)
- image: nats:2.14.1-linux
- image: nats:2.14-linux

working_directory: ~/project

Expand Down Expand Up @@ -82,4 +81,4 @@ workflows:
- "cimg/ruby:3.1"
- "cimg/ruby:3.4"
- "jruby:9.4"
- "jruby:10.0"
- "jruby:10.0"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Changelog

### 0.12.0.pre0 - WIP
- Removed JNats (`nats-pure` is fast enough for JRuby and CRuby parallel work)
- Added ResponseMuxer (similar to Golang)
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

The java-nats client is temporarily forked to support jruby > 9.2.10.0. The living branch for that is here: https://github.com/film42/java-nats/tree/jruby-compat. This will be removed when we upgrade to the new nats.java client.

## Contributing

Expand Down
17 changes: 17 additions & 0 deletions bench/console.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "protobuf/nats"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

# ENV["PB_CLIENT_TYPE"] = "protobuf/nats/client"
# ENV["PB_SERVER_TYPE"] = "protobuf/nats/runner"

require "irb"
IRB.start(__FILE__)
4 changes: 2 additions & 2 deletions bench/real_client.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Protobuf::Logging.logger = ::Logger.new(nil)

Benchmark.ips do |config|
config.warmup = 10
config.time = 10
config.warmup = 15
config.time = 30

config.report("single threaded performance") do
req = Warehouse::Shipment.new(:guid => SecureRandom.uuid)
Expand Down
10 changes: 10 additions & 0 deletions bench/real_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

export JRUBY_OPTS="--disable:did_you_mean -J-Djava.security.egd=file:/dev/./urandom -J-Xmx2g -J-Xms1024m -J-Xmn512m -Xjit.threshold=10 -J-XX:CompileThreshold=10"

export PB_SERVER_TYPE="protobuf/nats/runner"
export PB_CLIENT_TYPE="protobuf/nats/client"

echo "$PWD"

bundle exec ruby -I lib bench/real_client.rb
9 changes: 8 additions & 1 deletion bench/real_server.sh
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
PB_SERVER_TYPE="protobuf/nats/runner" PB_CLIENT_TYPE="protobuf/nats/client" bundle exec rpc_server start --threads=20 ./examples/warehouse/app.rb > /dev/null
export JRUBY_OPTS="--disable:did_you_mean -J-Djava.security.egd=file:/dev/./urandom -J-Xmx2g -J-Xms1024m -J-Xmn512m -Xjit.threshold=10 -J-XX:CompileThreshold=10"

export PB_SERVER_TYPE="protobuf/nats/runner"
export PB_CLIENT_TYPE="protobuf/nats/client"

export PB_NATS_SERVER_SLOW_START_DELAY=1

bundle exec rpc_server start --threads=20 ./examples/warehouse/app.rb
62 changes: 62 additions & 0 deletions bench/results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

Ran on Monday, June 1. MBP 14 M1 Pro.

Notes:
`-Xjit.threshold=0` - Setting the threshold to 0 forces JRuby to compile every method into Java bytecode immediately before its very first execution. This is particularly useful for debugging or bypassing warm-up times during profiling


`-Xjit.threshold=10 -J-XX:CompileThreshold=10` - If you are running benchmarks and want both JRuby and the JVM to aggressively optimize early, you can lower both thresholds simultaneously

`bundle; bx ruby -I lib bench/real_client.rb`

Start local nats server so details can be monitored.
`/opt/homebrew/opt/nats-server/bin/nats-server -m 8222`


```
export JRUBY_OPTS="--disable:did_you_mean -J-Djava.security.egd=file:/dev/./urandom -J-Xmx2g -J-Xms1024m -J-Xmn512m -Xjit.threshold=10 -J-XX:CompileThreshold=10"
```


## `jruby-10.0.5.0`

```
I, [2026-06-01T14:37:25.025154 #60447] INFO -- : Using NATS::Client to connect
jruby 10.0.5.0 (3.4.5) 2026-04-06 5db1ba72f3 OpenJDK 64-Bit Server VM 21.0.11 on 21.0.11 +indy +jit [arm64-darwin]
Warming up --------------------------------------
single threaded performance 16.000 i/100ms
Calculating -------------------------------------
single threaded performance 907.463 (±22.7%) i/s (1.10 ms/i) - 27.200k in 29.973673s
```

## `jruby-9.4.14.0`

```
I, [2026-06-01T14:35:40.758758 #59092] INFO -- : Using NATS::Client to connect
jruby 9.4.14.0 (3.1.7) 2025-08-28 ddda6d5992 OpenJDK 64-Bit Server VM 21.0.11 on 21.0.11 +jit [arm64-darwin]
Warming up --------------------------------------
single threaded performance 22.000 i/100ms
Calculating -------------------------------------
single threaded performance 1.014k (±11.2%) i/s (986.40 μs/i) - 30.404k in 29.990625s
```

## `ruby-3.1.7`

```
I, [2026-06-01T14:38:46.998079 #61611] INFO -- : Using NATS::Client to connect
ruby 3.1.7p261 (2025-03-26 revision 0a3704f218) [arm64-darwin25]
Warming up --------------------------------------
single threaded performance 111.000 i/100ms
Calculating -------------------------------------
single threaded performance 1.120k (± 6.6%) i/s (893.04 μs/i) - 33.633k in 30.035636s
```

## `ruby-3.4.9`
```
ruby 3.4.9 (2026-03-11 revision 76cca827ab) +PRISM [arm64-darwin25]
Warming up --------------------------------------
single threaded performance 108.000 i/100ms
Calculating -------------------------------------
single threaded performance 1.107k (± 8.5%) i/s (903.53 μs/i) - 33.264k in 30.054932s
```

43 changes: 41 additions & 2 deletions examples/warehouse/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Shipment < ::Protobuf::Message; end
class ShipmentRequest < ::Protobuf::Message; end
class Shipments < ::Protobuf::Message; end


##
# Message Fields
#
Expand All @@ -33,7 +32,6 @@ class Shipments
repeated ::Warehouse::Shipment, :records, 1
end


##
# Service Classes
#
Expand All @@ -52,4 +50,45 @@ def search
end
end


# ##
# # Message Classes
# #
# class CargoShip < ::Protobuf::Message; end
# class CargoShipRequest < ::Protobuf::Message; end
# class CargoShips < ::Protobuf::Message; end

# ##
# # Message Fields
# #
# class CargoShip
# optional :string, :name, 1
# optional :string, :guid, 2
# optional :string, :status, 3
# end

# class CargoShips
# repeated ::Warehouse::CargoShip, :records, 1
# end

# class CargoShipRequest
# repeated :string, :name, 1
# repeated :string, :guid, 2
# repeated :string, :status, 3
# end

# class ShipService < ::Protobuf::Rpc::Service
# rpc :create, ::Warehouse::CargoShip, ::Warehouse::CargoShip
# rpc :search, ::Warehouse::CargoShipRequest, ::Warehouse::CargoShip

# def create
# respond_with request
# end

# def search
# ship = ::Warehouse::CargoShip.new(:guid => SecureRandom.uuid, :name => SecureRandom.uuid, :status => SecureRandom.uuid)
# respond_with ::Warehouse::CargoShip.new(:records => [ship])
# end
# end

end
8 changes: 1 addition & 7 deletions lib/protobuf/nats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ module Messages
NACK = "\2".freeze
end

NatsClient = if defined? JRUBY_VERSION
require "protobuf/nats/jnats"
::Protobuf::Nats::JNats
else
::NATS::IO::Client
end
NatsClient = ::NATS::IO::Client

GET_CONNECTED_MUTEX = ::Mutex.new

Expand Down Expand Up @@ -114,7 +109,6 @@ def self.start_client_nats_connection
end
end

# This will work with both ruby and java errors
def self.log_error(error)
logger.error error.to_s
logger.error error.class.to_s
Expand Down
Loading