# Re: forkoff - parallel processing for ruby enumerables

**URL:** <https://www.ruby-forum.com/t/re-forkoff-parallel-processing-for-ruby-enumerables/135404>\
**Category:** Ruby\
**Created:** [April 21, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/re-forkoff-parallel-processing-for-ruby-enumerables/135404 "2008-04-21T22:39:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhoult](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bhoult](https://www.ruby-forum.com/u/bhoult)\
**Post date:** [April 21, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/re-forkoff-parallel-processing-for-ruby-enumerables/135404/1 "2008-04-21T22:39:41Z")

</div>

I had some issues using active record objects inside the code block. It  
seems that activerecord does not allow concurrency by default, and I  
ended  
up with “MySQL server has gone away” messages as a result.

I found a couple of possible fixes here  
[http://www.ruby-forum.com/topic/123472](http://www.ruby-forum.com/topic/123472), and am not sure which one is  
best to  
use.

The first is just to add “ActiveRecord::Base.allow\_concurrency = true”  
which  
seems to work fine for me and is certainly the simplest.

The other is to “ActiveRecord::Base.remove\_connection” before forkoff!  
then  
“ActiveRecord::Base.establish\_connection(dbconfig)” first thing in the  
code  
block, then “ActiveRecord::Base.establish\_connection(dbconfig)” after  
forkoff.

If the second method is better then it would probably be best added to  
the  
gem. Any advice?

---

<div class="post-metadata">

**Author:** ![bhoult](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bhoult](https://www.ruby-forum.com/u/bhoult)\
**Post date:** [April 22, 2008, 12:52am UTC](https://www.ruby-forum.com/t/re-forkoff-parallel-processing-for-ruby-enumerables/135404/2 "2008-04-22T00:52:29Z")

</div>

On Apr 21, 2008, at 2:39 PM, Brandon H. wrote:

> The other is to “ActiveRecord::Base.remove\_connection” before  
> forkoff! then  
> “ActiveRecord::Base.establish\_connection(dbconfig)” first thing in  
> the code  
> block, then “ActiveRecord::Base.establish\_connection(dbconfig)” after  
> forkoff.
> 
> If the second method is better then it would probably be best added  
> to the  
> gem. Any advice?

this is purely an active record issue - nothing to do with forkoff.  
the ar code doesn’t carry itself across a fork - there are a few  
patches out there that fix this - one by a guy in denver - can’t  
recall his name - anyone?

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![bhoult](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bhoult](https://www.ruby-forum.com/u/bhoult)\
**Post date:** [April 29, 2008, 11:14pm UTC](https://www.ruby-forum.com/t/re-forkoff-parallel-processing-for-ruby-enumerables/135404/3 "2008-04-29T23:14:55Z")

</div>

Check out the code for spawn, the guys have fixed this
