ThreadLimiter 0.1.0

E

Erik Veenstra

ThreadLimiter 0.1.0 is released.

RDoc: http://www.erikveen.dds.nl/threadlimiter/doc/index.html
Download: http://rubyforge.org/projects/threadlimiter/index.html

gegroet,
Erik V. - http://www.erikveen.dds.nl/

----------------------------------------------------------------

ThreadLimiter forks threads like Thread.fork(), but limits the
number of concurrently running threads.

ThreadLimiter isn't a thread pool. Each fork really starts a
new thread.

Example: Get the titles of a large collections of URL's.

The traditional way, using Thread directly:

urls = [.....] # A lot of URL's. Maybe
even thousends.

titles =
urls.collect do |url|
Thread.fork do
# ... get the title of the url...
end
end.collect do |thread|
thread.value
end

With ThreadLimiter#fork():

thread_limiter = ThreadLimiter.new(10) # Max. 10 concurrently
running threads.
urls = [.....] # A lot of URL's. Maybe
even thousends.

titles =
urls.collect do |url|
thread_limiter.fork do
# ... get the title of the url...
end
end.collect do |thread|
thread.value
end

With Enumerable#threaded_collect():

urls = [.....] # A lot of URL's. Maybe
even thousends.

titles =
urls.threaded_collect(10) do |url| # Max. 10 concurrently
running threads.
# ... get the title of the url...
end

----------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,264
Latest member
FletcherDa

Latest Threads

Top