Correct way to use DRb within a Rails Controller?

X

x1

[not really rails specific]
I'm unsure about what should be placed where or if it even matters.
Here's the basic rails controller:

-------please_work_controller.rb----------
class PleaseWork < ApplicationController
def get_name
@name =3D retrieve.name
end
def get_age
@age =3D retrieve.age
end
end
-------/please_work_controller.rb--------
To create your typical client DRb connection, you'll need the following:

require 'drb'
DRb.start_service
retrieve =3D DRbObject.new(nil,"druby://#{hostname}:#{port}")

Where should these definitions be placed? They seem to work just about
anywhere but whats the optimal placement? Also, I realize retrieve
does not *need* to be defined but since it is used throughout the
class in other methods as such..

Thanks as usual!
 
E

Eric Hodel

[not really rails specific]
I'm unsure about what should be placed where or if it even matters.
Here's the basic rails controller:

-------please_work_controller.rb----------
class PleaseWork < ApplicationController
def get_name
@name = retrieve.name
end
def get_age
@age = retrieve.age
end
end
-------/please_work_controller.rb--------
To create your typical client DRb connection, you'll need the
following:

require 'drb'
DRb.start_service
retrieve = DRbObject.new(nil,"druby://#{hostname}:#{port}")

Depending upon how long your DRb server lives you can probably make
retrieve a global and put it in environment.rb. Score bonus points
for using NamedIdConv.
 
X

x1

The reason I asked this originally, was because webrick would just
come to a halt after about 10-15 http requests..

After eliminating ram/cpu/gc as the culprit, I did a netstat -a and
found loads of open sessions....

Removing DRb.start_server from the controller all together -fixed it.


[not really rails specific]
I'm unsure about what should be placed where or if it even matters.
Here's the basic rails controller:

-------please_work_controller.rb----------
class PleaseWork < ApplicationController
def get_name
@name =3D retrieve.name
end
def get_age
@age =3D retrieve.age
end
end
-------/please_work_controller.rb--------
To create your typical client DRb connection, you'll need the
following:

require 'drb'
DRb.start_service
retrieve =3D DRbObject.new(nil,"druby://#{hostname}:#{port}")

Depending upon how long your DRb server lives you can probably make
retrieve a global and put it in environment.rb. Score bonus points
for using NamedIdConv.
Where should these definitions be placed? They seem to work just about
anywhere but whats the optimal placement? Also, I realize retrieve
does not *need* to be defined but since it is used throughout the
class in other methods as such..

Thanks as usual!

--
Eric Hodel - (e-mail address removed) - http://segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top