Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in protobuf-nats.gemspec
gemspec


platforms :jruby do
# gem "jruby-profiler-flame_graph_profile_printer", path: "/users/john.bolliger/github/jruby-profiler-flame_graph_profile_printer"
end
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ used to allow JVM based servers to warm-up slowly to prevent jolts in runtime pe

`PB_NATS_CLIENT_SUBSCRIPTION_POOL_SIZE` - If subscription pooling is desired for the request/response cycle then the pool size maximum should be set; the pool is lazy and therefore will only start new subscriptions as necessary (default: 0)

`PB_NATS_DISABLE_JNATS` - Disable the default jruby jnats client on the jruby platform, use the nats-pure.rb client instead (default: false).

`PROTOBUF_NATS_CONFIG_PATH` - Custom path to the config yaml (default: "config/protobuf_nats.yml").

### YAML Config
Expand Down
14 changes: 12 additions & 2 deletions bench/real_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
require "benchmark/ips"
require "./examples/warehouse/app"

# require "jruby/profiler/flame_graph_profile_printer"

Protobuf::Logging.logger = ::Logger.new(nil)

# should_profile = ENV["profile"]

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)
Warehouse::ShipmentService.client.create(req)
end
end


# export JRUBY_OPTS="--disable:did_you_mean -J-Djava.security.egd=file:/dev/./urandom -J-Xmx2g -J-Xms1024m -J-Xmn512m --dev --debug --profile"
#
# export JRUBY_OPTS="--disable:did_you_mean -J-Djava.security.egd=file:/dev/./urandom -J-Xmx2g -J-Xms1024m -J-Xmn512m"
#
21 changes: 21 additions & 0 deletions bench/real_client_profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ENV["PB_CLIENT_TYPE"] = "protobuf/nats/client"
# ENV["PB_SERVER_TYPE"] = "protobuf/nats/runner"

# require "benchmark/ips"
# require "./examples/warehouse/app"

# # require "jruby/profiler/flame_graph_profile_printer"

# Protobuf::Logging.logger = ::Logger.new(nil)

# result = JRuby::Profiler.profile do
# 20_000.times do
# req = Warehouse::Shipment.new(:guid => SecureRandom.uuid)
# Warehouse::ShipmentService.client.create(req)
# end
# end

# printer = JRuby::Profiler::FlameGraphProfilePrinter.new(result)
# stdout = File.open('real_client.out', 'w')
# printer.printProfile(stdout)
# stdout.close
14 changes: 8 additions & 6 deletions lib/protobuf/nats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

require "nats/io/client"

require "protobuf/nats/platform"
require "protobuf/nats/errors"
require "protobuf/nats/client"
require "protobuf/nats/server"
Expand All @@ -23,12 +24,13 @@ module Messages
NACK = "\2".freeze
end

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

GET_CONNECTED_MUTEX = ::Mutex.new

Expand Down
Loading