{"id":18041925,"url":"https://github.com/bruceadams/pmap","last_synced_at":"2025-04-06T12:09:46.076Z","repository":{"id":1151517,"uuid":"1035448","full_name":"bruceadams/pmap","owner":"bruceadams","description":"Convenience Parallel Processing methods for Ruby","archived":false,"fork":false,"pushed_at":"2021-10-31T21:31:15.000Z","size":53,"stargazers_count":70,"open_issues_count":2,"forks_count":7,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-30T11:07:18.541Z","etag":null,"topics":["concurrency","hacktoberfest","multithreading","parallel","peach","pmap","ruby","ruby-threads","thread"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bruceadams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-10-29T17:20:19.000Z","updated_at":"2024-06-05T13:57:14.000Z","dependencies_parsed_at":"2022-07-06T09:01:54.879Z","dependency_job_id":null,"html_url":"https://github.com/bruceadams/pmap","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruceadams%2Fpmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruceadams%2Fpmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruceadams%2Fpmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruceadams%2Fpmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bruceadams","download_url":"https://codeload.github.com/bruceadams/pmap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478323,"owners_count":20945266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","hacktoberfest","multithreading","parallel","peach","pmap","ruby","ruby-threads","thread"],"created_at":"2024-10-30T16:13:24.292Z","updated_at":"2025-04-06T12:09:46.051Z","avatar_url":"https://github.com/bruceadams.png","language":"Ruby","readme":"# pmap\n\n[![Build status](https://github.com/bruceadams/pmap/actions/workflows/ruby.yml/badge.svg)](https://github.com/bruceadams/pmap/actions)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)\n[![Apache License](https://img.shields.io/github/license/bruceadams/pmap?logo=apache)](LICENSE)\n\nThis Ruby gem adds three methods to any Enumerable (notably including\nany Array). The three added methods are:\n\n* _pmap_ parallel map\n* _peach_ parallel each\n* _peach_with_index_ parallel each_with_index\n\nThreading in Ruby has limitations\n----------------------------------\n\nMatz Ruby 1.8.* uses _green_ threads. All Ruby threads are run within\na single thread in a single process. A single Ruby program will never\nuse more than a single core of a multi-core machine.\n\nMatz Ruby 1.9.* uses _native_ threads. Each Ruby thread maps directly\nto a thread in the underlying operating system. In theory, a single\nRuby program can use multiple cores. Unfortunately, there is a global\ninterpreter lock _GIL_ that causes single-threaded behavior.\n\nJRuby also uses _native_ threads. JRuby avoids the global interpreter\nlock, allowing a single Ruby program to really use multiple CPU cores.\n\nThreading useful for remote IO, such as HTTP\n--------------------------------------------\n\nDespite the Matz Ruby threading limitations, IO bound actions can\ngreatly benefit from multi-threading. A very typical use is making\nmultiple HTTP requests in parallel. Issuing those requests in separate\nRuby threads means the requests will be issued very quickly, well\nbefore the responses start coming back. As responses come back, they\nwill be processed as they arrive.\n\nExample\n-------\n\nSuppose that we have a function get_quote that calls out to a stock\nquote service to get a current stock price. The response time for\nget_quote ranges averages 0.5 seconds.\n\n    stock_symbols = [:ibm, :goog, :appl, :msft, :hp, :orcl]\n\n    # This will take about three seconds;\n    # an eternity if you want to render a web page.\n    stock_quotes = stock_symbols.map {|s| get_quote(s)}\n\n    # Replacing \"map\" with \"pmap\" speeds it up.\n    # This will take about half a second;\n    # however long the single slowest response took.\n    stock_quotes = stock_symbols.pmap {|s| get_quote(s)}\n\nThread Count\n------------\n\nThe thread count defaults to 64 and is set based on `$pmap_default_thread_count`.\n\nYou can also set the thread count per call by passing it as an argument to the `pmap` and `peach` methods.\n\n    # Use the default thread count (64)\n    (1..128).peach { |i| sleep 1 } # Takes 2 seconds\n\n    # Use a thread count of 128\n    (1..128).peach(128) { |i| sleep 1 } # Takes 1 second\n\n    # Use a thread count of 2\n    (1..128).peach(2) { |i| sleep 1 } # Takes 64 seconds\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbruceadams%2Fpmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbruceadams%2Fpmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbruceadams%2Fpmap/lists"}