On Sat, Feb 10, 2007 at 09:04:51AM +0900, ara.t.howard / noaa.gov wrote:
> On Thu, 8 Feb 2007, Eric Hodel wrote:
> >
> >I've heard a few people talk of it (mainly, TupleSpace with a persistence
> >(database)), but to my knowledge nobody's done it.
> >
> i have.  if people like it, i'll release next week.
> 
> 1) it's a hack
> 2) it's persistent
[...]
> 3) it's pretty fast (and uses little cpu)
> 
>   jib:~ > cat b.rb
>   require 'sqlitespace'
> 
>   rss = Rinda::SQLiteSpace.new
> 
>   rss.transaction{ 42424.times{ write [Time.now, rand] } }
> 
> 
>   jib:~ > time ruby b.rb
> 
>   real    0m19.063s
>   user    0m18.110s
>   sys     0m0.560s

It's pretty fast considering it's persistent, but it is of course slower than
the std. TupleSpace...

$ cat tuplespace.rb 
#!/usr/bin/env ruby

require 'rinda/tuplespace'

ts = Rinda::TupleSpace.new

require 'benchmark'
p Benchmark.measure {
  42424.times{ ts.write [Time.now, rand] }
}


#require 'rubygems'
#gem "sqlite-ruby"
require 'sqlitespace'
$VERBOSE = false
puts "Using SQLite #{SQLite::Version::STRING}"
ts2 = Rinda::SQLiteSpace.new

p Benchmark.measure {
  ts2.transaction{ 42424.times{ write [Time.now, rand] } }
}


$ time ruby tuplespace.rb 
#<Benchmark::Tms:0xa795b878 @total=4.62, @cutime=0.0, @label="", @stime=0.24, @real=4.64543700218201, @utime=4.38, @cstime=0.0>
/home/batsman/usr//lib/ruby/site_ruby/1.8/sqlite/database.rb:243: warning: `*' interpreted as argument prefix
/home/batsman/usr//lib/ruby/site_ruby/1.8/sqlite/statement.rb:103: warning: `*' interpreted as argument prefix
(eval):2: warning: `*' interpreted as argument prefix
(eval):2: warning: `*' interpreted as argument prefix
(eval):2: warning: `*' interpreted as argument prefix
(eval):2: warning: `*' interpreted as argument prefix
(eval):2: warning: `*' interpreted as argument prefix
(eval):2: warning: `*' interpreted as argument prefix
(eval):1: warning: method redefined; discarding old delete
Using SQLite 2.2.2
#<Benchmark::Tms:0xa7717d8c @total=74.8, @cutime=0.0, @label="", @stime=1.79, @real=76.8895101547241, @utime=73.01, @cstime=0.0>

real	1m21.836s
user	1m17.625s
sys	0m2.060s

(it seems slower w/o .transaction)

... and it won't scale any better, so it wouldn't solve the OP's problem:

>       def find_all(template, limit=nil, &block)
>         template= Rinda::TemplateEntry.new(Array.new(template)) if Numeric 
>         === template
>         size = template.size
>         all = []
>         @db.execute "select blob from bag where size=#{ size } #{ limit ? 
>         ('limit=%d' % limit) : '' }" do |tuple|
>           blob = tuple['blob']
>           t = decode blob
>           if t.alive? && template.match(t)
>             block ? block[t] : (all << t)
>           end
>         end
>         block ? nil : all
>       end
[...]
>       def find_all_template(tuple, limit=nil, &block)
>         size = tuple.size
>         all = []
>         @db.execute "select blob from bag where size=#{ size } #{ limit ? 
>         ('limit=%d' % limit) : '' }" do |tuple|
>           blob = tuple['blob']
>           t = decode blob
>           if t.alive? && t.match(tuple)
>             block ? block[t] : (all << t)
>           end
>         end
>         block ? nil : all
>       end

PS: some warnings removed...

--- sqlitespace.rb.orig	2007-02-10 09:33:20.000000000 +0100
+++ sqlitespace.rb	2007-02-10 10:09:50.000000000 +0100
@@ -43,7 +43,7 @@
          @read_waiter.transaction{
            @take_waiter.transaction{
              @notify_waiter.transaction{
-               instance_eval &b
+               instance_eval(&b)
              }
            }
          }
@@ -79,7 +79,7 @@
        def setup
          begin
            @db.execute(SCHEMA){}
-         rescue ::SQLite::SQLException => e
+         rescue (SQLite::SQLException rescue ::SQLite::Exceptions::SQLException) # tested with sqlite-ruby 2.2.3
            42
          end
        end
@@ -88,7 +88,7 @@
      # for older rubys
      #
        begin
-         Base64
+         x = Base64
          def encode64 blob
            Base64.encode64 blob
          end
@@ -122,7 +122,7 @@
        end
 
        def execute *a, &b
-         @db.execute *a, &b
+         @db.execute(*a, &b)
        end
 
        def transaction *a, &b
@@ -213,7 +213,7 @@
      end
 
      def transaction *a, &b
-       @db.transaction *a, &b
+       @db.transaction(*a, &b)
      end
 
      %w( push delete find_all find find_all_template delete ).each do |m|


-- 
Mauricio Fernandez  -   http://eigenclass.org   -  singular Ruby
                        ** Latest postings **
What's new in Ruby 1.9, Feb. 07 update
  http://eigenclass.org/hiki.rb?Changes-in-Ruby-1.9-update-6
Firebrigade: automated, sandboxed testing of RubyGems packages by other devels
  http://eigenclass.org/hiki.rb?firebrigade-launched