30
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rubyで簡単並列処理(Parallel)

Last updated at Posted at 2015-10-08

rubyで並列処理を書く場合、Parallelが簡単でおすすめです。

#インストール

gem install parallel

#実装例

マルチスレッドの例

list = ["A", "B", "C", "D"]
Parallel.each(list, in_thread: 2) do |name|
  puts name
end

マルチプロセスの例

list = ["A", "B", "C", "D"]
Parallel.each(list, in_process: 2) do |name|
  puts name
end

forkなどの処理をParallelが隠ぺいしてくれるので楽に書けますね。
in_thread, in_processの値を増やすことで並列度変更することもできます。

30
32
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?