Best practice with Ruby on Rails app

Hi, I was wondering what is the best practice for connecting to aerospike? For now I was using in application controller globial variable $client like this

class ApplicationController < ActionController::Base
  include Aerospike
  $client = Client.new('127.0.0.1')
end

and then in all method I would use $client. I am not sure if this is best practice or use something else for Rails app. Thank you

I would recommend setting up the Aerospike client in a Rails initializer file in config/initializers. The client will use the AEROSPIKE_HOSTS environment variable, if you don’t want to hard-code the cluster seed address(es) in the client constructor. The other thing to note is, that if you are using Phusion Passenger or Unicorn and app pre-loading is enabled, it is important to ensure that the client connects to the Aerospike cluster only after a new application process was forked from the pre-loaded image. See the client docs for more details.

Hope this helps!

Thank you, I have implemented like this, but now I got full error log like this:

E, [2019-04-01T07:45:50.745243 #31317] ERROR -- : width too big
I, [2019-04-01T07:45:50.745396 #31473]  INFO -- : Node BB9C5A5F2841EA8 refresh failed: #<Aerospike::Exceptions::Aerospike: Node name is empty>
E, [2019-04-01T07:45:50.745511 #31317] ERROR -- : Exception occured during tend: width too big
D, [2019-04-01T07:45:50.745543 #31473] DEBUG -- : /usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node/verify/name.rb:30:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node/refresh/info.rb:35:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node.rb:198:in `refresh_info'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:266:in `block in refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:232:in `tend'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:220:in `block (2 levels) in launch_tend_thread'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `loop'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `block in launch_tend_thread'
D, [2019-04-01T07:45:50.745648 #31317] DEBUG -- : /usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `%'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `resize'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:82:in `send_command'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:50:in `request'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node/refresh/info.rb:32:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node.rb:198:in `refresh_info'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:266:in `block in refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:232:in `tend'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:220:in `block (2 levels) in launch_tend_thread'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `loop'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `block in launch_tend_thread'
D, [2019-04-01T07:45:50.745836 #31317] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
E, [2019-04-01T07:45:50.861322 #31384] ERROR -- : width too big
E, [2019-04-01T07:45:50.861524 #31384] ERROR -- : Exception occured during tend: width too big
D, [2019-04-01T07:45:50.861623 #31384] DEBUG -- : /usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `%'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `resize'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:82:in `send_command'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:50:in `request'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node/refresh/info.rb:32:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node.rb:198:in `refresh_info'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:266:in `block in refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:232:in `tend'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:220:in `block (2 levels) in launch_tend_thread'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `loop'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `block in launch_tend_thread'
D, [2019-04-01T07:45:50.861741 #31384] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
E, [2019-04-01T07:45:50.929125 #31407] ERROR -- : width too big
E, [2019-04-01T07:45:50.929310 #31407] ERROR -- : Exception occured during tend: width too big
D, [2019-04-01T07:45:50.929453 #31407] DEBUG -- : /usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `%'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `resize'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:82:in `send_command'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:50:in `request'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node/refresh/info.rb:32:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node.rb:198:in `refresh_info'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:266:in `block in refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:232:in `tend'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:220:in `block (2 levels) in launch_tend_thread'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `loop'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `block in launch_tend_thread'
D, [2019-04-01T07:45:50.929595 #31407] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
E, [2019-04-01T07:45:51.673038 #31446] ERROR -- : width too big
E, [2019-04-01T07:45:51.673248 #31446] ERROR -- : Exception occured during tend: width too big
D, [2019-04-01T07:45:51.673343 #31446] DEBUG -- : /usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `%'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/utils/buffer.rb:66:in `resize'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:82:in `send_command'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/info.rb:50:in `request'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node/refresh/info.rb:32:in `call'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/node.rb:198:in `refresh_info'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:266:in `block in refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:265:in `refresh_nodes'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:232:in `tend'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:220:in `block (2 levels) in launch_tend_thread'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `loop'
/usr/local/lib/ruby/gems/2.5.0/gems/aerospike-2.9.0/lib/aerospike/cluster.rb:218:in `block in launch_tend_thread'
D, [2019-04-01T07:45:51.673435 #31446] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
D, [2019-04-01T07:45:51.745966 #31473] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout

Do you have any idea why is this? Thank you

I haven’t encountered this “width too big” error before. Is this still an issue or have you been able to resolve this on your own?

Hi, I though it solved itself, but now after update to 2.9.1 I got error Record too big, and I cannot find where is the problem

I, [2019-04-08T07:51:02.511773 #10349]  INFO -- : Seeding the cluster. Seeds count: 1
D, [2019-04-08T07:51:02.511954 #10349] DEBUG -- : Node Validator found 1 addresses for host 127.0.0.1:3000: [127.0.0.1:3000]
D, [2019-04-08T07:51:02.511992 #10349] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
D, [2019-04-08T07:51:02.512325 #10349] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
I, [2019-04-08T07:51:02.512517 #10349]  INFO -- : Node BB9C5A5F2841EA8 peers generation 1 changed
I, [2019-04-08T07:51:02.512544 #10349]  INFO -- : Node BB9C5A5F2841EA8 partition generation 0 changed
D, [2019-04-08T07:51:02.512569 #10349] DEBUG -- : Update peers for node BB9C5A5F2841EA8
I, [2019-04-08T07:51:02.512746 #10349]  INFO -- : Updating partitions for node BB9C5A5F2841EA8 using new protocol
I, [2019-04-08T07:51:02.514860 #10349]  INFO -- : Partitions for node BB9C5A5F2841EA8 updated
D, [2019-04-08T07:51:02.514900 #10349] DEBUG -- : Cluster config change detected; active nodes: ["BB9C5A5F2841EA8"]
D, [2019-04-08T07:51:02.514936 #10349] DEBUG -- : Cluster features: ["peers", "cdt-list", "cdt-map", "cluster-stable", "pipelining", "geo", "float", "batch-index", "replicas", "replicas-all", "replicas-master", "replicas-prole", "udf"]
I, [2019-04-08T07:51:02.514969 #10349]  INFO -- : Tend finished. 1 node has joined the cluster. Old node count: 0, New node count: 1
I, [2019-04-08T07:51:02.516417 #10349]  INFO -- : New cluster initialized and ready to be used...
D, [2019-04-08T07:51:02.586249 #10349] DEBUG -- :    (0.2ms)  SET NAMES utf8,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
D, [2019-04-08T07:51:02.588274 #10349] DEBUG -- :   Trapair Load (1.7ms)  SELECT `trapairs`.* FROM `trapairs` WHERE (history=1)
D, [2019-04-08T07:51:02.614632 #10349] DEBUG -- : Trying to connect to 127.0.0.1:3000 with 1.0s timeout
E, [2019-04-08T07:51:02.615338 #10349] ERROR -- : Record too big

Also, when second client connect to nginx (I have Rails with passenger and nginx) first client stop receiving all data and halts, this is how my intializer/aerospike.rb looks like:

ENV["AEROSPIKE_HOSTS"] = "127.0.0.1"
connect = true
if defined?(PhusionPassenger)
  connect = false
  PhusionPassenger.on_event(:starting_worker_process) do
    $client.connect
  end
end
$client = Aerospike::Client.new(connect: connect)

The “Record too big” error means that the record you are writing is too big. By default, on a Flash device, the default write-block-size, which limits how big the combined size of the bins of a record can be, is 128 KB. This limit can be increased up to 8 MiB: Known Limitations | Aerospike Documentation.

Ok, thank you, I think I found the problem, it was some external job that aggregated data.