github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

schleyfox / peach

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 13
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Parallel Each for JRuby — Read more

  cancel

http://peach.rubyforge.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fixed a rounding issue 
schleyfox (author)
Mon Aug 03 07:14:48 -0700 2009
commit  a865b07d3e43f2dcb5584df77a4f69fc935a6d65
tree    425894d4ebefc5ad0109838f803823100ff928df
parent  8d4910dd454ca5ad270d6e2d4fe8ff680c10e226
peach /
name age
history
message
file LICENSE Tue May 06 14:26:44 -0700 2008 Added MIT License git-svn-id: svn+ssh://rubyf... [schleyfox]
file README Tue May 06 14:26:44 -0700 2008 Added MIT License git-svn-id: svn+ssh://rubyf... [schleyfox]
file Rakefile Thu Apr 02 23:32:34 -0700 2009 Added tests, fixed a few potential bugs, cleane... [schleyfox]
directory bn/ Tue May 06 14:26:43 -0700 2008 Changed directory structure git-svn-id: svn+s... [schleyfox]
directory lib/ Mon Aug 03 07:14:48 -0700 2009 Fixed a rounding issue [schleyfox]
file peach.gemspec Tue Jul 14 06:50:39 -0700 2009 Optimizations that reduce memory usage a lot. [robbrit]
directory test/ Thu Apr 02 23:32:34 -0700 2009 Added tests, fixed a few potential bugs, cleane... [schleyfox]
directory web/ Tue May 06 14:42:07 -0700 2008 Fixed gemspec [schleyfox]
README
Parallel Each  (for ruby with threads) 

It is pretty common to have iterations over Arrays that can be safely run in parallel. With multicore chips becoming 
pretty common, single threaded processing is about as cool as Pog. Unfortunately, standard Ruby hates real threads 
pretty hardcore at the present time; however, for some ruby projects alternate VMs like  JRuby do give multicores some 
lovin'. Peach exists to make this power simple to use with minimal code changes. 

Functions like map, each, and delete_if are often used in a functional, side-effect free style. If the operation in the 
block is computationally intense, performance can often be gained by multithreading the process. That's where Peach 
comes in. In the simplest case, you are one letter away from harnessing the power of parallelism and unlocking the 
secret of a guilt-free tan. At this stage, the goggles are purely optional. 

Using Peach

Suppose you are going about your day job hacking away at code for the WOPR when you stumble upon the code: 

cities.each {|city| thermonuclear_war(city)}
        
Clearly, the only winning move is to declare war in parallel. With Peach, the new code is: 
require 'peach'

cities.peach {|city| thermonuclear_war(city)}
        
 Requiring peach.rb monkey patches Array into submission. Currently Peach provides peach, pmap, and pdelete_if. Each of 
 these functions takes an optional argument n, which represents the desired number of worker threads with the default 
 being one thread per Array element. For cheaper operations on a large number of elements, you probably want to set n to 
 something reasonably low. 

(0...10000).to_a.pmap(4) {|x| process(x)}
        
 Constructing the threads and adding on a few layers of indirection does add a bit of overhead to the iteration 
 especially on MRI. Keep this in mind and remember to benchmark when unsure. 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server