{"id":1953,"date":"2010-11-08T16:19:50","date_gmt":"2010-11-08T07:19:50","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=1953"},"modified":"2021-04-27T15:03:25","modified_gmt":"2021-04-27T06:03:25","slug":"post1953","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2010\/11\/1953\/","title":{"rendered":"Ruby\u306e\u3059\u309d\u3081 #01 - \u30d9\u30f3\u30c1\u30de\u30fc\u30af\u30c6\u30b9\u30c8\u3068\u30d7\u30ed\u30bb\u30b9\u7ba1\u7406\u7de8"},"content":{"rendered":"<p>\u3044\u3064\u3082\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u305f\u3060\u3044\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u30b0\u30ea\u30fc\u682a\u5f0f\u4f1a\u793e\u3067\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u3057\u3066\u3044\u308b takano32 \u3067\u3059\u3002<\/p>\n<p>\u8aad\u8005\u306e\u65b9\u3005\u306b\u306f\u30d7\u30ed\u30b0\u30e9\u30de\u3084\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u3057\u3066\u3044\u308b\u65b9\u3005\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u307f\u306a\u3055\u3093\u306f\u4f55\u304b\u624b\u306b\u99b4\u67d3\u3093\u3060\u9053\u5177\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u304b\uff1f<\/p>\n<p>\u30b0\u30ea\u30fc\u306b\u3064\u3044\u3066\u8a00\u3048\u3070\u300c\u30b0\u30ea\u30fc\u3068\u3044\u3048\u3070\u3001PHP\u3068MySQL\u300d\u3068\u3044\u3046\u30a4\u30e1\u30fc\u30b8\u3092\u304a\u6301\u3061\u306e\u65b9\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u3057\u3001\u5b9f\u969b\u306b\u30b7\u30b9\u30c6\u30e0\u306e\u6838\u5fc3\u90e8\u306fPHP\u3068MySQL\u306b\u3088\u3063\u3066\u6a5f\u80fd\u3057\u3066\u3044\u307e\u3059\u3002PHP\u3068MySQL\u306f\u30b0\u30ea\u30fc\u306b\u6b20\u304b\u305b\u306a\u3044\u9053\u5177\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u30b0\u30ea\u30fc\u3067\u50cd\u304f\u30a8\u30f3\u30b8\u30cb\u30a2\u3072\u3068\u308a\u3072\u3068\u308a\u306b\u306f\u3084\u306f\u308a\u500b\u6027\u304c\u3042\u308a\u3001\u624b\u306b\u99b4\u67d3\u3093\u3067\u3044\u308b\u9053\u5177\u3082\u4eba\u305d\u308c\u305e\u308c\u3067\u3059\u3002<br \/>\nPython\u3067\u793e\u5185\u30b7\u30b9\u30c6\u30e0\u5411\u3051\u306e\u30af\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3057\u3066\u60c5\u5831\u3092\u53ce\u96c6\u3057\u3066\u3044\u308b\u65b9\u3001C\u8a00\u8a9e\u3067\u30b0\u30ea\u30fc\u306e\u30b7\u30b9\u30c6\u30e0\u306b\u9069\u5408\u3059\u308bDNS\u30b5\u30fc\u30d0\u3084MySQL\u30d7\u30ed\u30ad\u30b7(g2proxy)\u3092\u4f5c\u6210\u3057\u3066\u3044\u308b\u65b9\u3005\u306a\u3069\u3055\u307e\u3056\u307e\u306a\u30a8\u30f3\u30b8\u30cb\u30a2\u304c\u30b0\u30ea\u30fc\u3067\u306f\u50cd\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u79c1\u3082\u3044\u3064\u3082PHP\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u3001\u624b\u306b\u99b4\u67d3\u3093\u3060\u9053\u5177\u3068\u3057\u3066\u306fRuby\u3092\u7528\u3044\u308b\u983b\u5ea6\u304c\u9ad8\u3044\u3067\u3059\u3002\u4eca\u56de\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b7\u30b9\u30c6\u30e0\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306b\u7528\u3044\u305fRuby\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306e\u5bfe\u8c61\u3068\u306a\u308b\u30b7\u30b9\u30c6\u30e0\u3084\u524d\u63d0\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<ul>\n<li> \u30b3\u30a2\u306e\u30b7\u30b9\u30c6\u30e0\u306f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308b<\/li>\n<li> \u8ca0\u8377\u3092\u4e0e\u3048\u308b\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306ePHP\u30b9\u30af\u30ea\u30d7\u30c8\uff08\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u7528\u3044\u308b\u305f\u3081\u3001PHP\u3067\u8a18\u8ff0\uff09\u304c\u3042\u308b<\/li>\n<li> \u30d9\u30f3\u30c1\u30de\u30fc\u30af\u65b9\u6cd5\u306f\u8ca0\u8377\u3092\u4e0e\u3048\u308bPHP\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u5b9f\u884c\u3092\u958b\u59cb\u3057\u3001\u7d42\u4e86\u3059\u308b\u307e\u3067\u306e\u5b9f\u884c\u6642\u9593\u3092\u30b9\u30b3\u30a2\u3068\u3059\u308b<\/li>\n<li> \u8ca0\u8377\u3092\u4e0e\u3048\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u8a08\u7b97\u6a5f\u306f\u30de\u30eb\u30c1\u30b3\u30a2\u3067\u3042\u308b<\/li>\n<li> \u8ca0\u8377\u3092\u8a08\u6e2c\u3059\u308b\u306b\u306f\u5927\u91cf\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u304c\u5fc5\u8981\u3067\u3042\u308b<\/li>\n<\/ul>\n<p>PHP\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u306b\u3059\u308b\u3053\u3068\u3084\u30d7\u30ed\u30bb\u30b9\u3092\u30d5\u30a9\u30fc\u30af\u3059\u308b\u3053\u3068\u3082\u8003\u3048\u3089\u308c\u307e\u3057\u305f\u304c\u3001PHP\u304cWeb\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u5411\u3051\u306e\u7528\u9014\u3092\u5f97\u610f\u3068\u3057\u3066\u3044\u308b\u3053\u3068\u3084\u3001\u308f\u305f\u3057\u304c\u307e\u3060PHP\u306b\u8a73\u3057\u304f\u306a\u3044\u3053\u3068\u3092\u8003\u3048\u308b\u3068\u8e8a\u8e87\u3044\u3092\u611f\u3058\u307e\u3057\u305f\u3002<br \/>\n\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306aRuby\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8a18\u8ff0\u3057\u3001\u3044\u304f\u3064\u304b\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3092\u540c\u6642\u5b9f\u884c\u3057\u3001\u3059\u3079\u3066\u306e\u30d7\u30ed\u30bb\u30b9\u304c\u5b9f\u884c\u3092\u7d42\u4e86\u3059\u308b\u307e\u3067\u306e\u6642\u523b\u3092\u8a08\u6e2c\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Ruby\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8a18\u8ff0\u3059\u308b\u306b\u3042\u305f\u3063\u3066\u6ce8\u610f\u3057\u305f\u90e8\u5206\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7b87\u6240\u3067\u3059\u3002<\/p>\n<ul>\n<li> Ruby\u306e\u30b9\u30ec\u30c3\u30c9\u306f\u51e6\u7406\u7cfb\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u306f\u30e6\u30fc\u30b6\u30ec\u30d9\u30eb\u30b9\u30ec\u30c3\u30c9\u3067\u3042\u308b\u305f\u3081\u3001\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u4f9d\u5b58\u3057\u306a\u3044\u3088\u3046\u306b\u8907\u6570\u306e\u30b3\u30a2\u3092\u4f7f\u3044\u5207\u308b\u305f\u3081\u306b\u306f\u30d7\u30ed\u30bb\u30b9\u3092\u8907\u6570\u8d77\u52d5\u3057\u305f\u307b\u3046\u304c\u3088\u3044<\/li>\n<li> \u30d7\u30ed\u30bb\u30b9\u306e\u30d5\u30a9\u30fc\u30af\u306f\u5358\u4e00\u306e\u5b50\u30d7\u30ed\u30bb\u30b9\u3092\u5b9f\u884c\u3057\u3001\u5f85\u3061\u5408\u308f\u305b\u3092\u3059\u308b\u306e\u306b\u306f\u4fbf\u5229\u3060\u304c\u3001\u8907\u6570\u306e\u5b50\u30d7\u30ed\u30bb\u30b9\u3092\u5236\u5fa1\u3059\u308b\u306b\u306f\u5c11\u3057\u8907\u96d1\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u306a\u3063\u3066\u3057\u307e\u3046<\/li>\n<li> exec \u306f\u51e6\u7406\u306e\u3042\u3068\u306b exec \u5143\u306e\u884c\u306b\u306f\u623b\u3089\u306a\u3044<\/li>\n<\/ul>\n<p>\u66f8\u304d\u3042\u304c\u3063\u305fRuby\u30b9\u30af\u30ea\u30d7\u30c8\u306fThread, fork, exec \u306e\u5404\u7279\u5fb4\u3092\u7d44\u307f\u5408\u308f\u305b\u3001Thread\u3067\u5b9f\u884c\u306e\u7ba1\u7406\u3092\u5b9f\u73fe\u3001fork\u3067\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u3067\u306e\u5b9f\u884c\u3092\u5b9f\u73fe\u3001exec\u3067Ruby\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089\u4ed6\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3078\u30d7\u30ed\u30bb\u30b9\u306e\u51e6\u7406\u3092\u5909\u66f4\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"superpre ruby\">\n#!\/usr\/bin\/env ruby\n# process_group.rb\n\nclass ProcessGroup\n        def initialize\n                @threads = ThreadGroup.new\n        end\n\n        def exec(*args)\n                th = Thread.start do\n                        fork_exec(*args)\n                end\n                @threads.add(th)\n        end\n\n        def fork_exec(*args)\n                pid = fork\n                unless pid then\n                        Kernel.exec(*args)\n                else\n                        Process.waitpid(pid)\n                end\n        end\n\n        def wait\n                @threads.list.each do |th|\n                        th.join\n                end\n        end\nend\n\n\nif $0 == __FILE__ then\n        pg = ProcessGroup.new\n        pg.exec(\"\/usr\/bin\/php5\", \"bench.php\", \"input01.txt\")\n        pg.exec(\"\/usr\/bin\/php5\", \"bench.php\", \"input02.txt\")\n        pg.exec(\"\/usr\/bin\/php5\", \"bench.php\", \"input03.txt\")\n        pg.exec(\"\/usr\/bin\/php5\", \"bench.php\", \"input04.txt\")\n        pg.wait\n        puts \"end\"\nend<\/pre>\n<p>\u540d\u524d\u306fProcess\u3092Group\u3067\u7ba1\u7406\u3059\u308b\u30af\u30e9\u30b9\u3068\u3044\u3046\u3053\u3068\u3067ProcessGroup\u30af\u30e9\u30b9\u3068\u3057\u307e\u3057\u305f\u3002Ruby\u306b\u306f\u6a19\u6e96\u3067ThreadGroup\u30af\u30e9\u30b9\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308b\u306e\u3067\u3059\u304c\u3001ProcessGroup is-a ThreadGroup \u3068\u3044\u3046\u95a2\u4fc2\u6027\u306f\u306a\u3044\u306e\u3067\u3001\u7279\u306b\u7d99\u627f\u306a\u3069\u306f\u3057\u3066\u3044\u307e\u305b\u3093\u3002<br \/>\n\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3067\u306f\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u5b9f\u884c\u6642\u9593\u3092time\u30b3\u30de\u30f3\u30c9\u3067\u8a08\u6e2c\u3059\u308b\u3053\u3068\u3067\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306e\u30b9\u30b3\u30a2\u3068\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u306fRuby\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u8907\u6570\u306e\u30d7\u30ed\u30bb\u30b9\u3092\u4e26\u884c\u306b\u5b9f\u884c\u3057\u3066\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3092\u884c\u3046\u4f8b\u3092\u7d39\u4ecb\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u4ed6\u306b\u3082\u30b0\u30ea\u30fc\u3067\u306f\u5927\u898f\u6a21\u306a\u30b5\u30fc\u30d0\u7fa4\u306b\u3061\u3087\u3063\u3068\u3057\u305f\u4e00\u6589\u51e6\u7406\u3092\u884c\u3046\u3068\u304d\u3084\u3001\u60c5\u5831\u306e\u53ce\u96c6\u306a\u3069\u306bRuby\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u4f7f\u308f\u308c\u3066\u3044\u308b\u7b87\u6240\u306a\u3069\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u307f\u306a\u3055\u3093\u3082\u81ea\u5206\u306e\u624b\u306b\u99b4\u67d3\u3093\u3060\u9053\u5177\u3092\u5927\u5207\u306b\u3057\u3001\u826f\u3044\u30a8\u30f3\u30b8\u30cb\u30a2\u30e9\u30a4\u30d5\u3092\u304a\u9001\u308a\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u3054\u610f\u898b\u3054\u611f\u60f3\u306a\u3069\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u305c\u3072 <a href=\"http:\/\/twitter.com\/takano32\/\">@takano32<\/a> \u307e\u3067\u3054\u9023\u7d61\u304f\u3060\u3055\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u307e\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3044\u3064\u3082\u30a8\u30f3\u30b8\u30cb\u30a2\u30d6\u30ed\u30b0\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u305f\u3060\u3044\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u30b0\u30ea\u30fc\u682a\u5f0f\u4f1a\u793e\u3067\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u3057\u3066\u3044\u308b takano32 \u3067\u3059\u3002 \u8aad\u8005\u306e\u65b9\u3005\u306b\u306f\u30d7\u30ed\u30b0\u30e9\u30de\u3084\u30a8\u30f3\u30b8\u30cb\u30a2\u3092\u3057\u3066\u3044\u308b\u65b9\u3005\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u307f\u306a\u3055\u3093\u306f\u4f55\u304b\u624b\u306b [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[25],"class_list":["post-1953","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-info","tag-ruby"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/1953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=1953"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/1953\/revisions"}],"predecessor-version":[{"id":21143,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/1953\/revisions\/21143"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=1953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=1953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=1953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}