{"id":30637678,"url":"https://github.com/splaplapla/blue_green_process","last_synced_at":"2025-08-30T23:07:29.917Z","repository":{"id":50640603,"uuid":"519424424","full_name":"splaplapla/blue_green_process","owner":"splaplapla","description":"A library that solves GC bottlenecks with multi-process.","archived":false,"fork":false,"pushed_at":"2024-01-08T11:17:33.000Z","size":81,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-16T23:24:24.427Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/splaplapla.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-07-30T05:10:04.000Z","updated_at":"2022-08-11T05:43:02.000Z","dependencies_parsed_at":"2024-01-08T12:50:01.664Z","dependency_job_id":"f9e2e489-d25d-447b-9c4d-da6630c83b88","html_url":"https://github.com/splaplapla/blue_green_process","commit_stats":{"total_commits":85,"total_committers":2,"mean_commits":42.5,"dds":0.04705882352941182,"last_synced_commit":"67313545bab4a86b087275ae68f877bd8ac3c518"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/splaplapla/blue_green_process","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splaplapla%2Fblue_green_process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splaplapla%2Fblue_green_process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splaplapla%2Fblue_green_process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splaplapla%2Fblue_green_process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/splaplapla","download_url":"https://codeload.github.com/splaplapla/blue_green_process/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splaplapla%2Fblue_green_process/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272917735,"owners_count":25014935,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ruby"],"created_at":"2025-08-30T23:07:29.180Z","updated_at":"2025-08-30T23:07:29.910Z","avatar_url":"https://github.com/splaplapla.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BlueGreenProcess\n\nA library that solves GC bottlenecks with multi-process.\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add blue_green_process\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install blue_green_process\n\n## Usage\n\n```ruby\nBlueGreenProcess.configure do |config|\n  config.after_fork = -\u003e{ puts 'forked!' }\nend\n\nprocess = BlueGreenProcess.new(\n  worker_instance: BlueGreenProcess::BaseWorker.new,\n  max_work: 14,\n)\n\n40.times do\n  process.work\nend\n\nsleep(1)\n\nprocess.shutdown\n# or BlueGreenProcess.terminate_workers_immediately\nProcess.waitall\n```\n\n### プロセス間での値の共有\n* Hashが入っている'BlueGreenProcess::SharedVariable.data' の値はmaster process, work processで共有します.\n* 共有するHashのキーは `config.shared_variables` で許可する必要があります\n* プロセスを入れ替えるタイミングで値の復元とダンプを行います\n* JSONでシリアライズしているので共有できるオブジェクトはプリミティブ型に限定されます\n* GCの時間を軽減するために整数型だけを共有するとパフォーマンスに良さそう\n* `config.shared_variables` に最初から入っている `extend_run_on_this_process` は消すことができません\n\n```ruby\nBlueGreenProcess.configure do |config|\n  config.shared_variables = [:count]\nend\n\nworker_class = Class.new(BlueGreenProcess::BaseWorker) do\n  def initialize(*); end\n\n  def work(label)\n    BlueGreenProcess::SharedVariable.data['count'] += 1\n    puts \"#{label}'s data['count'] is #{BlueGreenProcess::SharedVariable.data['count']}\"\n  end\nend\n\nBlueGreenProcess::SharedVariable.data['count'] = 0\nprocess = BlueGreenProcess.new(worker_instance: worker_class.new, max_work: 3)\nprocess.work # blue\nprocess.work # green\nprocess.work # blue\nBlueGreenProcess::SharedVariable.data['count']\n```\n\noutputs\n\n```\nblue's data['count'] is 1\nblue's data['count'] is 2\nblue's data['count'] is 3\ngreen's data['count'] is 4\ngreen's data['count'] is 5\ngreen's data['count'] is 6\nblue's data['count'] is 7\nblue's data['count'] is 8\nblue's data['count'] is 9\n9\n```\n\n### 単一プロセスでの実行を延長する\n* workerクラスの中で、`BlueGreenProcess::SharedVariable.extend_run_on_this_process`にtrueをセットするともう一度同じプロセスで処理を行います\n    * 次の実行でtrueを明示しない限りはプロセスを切り替えます\n* 単一プロセスでの実行を延長するとGC.startを実行しなくなります\n    * 長時間にわたって延長する時は呼び出し側でGC.startを実行してください\n\n```ruby\nBlueGreenProcess.configure do |config|\n  config.shared_variables = [:count]\nend\n\nworker_class = Class.new(BlueGreenProcess::BaseWorker) do\n  def initialize(*); end\n\n  def work(label)\n    BlueGreenProcess::SharedVariable.data['count'] += 1\n    BlueGreenProcess::SharedVariable.extend_run_on_this_process = true\n    puts \"#{label}'s data['count'] is #{BlueGreenProcess::SharedVariable.data['count']}\"\n  end\nend\n\nBlueGreenProcess::SharedVariable.data['count'] = 0\nprocess = BlueGreenProcess.new(worker_instance: worker_class.new, max_work: 3)\nprocess.work # blue\nprocess.work # blue\nprocess.work # blue\nprocess.work # blue\n```\n\n### Metrics\nパフォーマンスの解析に使えます\n\n##### BlueGreenProcess.performance.process_switching_time_before_work\n* プロセスを最後に入れ替えた時にかかった時間を返す\n\n### Callbacks\n#### after_fork\n\nプロセスをforkした時に実行する\n\n```ruby\nBlueGreenProcess.configure do |config|\n  config.after_fork = -\u003e{ puts 'forked!' }\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/blue_green_process.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## NOTE\n* 処理は直列で行う\n* processが行う処理内容は引数を含めて固定\n* A processがinactiveになった時に行うGC.startに時間がかかると、次にA processがbe_activeになったらレスポンスが遅れる. 構造上の仕様.\n  * これが起きる場合はオブジェクトの生成を減らすとか、blue, greenではなくプロセスのプールを作ってプロセスがGCに時間を費やせるようにする\n* workerプロセスでエラーが起きたらmasterプロセスにそのエラーが伝わり、workerプロセスは終了します\n\n## TODO\n* shutdownしないでプロセスを停止したときにSIGINTを受け取りたい\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplaplapla%2Fblue_green_process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsplaplapla%2Fblue_green_process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplaplapla%2Fblue_green_process/lists"}