This raises a couple of quick questions: firstly, how big is a
"limited set", in a hand-waving, give or take an order-of-magnitude
sort of estimate?
Lots.
It all depends on how much RAM you have available.
-----
a = 'a'
1.upto(2000000) do
a.to_sym
a.next!
end
puts "#{a} -- sleeping now"
sleep 30
-----
Run that. It creates two million symbols from :a to :ditoc, then sleeps so
that you can go look at memory usage before it exits.
On my box a ps shows something like this:
herbie 22539 74.4 6.3 131944 130320 pts/1 S 06:21 0:07 ruby /tmp/a.rb
It shows no significant variation between Ruby 1.8.0, 1.8.1, 1.8.2, or 1.8.3.
So, if you have the RAM, you can use a considerable number of symbols.
Secondly, I note that the FAQ says that fork "is slow". Am I right
to think that's simply the overhead of starting up the thread, and
then things run smoothly thereafter, or is there some other penalty
of which I'm not aware?
The expense of a fork is in the overhead required to create a new process.
That expense disappears into the background noise if the process that is
being forked persists for more than a short period of time, though.
If you have multiple processes that need to interact, then you have to deal
with interprocess communication. There are many ways to do this, but one
very convenient way with Ruby is to make use of Drb + Rinda + Tuplespace.
They provide a simple to setup and effective way of passing messages around.
Kirk Haines