# \[ANN\] forkoff - parallel processing for ruby enumerables

**URL:** <https://rubytalk.org/t/ann-forkoff-parallel-processing-for-ruby-enumerables/46015>\
**Category:** ruby-talk\
**Created:** [21 April 2008 20:39 UTC](https://rubytalk.org/t/ann-forkoff-parallel-processing-for-ruby-enumerables/46015 "2008-04-21T20:39:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Hoult](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Brandon\_Hoult](https://rubytalk.org/u/Brandon_Hoult)\
**Post date:** [21 April 2008 20:39 UTC](https://rubytalk.org/t/ann-forkoff-parallel-processing-for-ruby-enumerables/46015/1 "2008-04-21T20:39:11Z")

</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:** ![a11](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/a11/32/8169_2.png) [@a11](https://rubytalk.org/u/a11)\
**Post date:** [21 April 2008 22:51 UTC](https://rubytalk.org/t/ann-forkoff-parallel-processing-for-ruby-enumerables/46015/2 "2008-04-21T22:51:06Z")

</div>

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/)

> **···**
>
> On Apr 21, 2008, at 2:39 PM, Brandon Hoult 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?
> 
> --  
> we can deny everything, except that we have the possibility of being better. simply reflect on that.  
> h.h. the 14th dalai lama

---

<div class="post-metadata">

**Author:** ![Abdul-rahman\_Advany](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@Abdul-rahman\_Advany](https://rubytalk.org/u/Abdul-rahman_Advany)\
**Post date:** [29 April 2008 21:14 UTC](https://rubytalk.org/t/ann-forkoff-parallel-processing-for-ruby-enumerables/46015/3 "2008-04-29T21:14:55Z")

</div>

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
