# Drb and PStore behaviour

**URL:** <https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139>\
**Category:** Ruby\
**Created:** [May 20, 2006, 10:38pm UTC](https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139 "2006-05-20T22:38:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 20, 2006, 10:38pm UTC](https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139/1 "2006-05-20T22:38:09Z")

</div>

I’m doing a remote database object so i can do:

result = database.find do |record|  
record[:name] == “john”  
end

in the server object i have something like:

class Foo  
include DRb::DRbUndumped

```
 def find(&block)
         result = nil
         @store.transaction do
                 result = @store[:records].find_all do |record|

                          yield(record)
                 end
         end
         return result
 end

```

end

well, the problem is yielding that block. All the database is  
“cloned/copied” (?) over the network when doing the find. I don’t want  
to copy all that data, just return the found records.

I tried adding DRb::DRbUndumped to class PStore, but the same result.  
The database size is about 3 MB.

Do you know how to solve this problem?

---

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 20, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139/2 "2006-05-20T23:18:21Z")

</div>

The problem is that you can’t pass a block from the client to the server  
because block’s aren’t serializable.

Jamey

---

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 20, 2006, 11:31pm UTC](https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139/3 "2006-05-20T23:31:41Z")

</div>

Oh, so the answer to my problem will be to rewrite using sockets and  
marshaling for that.

(the same happened with xmlrpc).  
thanks for the quick response.

---

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 21, 2006, 6:17am UTC](https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139/4 "2006-05-21T06:17:51Z")

</div>

Javier V. wrote:

> ```
> def find(&block)
> 
> ```

```
           ^^^^^^

```

You don’t need this, since you are using yield.

> well, the problem is yielding that block. All the database is  
> “cloned/copied” (?) over the network when doing the find. I don’t want  
> to copy all that data, just return the found records.

Yielding to a DRb client is not itself a problem. The block stays on the  
client side. In some cases that’s ok, but in this case, it generates too  
much traffic because every record iterated over by find\_all is  
serialized to the client, so that the client can call the block on it.

> I tried adding DRb::DRbUndumped to class PStore, but the same result.  
> The database size is about 3 MB.

I doubt the database object as a whole is being serialized, just each  
record individually.

Maybe you want do define query objects and pass them as an argument to  
find?

result = database.find(QueryEqual.new(:name, “john”))

Then only the query object and the results need to get serialized.

---

<div class="post-metadata">

**Author:** ![javier\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@javier\_v](https://www.ruby-forum.com/u/javier_v)\
**Post date:** [May 21, 2006, 8:11am UTC](https://www.ruby-forum.com/t/drb-and-pstore-behaviour/61139/5 "2006-05-21T08:11:02Z")

</div>

Joel VanderWerf wrote:

> > 
> 
> > well, the problem is yielding that block. All the database is
> 
> result = database.find(QueryEqual.new(:name, “john”))
> 
> Then only the query object and the results need to get serialized.

Interesting point, i’ll try it.

And thanks for the correction.
