
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>mruby Apache mod_mruby | monolog</title>
	<atom:link href="https://blog.monora.me/tag/mruby-apache-mod_mruby/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.monora.me</link>
	<description>monora log #=&#62; ものろーぐ</description>
	<lastBuildDate>Sun, 24 May 2020 18:57:42 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.1</generator>
<site xmlns="com-wordpress:feed-additions:1">21279848</site>	<item>
		<title>mod_mrubyをFreeBSDで動かそうとして詰まる</title>
		<link>https://blog.monora.me/2012/12/mod_mruby%e3%82%92freebsd%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%9d%e3%81%86%e3%81%a8%e3%81%97%e3%81%a6%e8%a9%b0%e3%81%be%e3%82%8b/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mod_mruby%25e3%2582%2592freebsd%25e3%2581%25a7%25e5%258b%2595%25e3%2581%258b%25e3%2581%259d%25e3%2581%2586%25e3%2581%25a8%25e3%2581%2597%25e3%2581%25a6%25e8%25a9%25b0%25e3%2581%25be%25e3%2582%258b</link>
		
		<dc:creator><![CDATA[きょんたん]]></dc:creator>
		<pubDate>Fri, 21 Dec 2012 11:37:29 +0000</pubDate>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[mruby Apache mod_mruby]]></category>
		<guid isPermaLink="false">http://blog.monora.me/?p=230</guid>

					<description><![CDATA[<p>CombConfの発表が2日後に迫っているにも関わらず他の技術に手がでます。 組み込み向けのRubyであるmrubyをApacheに組み込めるようにした、mod_mrubyというものをFreeBSDで動かしてみようかと思 [&#8230;]</p>
The post <a href="https://blog.monora.me/2012/12/mod_mruby%e3%82%92freebsd%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%9d%e3%81%86%e3%81%a8%e3%81%97%e3%81%a6%e8%a9%b0%e3%81%be%e3%82%8b/">mod_mrubyをFreeBSDで動かそうとして詰まる</a> first appeared on <a href="https://blog.monora.me">monolog</a>.]]></description>
										<content:encoded><![CDATA[<p>CombConfの発表が2日後に迫っているにも関わらず他の技術に手がでます。</p>
<p>組み込み向けのRubyである<a title="mruby/mruby · GitHub" href="https://github.com/mruby/mruby">mruby</a>をApacheに組み込めるようにした、<a title="matsumoto-r/mod_mruby · GitHub" href="https://github.com/matsumoto-r/mod_mruby">mod_mruby</a>というものをFreeBSDで動かしてみようかと思って手を出したら大苦戦しました。</p>
<p>とりあえず動いたには動いたという状況ですが、簡単なメモとベンチマークを取ってみました。</p>
<blockquote><p>
<strong>2013/2/17追記</strong><br />
mod_mrubyの更新によって手順が変わりました⇒ <a title="mod_mruby on FreeBSD" href="https://blog.monora.me/2013/02/mod_mruby-on-freebsd/">mod_mruby on FreeBSD</a>
</p></blockquote>
<p>導入はmod_mrubyのページと同じようにやればいいのかと思いきや、makeでエラーを吐いてしまいます。</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-linenumbers="true">
$ make
make: illegal option -- -
usage: make [-BPSXeiknpqrstv] [-C directory] [-D variable]
        [-d flags] [-E variable] [-f makefile] [-I directory]
        [-j max_jobs] [-m directory] [-V variable]
        [variable=value] [target ...]
rake aborted!
Command failed with status (2): [make -C src --no-print-directory CC='gcc' ...]

Tasks: TOP =&gt; default =&gt; all
(See full trace by running task with --trace)
*** [libmruby.a] Error code 1

Stop in /root/mod_mruby.
</pre>
<p>どうもmrubyのRakefileがLinux向けのようで、makeをgmakeに書き換える必要があるようです。</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-linenumbers="true">
$ nano tmp/mruby/Rakefile
#MAKE = ENV['MAKE'] || 'make'
MAKE = ENV['MAKE'] || 'gmake'
</pre>
<p>mrubyは1回mod_mrubyをmakeをしないとRakefileが存在しないので注意です。</p>
<p>あとはWarningが出ますがとりあえずスルーして、make installすればApacheにモジュールが登録されます。<br />
あとはhttpd.confに、</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-linenumbers="true">
AddHandler mruby-script .mrb
</pre>
<p>と書き加えれば普通にmrubyファイルが動くはずなのですが……</p>
<p>自分の環境(Freebsd 9.1-BETA1 amd64, Apache/2.2.23 Event MPM)な環境では、httpdを起動した直後からCPUをバカ食いする上、リクエストに全く応答しなくなるという状況に陥ってしまい、解決策が分からなくなりました。<br />
そんなことをTwitterで呟いたら、mod_mrubyの作者である、<a title="人間とウェブの未来" href="http://blog.matsumoto-r.jp/" target="_blank" rel="noopener noreferrer">matsumoto-r</a>さんから</p>
<blockquote class="twitter-tweet" data-width="550" data-dnt="true">
<p lang="ja" dir="ltr"><a href="https://twitter.com/kyonfuee?ref_src=twsrc%5Etfw">@kyonfuee</a> 現状、きちんと対応しているのはpreformでworkerもeventも一応動くのですが、不安定です。preforkで試してもだめでしょうか？</p>
<p>&mdash; Ryosuke Matsumoto / まつもとりー (@matsumotory) <a href="https://twitter.com/matsumotory/status/282046980342022144?ref_src=twsrc%5Etfw">December 21, 2012</a></p></blockquote>
<p><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>という指摘を頂きました。試しに(FreeBSD 9.0 i386, Apache/2.2.22 Prefork MPM)な旧サーバーで試したところ、何も問題がないかのように動きました。<br />
どうもApache 2.2でEvent MPMをやるのはだめみたい……？</p>
<p><span id="more-230"></span></p>
<p>試しにどのくらい速いのか、mruby, FastCGIのRuby(mod_fcgid, 1.9.3p125), 静的ファイルの3つで比較してみました。</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-linenumbers="true">
$ cat test.mrb
Apache.rputs(&quot;Hello&quot;)
Apache.return(Apache::OK)
#!/usr/local/bin/ruby

$ cat test.rb
print &quot;Content-type: text/plainnn&quot;
print &quot;Hello!&quot;

$ cat test.txt
Hello!
</pre>
<p>検証機のスペック: <a title="ThinkCentre S50(8086-AGJ) - 製品仕様" href="http://support.lenovo.com/ja_JP/detail.page?LegacyDocID=SYP0-03184BF" target="_blank" rel="noopener noreferrer">IBM ThinkCentre 8086-AGJ</a><br />
CPU: Celeron D 330 2.66GHz<br />
RAM: DDR-SDRAM 1GB<br />
LAN: Gigabit Ethernet(Intel chip)</p>
<p>abの条件は下記の通り</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-linenumbers="true">
$ ab -n 100000 -c 100
</pre>
<p>結果:</p>
<ul>
<li>mruby</li>
</ul>
<p>Time taken for tests: 108.551 seconds<br />
Requests per second: <strong>921.23 [#/sec]</strong> (mean)<br />
Time per request: 108.551 [ms] (mean)<br />
Time per request: 1.086 [ms] (mean, across all concurrent requests)</p>
<ul>
<li>Ruby(FastCGI)</li>
</ul>
<p>Time taken for tests: 362.996 seconds<br />
<strong>Failed requests: 109</strong><br />
Requests per second: <strong>275.48 [#/sec]</strong> (mean)<br />
Time per request: 362.996 [ms] (mean)<br />
Time per request: 3.630 [ms] (mean, across all concurrent requests)</p>
<ul>
<li>txt</li>
</ul>
<p>Time taken for tests: 98.767 seconds<br />
Requests per second: <strong>1012.48 [#/sec]</strong> (mean)<br />
Time per request: 98.767 [ms] (mean)<br />
Time per request: 0.988 [ms] (mean, across all concurrent requests)</p>
<p>なんとmrubyが静的ファイルに迫る速度を出してました。すごい……</p>
<p><small>ちなみにmrubyが動かなかった方のメインサーバー(Core2 duo E6300@1.86Ghz, RAM512MB)ではRuby(FastCGI: mod_fcgid)で1857.93 [#/sec]とかいう値を叩きだしてました。</small><br />
後日メインのサーバーの方もPreforkにして検証してみようかと思います。<br />
いつになったらFreeBSD PortsにApache 2.4が来るのだろう……</p>
<p>そういえば、もう明後日に迫っていますが、<a title="CombConf" href="http://combconf.com/" target="_blank" rel="noopener noreferrer">CombConf</a>に参加します！<br />
内容は、「HTTPSを使わずに暗号化通信をしよう」でやる予定です。<br />
出来るの………？(まだ検証してない</p>The post <a href="https://blog.monora.me/2012/12/mod_mruby%e3%82%92freebsd%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%9d%e3%81%86%e3%81%a8%e3%81%97%e3%81%a6%e8%a9%b0%e3%81%be%e3%82%8b/">mod_mrubyをFreeBSDで動かそうとして詰まる</a> first appeared on <a href="https://blog.monora.me">monolog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">230</post-id>	</item>
	</channel>
</rss>
