This will work well if you can load all the database drivers on the client
end (once per client), and will perform the best because DRb is only
dispatching database connections.
well, the client and server will be the same in my case - i plan to use this
object from cgi programs.
Here I meant client and server processes.
This will result in the least memory overhead, but DRb may become a
bottleneck if you have to do alot of database activity. Remember DRb spawns
a thread per request.
yes, this does seem like a bottle neck. in general, what types of data needs
thread protection when programming drb?
Anything you write to should have a mutex around it, unless you don’t
care about lost updates.
For a DB driver, that would probably be the open DB socket count.
Well, if you have only a few database requests, or have low memory, go
with option b. If you have a ton of memory, or are doing many database
queries, go with option a.
2GB or 512GB of RAM - primary/secondar ha-linux machines.
If you’re going to be using this with Apache, you’ll be a tough call. Is
the overhead of having the PG drivers in each Apache process worth it?
Probably yes if you have a ton of memory or don’t have many Apache processes
hanging around. If you are low on memory, or only do a few DB queries/page,
then you may be better off having DRb handle everything.
you lost me.
why would the pg drivers be loaded into apache in either case? i’m
envisioning a pool which fires up idependently from cgi programs or apache,
cgi programs will either get a proxy object delegating calls to the drb object
which does have the drivers loaded, or a handle (guess this is a proxy too
;0) to the actuall connection object. in either case it seems like only the
server(s) would have the postgresql.so in memory? i’m not using mod_ANYTHING.
Let me clear this up with a little code:
When you use Undumped, DRb passes a proxy of the object across to
the client, so everything done through the object takes place on
the server side, not the client side. The client only needs to load
DRb.
If you don’t use Undumped, you need to load all the libraries used by
the class on the client side. For a DB driver, this would be the
postgres drives, and you’d get the whole driver on each Apache process.
The more Apache processes you have, the more overhead this takes up.
Here is an example:
···
ahoward (ahoward@fsl.noaa.gov) wrote:
server.rb:
require ‘drb’
class Server
def custom_obj
return CustomObj.new
end
def custom_undumped_obj
return CustomUnDumpedObj.new
end
end
class CustomObj
def do_stuff
puts “I’m doing stuff!”
end
end
class CustomUnDumpedObj
include DRbUndumped
def do_stuff
puts “I’m doing stuff, and I’m not dumped!”
end
end
DRb.start_service(‘druby://localhost:5000’, Server.new)
DRb.thread.join
client.rb:
require ‘drb’
class CustomObj
def do_stuff
puts “I’m doing stuff!”
end
end
DRb.start_service
obj = DRbObject.new(nil, ‘druby://localhost:5000’)
co = obj.custom_obj
udo = obj.custom_undumped_obj
p co
p udo
co.do_stuff
udo.do_stuff
If you start up the server, then run the client you will see:
** client side:
$ ruby client.rb
#CustomObj:0x8056f28
#<DRb::DRbObject:0x8056b18 @ref=67286072, @uri=“druby://localhost:5000”>
I’m doing stuff!
** server side:
$ ruby server.rb
I’m doing stuff, and I’m not dumped!
^C
$
If you remove the class CustomObj from the client.rb you get this:
** client side:
$ ruby client.rb
/usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:123:in load': undefined class/module CustomObj (ArgumentError) from /usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:123:in
load’
from /usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:166:in recv_reply' from /usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:300:in
send_message’
from /usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:227:in method_missing' from /usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:226:in
open’
from /usr/local/lib/ruby/site_ruby/1.6/drb/drb.rb:226:in `method_missing’
from client.rb:15
So the advantage of using include UnDumped is that everything gets
proxied, there’s less per-process overhead because you don’t have a
driver sitting in each process, and you have perfect control over the
number of DB sockets you have open.
The disadantage is that you’re shoving everything into a bitty socket
before sending it out to the DB.
–
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04