druby - How to close connection from client?

M

Martin Boese

I need to disconnect explicitly from a druby client.

My code is like:

DRb.start_service
@drb = DRbObject.new(nil, 'druby://localhost:7777')
@drb.dosomething(param1, param2, param3)
...(here I'd like to disconnect!!)...


Background:
I am using druby to communicate between a Rails application running on
lighttpd/FreeBSD6 and a server-script running on the same box with different
user rights.

I noticed that the longer I run the webserver the more sockets stay open,
"sockstat | grep ruby" gives me hundreds of:
www ruby18 26179 10 tcp4 *:51359 *:*
www ruby18 26179 11 tcp4 *:57690 *:*
www ruby18 26179 12 tcp4 *:53473 *:*

I assume that every time I run the druby client on the website a connection
remains open. They get all cleared if I restart lighttpd.

Thanks.
martin
 
T

Tim Pease

I need to disconnect explicitly from a druby client.

My code is like:

DRb.start_service
@drb = DRbObject.new(nil, 'druby://localhost:7777')
@drb.dosomething(param1, param2, param3)
...(here I'd like to disconnect!!)...


DRb.stop_service


You can make another call to DRb.start_service if you want to restart
your DRb connection. You'll have to create another DRbObject, though,
since stop_service terminates all connections.

Blessings,
TwP
 
M

michael.moen

Martin said:
I need to disconnect explicitly from a druby client.

My code is like:

DRb.start_service
@drb = DRbObject.new(nil, 'druby://localhost:7777')
@drb.dosomething(param1, param2, param3)
..(here I'd like to disconnect!!)...


Background:
I am using druby to communicate between a Rails application running on
lighttpd/FreeBSD6 and a server-script running on the same box with different
user rights.

Martin- I'm doing something similar but using Rinda as a middle man.
What I did was create a singleton class to handle the conenction, one
connection stays open and gets reused.

Here's what the client looks like.

#!/usr/bin/env ruby -w

require 'rinda/ring'
require 'uuidtools'
require 'rinda'
require 'search_result'

class SearchClient
private_class_method :new
@@tuple_space = nil

def self.create
if @@tuple_space.nil?
DRb.start_service
@@tuple_space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil,
RINDA_MASTER))
end
@@tuple_space
end

def self.user_search(opts)
retries = 0
begin
opts[:uuid] = UUID.random_create.to_s
puts "outgoing => uuid: #{opts[:uuid]}\nopts: #{opts}"
SearchClient.create.write([:UserSearch, DRb.uri, opts],
RINDA_TIMEOUT)
tuple = SearchClient.create.take([:UserSearchResults,
opts[:uuid], nil], RINDA_TIMEOUT)
SearchResult.new tuple[2]
rescue DRb::DRbConnError
# handle connection closed
rescue
@@tuple_space = nil
raise 'Connection Error'
end
end
end
 
E

Ezra Zygmuntowicz

I need to disconnect explicitly from a druby client.

My code is like:

DRb.start_service
@drb = DRbObject.new(nil, 'druby://localhost:7777')
@drb.dosomething(param1, param2, param3)
...(here I'd like to disconnect!!)...


Background:
I am using druby to communicate between a Rails application running on
lighttpd/FreeBSD6 and a server-script running on the same box with
different
user rights.

I noticed that the longer I run the webserver the more sockets stay
open,
"sockstat | grep ruby" gives me hundreds of:


I assume that every time I run the druby client on the website a
connection
remains open. They get all cleared if I restart lighttpd.

Thanks.
martin

He Martin-

You may want to have a look at a rails plugin I wrote called
BackgrounDRb [1]. Its built for this exact purpose. You can have
worker classes that run in the drb server that you can start and stop
from rails. It also has hooks and examples of how to create ajax
progress bars while your workers do their task.

Cheers-
-Ezra

[1] http://backgroundrb.rubyforge.org/
 
M

Martin Boese

That's great! I will for sure look into this plugin..=20

=46or now I just do DRb.stop_service as suggested by Tim and it seems to wo=
rk=20
fine.

Thanks everybody for the nice help.

Martin
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top