<?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/"
	>

<channel>
	<title>Erlang非业余研究 &#187; Erlang探索</title>
	<atom:link href="http://blog.yufeng.info/archives/tag/erlang/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.yufeng.info</link>
	<description>Erlang系统深度探索和应用</description>
	<lastBuildDate>Tue, 17 Jan 2012 06:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>高性能集群服务器(Erlang解决方案)</title>
		<link>http://blog.yufeng.info/archives/1479</link>
		<comments>http://blog.yufeng.info/archives/1479#comments</comments>
		<pubDate>Sat, 30 Jul 2011 14:42:57 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[高性能，集群，服务器]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=1479</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: 高性能集群服务器(Erlang解决方案) 高性能集群服务器(Erlang解决方案) View more presentations from Feng Yu Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/1479">高性能集群服务器(Erlang解决方案)</a></p>
</div>
<div style="width:425px" id="__ss_8721188"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mryufeng/erlang-8721188" title="高性能集群服务器(Erlang解决方案)" target="_blank">高性能集群服务器(Erlang解决方案)</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/8721188" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/mryufeng" target="_blank">Feng Yu</a> </div>
</p></div>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/1479/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Erlang低成本云计算</title>
		<link>http://blog.yufeng.info/archives/972</link>
		<comments>http://blog.yufeng.info/archives/972#comments</comments>
		<pubDate>Sat, 11 Dec 2010 10:12:56 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[clound]]></category>
		<category><![CDATA[computing]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=972</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: Erlang低成本云计算 Erlang low cost_clound_computing View more presentations from Feng Yu. Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/972">Erlang低成本云计算</a></p>
</div>
<div style="width:425px" id="__ss_6113105"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mryufeng/erlang-low-costcloundcomputing" title="Erlang low cost_clound_computing">Erlang low cost_clound_computing</a></strong><object id="__sse6113105" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=erlanglowcostcloundcomputing9-101211035752-phpapp01&#038;stripped_title=erlang-low-costcloundcomputing&#038;userName=mryufeng" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse6113105" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=erlanglowcostcloundcomputing9-101211035752-phpapp01&#038;stripped_title=erlang-low-costcloundcomputing&#038;userName=mryufeng" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/mryufeng">Feng Yu</a>.</div>
</div>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/972/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Latest News From the Erlang/OTP team at Ericsson 我有抱怨</title>
		<link>http://blog.yufeng.info/archives/871</link>
		<comments>http://blog.yufeng.info/archives/871#comments</comments>
		<pubDate>Fri, 19 Nov 2010 03:37:18 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[numa]]></category>
		<category><![CDATA[otp]]></category>
		<category><![CDATA[R14B01]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=871</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: Latest News From the Erlang/OTP team at Ericsson 我有抱怨 刚刚结束的Erlang factory会议， Kenneth Lundin按照规矩汇报了下Erlang下一阶段的工作： 请参考： Latest News From the Erlang/OTP team at Ericsson http://www.erlang-factory.com/upload/presentations/307/OTP_LATEST_NEWS_EUC10.pdf 这次的汇报很让人失望，除了回顾了下R14添加的读写锁的性能， 再有就是R14B01会支持ets的压缩，其他的都没有提到。 特别是上次承偌的numa和每调度器一个内存池的实现都没有提到。 随着硬件的发展，numa的问题越来越凸显。 我昨天测试的Dell 48核心/48G内存的机器，有8个numa node, 在一个进程用到很少内存的时候，系统开始swap, 但是实际上系统还有40G左右的内存。 而且在访问其他node的内存的时候，带宽从6G跌为4G，损失40%的性能。 期待otp团队给力！ Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/871">Latest News From the Erlang/OTP team at Ericsson 我有抱怨</a></p>
</div>
<p>刚刚结束的Erlang factory会议， Kenneth Lundin按照规矩汇报了下Erlang下一阶段的工作：</p>
<p>请参考： Latest News From the Erlang/OTP team at Ericsson<br />
<a href="http://www.erlang-factory.com/upload/presentations/307/OTP_LATEST_NEWS_EUC10.pdf">http://www.erlang-factory.com/upload/presentations/307/OTP_LATEST_NEWS_EUC10.pdf</a></p>
<p>这次的汇报很让人失望，除了回顾了下R14添加的读写锁的性能， 再有就是R14B01会支持ets的压缩，其他的都没有提到。 特别是上次承偌的numa和每调度器一个内存池的实现都没有提到。 </p>
<p>随着硬件的发展，numa的问题越来越凸显。 我昨天测试的Dell 48核心/48G内存的机器，有8个numa node, 在一个进程用到很少内存的时候，系统开始swap, 但是实际上系统还有40G左右的内存。 而且在访问其他node的内存的时候，带宽从6G跌为4G，损失40%的性能。</p>
<p>期待otp团队给力！</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/871/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tsung用于压测MySQL服务器的脚本</title>
		<link>http://blog.yufeng.info/archives/858</link>
		<comments>http://blog.yufeng.info/archives/858#comments</comments>
		<pubDate>Thu, 18 Nov 2010 12:31:38 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[工具介绍]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Tsung]]></category>
		<category><![CDATA[脚本]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=858</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: Tsung用于压测MySQL服务器的脚本 这个MySQL服务器压测的需求是 ： 环境: Linux RHEL 5U4 X86-64, 24G内存， 16核. MySQL服务器在xx.232.36.1上。 压力由最多32个客户端发起，每个客户端分别做update， insert, delete操作，概率分别是50%, 30%, 20%, 每种操作循环999999 × 100次，每100次操作后休息1-3秒。 这样的压力最多持续2个小时。 我们用的是著名的tsung压力测试工具， 之前我有篇blog介绍过， 见这里。 以下是用到的脚本， 用到了比较先进的随机动态参数替换等技术，对于编写此类脚本有很大的借鉴意义。 祝压测开心！ Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/858">Tsung用于压测MySQL服务器的脚本</a></p>
</div>
<p>这个MySQL服务器压测的需求是 ：</p>
<p>环境: Linux RHEL 5U4 X86-64,  24G内存， 16核.<br />
MySQL服务器在xx.232.36.1上。</p>
<p>压力由最多32个客户端发起，每个客户端分别做update， insert, delete操作，概率分别是50%, 30%,  20%, 每种操作循环999999 × 100次，每100次操作后休息1-3秒。<br />
这样的压力最多持续2个小时。</p>
<p>我们用的是著名的tsung压力测试工具， 之前我有篇blog介绍过， <a href="http://blog.yufeng.info/archives/605">见这里</a>。</p>
<p>以下是用到的脚本， 用到了比较先进的随机动态参数替换等技术，对于编写此类脚本有很大的借鉴意义。<br />
<span id="more-858"></span></p>
<pre class="brush: xml; title: ; notranslate">

&lt;!DOCTYPE tsung SYSTEM &quot;/usr/local/share/tsung/tsung-1.0.dtd&quot;&gt;
&lt;tsung loglevel=&quot;warning&quot; dumptraffic=&quot;false&quot;&gt;

  &lt;clients&gt;
    &lt;client host=&quot;localhost&quot; use_controller_vm=&quot;true&quot;/&gt;
  &lt;/clients&gt;

 &lt;servers&gt;
  &lt;server host=&quot;xx.232.36.1&quot; port=&quot;3306&quot; type=&quot;tcp&quot;/&gt;
 &lt;/servers&gt;

 &lt;load&gt;
  &lt;arrivalphase phase=&quot;1&quot; duration=&quot;2&quot; unit=&quot;hour&quot;&gt;
    &lt;users interarrival=&quot;0.1&quot; unit=&quot;second&quot; maxnumber=&quot;32&quot;&gt;&lt;/users&gt;
  &lt;/arrivalphase&gt;
 &lt;/load&gt;

 &lt;sessions&gt;
  &lt;session probability=&quot;50&quot; name=&quot;st-replace&quot; type=&quot;ts_mysql&quot;&gt;

      &lt;request&gt;
        &lt;mysql type=&quot;connect&quot; /&gt;
      &lt;/request&gt;
      &lt;request&gt;
        &lt;mysql type=&quot;authenticate&quot; database=&quot;test&quot; username=&quot;test&quot; password=&quot;mysqltest&quot; /&gt;
      &lt;/request&gt;  

      &lt;for from=&quot;1&quot; to=&quot;999999&quot; var=&quot;counter&quot;&gt;
        &lt;for from=&quot;1&quot; to=&quot;100&quot; var=&quot;counter&quot;&gt;
          &lt;setdynvars sourcetype=&quot;random_number&quot; start=&quot;1&quot; end=&quot;999999999&quot;&gt;
            &lt;var name=&quot;rnd_uid&quot; /&gt;
          &lt;/setdynvars&gt;
          &lt;setdynvars sourcetype=&quot;random_string&quot; length=&quot;13&quot;&gt;
            &lt;var name=&quot;rnd_uname&quot; /&gt;
          &lt;/setdynvars&gt;
          &lt;setdynvars sourcetype=&quot;random_number&quot; start=&quot;0&quot; end=&quot;1&quot;&gt;
            &lt;var name=&quot;rnd_male&quot; /&gt;
          &lt;/setdynvars&gt;
          &lt;setdynvars sourcetype=&quot;random_number&quot; start=&quot;1&quot; end=&quot;120&quot;&gt;
           &lt;var name=&quot;rnd_age&quot; /&gt;
         &lt;/setdynvars&gt;
         &lt;setdynvars sourcetype=&quot;random_string&quot; length=&quot;10&quot;&gt;
           &lt;var name=&quot;rnd_city&quot; /&gt;
         &lt;/setdynvars&gt;
         &lt;setdynvars sourcetype=&quot;random_string&quot; length=&quot;52&quot;&gt;
           &lt;var name=&quot;rnd_profile&quot; /&gt;
         &lt;/setdynvars&gt;
         &lt;request subst=&quot;true&quot;&gt;
           &lt;mysql type=&quot;sql&quot;&gt;replace into user(tid, uname, male, age, city, profile) values(%%_rnd_uid%%, &quot;%%_rnd_uname%%&quot;, %%_rnd_male%%, %%_rnd_age%%, &quot;%%_rnd_city%%&quot;, &quot;%%_rnd_profile%%&quot;) &lt;/mysql&gt;
         &lt;/request&gt;
        &lt;/for&gt;
        &lt;thinktime min=&quot;2&quot; max=&quot;5&quot; random=&quot;true&quot; /&gt;
      &lt;/for&gt;

      &lt;request&gt;
        &lt;mysql type=&quot;close&quot;&gt;&lt;/mysql&gt;
      &lt;/request&gt;
  &lt;/session&gt;

  &lt;session probability=&quot;20&quot; name=&quot;st-delete&quot; type=&quot;ts_mysql&quot;&gt;

      &lt;request&gt;
        &lt;mysql type=&quot;connect&quot; /&gt;
      &lt;/request&gt;
      &lt;request&gt;
        &lt;mysql type=&quot;authenticate&quot; database=&quot;test&quot; username=&quot;test&quot; password=&quot;mysqltest&quot; /&gt;
      &lt;/request&gt;  

      &lt;for from=&quot;1&quot; to=&quot;999999&quot; var=&quot;counter&quot;&gt;
        &lt;for from=&quot;1&quot; to=&quot;100&quot; var=&quot;counter&quot;&gt;
          &lt;setdynvars sourcetype=&quot;random_number&quot; start=&quot;1&quot; end=&quot;999999999&quot;&gt;
            &lt;var name=&quot;rnd_uid&quot; /&gt;
          &lt;/setdynvars&gt;
          &lt;request subst=&quot;true&quot;&gt;
            &lt;mysql type=&quot;sql&quot;&gt;delete from user where tid = %%_rnd_uid%% &lt;/mysql&gt;
          &lt;/request&gt;
        &lt;/for&gt;
        &lt;thinktime min=&quot;2&quot; max=&quot;5&quot; random=&quot;true&quot; /&gt;
      &lt;/for&gt;

      &lt;request&gt;
        &lt;mysql type=&quot;close&quot;&gt;&lt;/mysql&gt;
      &lt;/request&gt;
  &lt;/session&gt;

  &lt;session probability=&quot;30&quot; name=&quot;st-update&quot; type=&quot;ts_mysql&quot;&gt;

      &lt;request&gt;
        &lt;mysql type=&quot;connect&quot; /&gt;
      &lt;/request&gt;
      &lt;request&gt;
        &lt;mysql type=&quot;authenticate&quot; database=&quot;test&quot; username=&quot;test&quot; password=&quot;mysqltest&quot; /&gt;
      &lt;/request&gt;  

      &lt;for from=&quot;1&quot; to=&quot;999999&quot; var=&quot;counter&quot;&gt;
        &lt;for from=&quot;1&quot; to=&quot;100&quot; var=&quot;counter&quot;&gt;
          &lt;setdynvars sourcetype=&quot;random_number&quot; start=&quot;1&quot; end=&quot;999999999&quot;&gt;
            &lt;var name=&quot;rnd_uid&quot; /&gt;
          &lt;/setdynvars&gt;
         &lt;setdynvars sourcetype=&quot;random_string&quot; length=&quot;52&quot;&gt;
           &lt;var name=&quot;rnd_profile&quot; /&gt;
         &lt;/setdynvars&gt;

         &lt;request subst=&quot;true&quot;&gt;
           &lt;mysql type=&quot;sql&quot;&gt;update  user set profile = &quot;%%_rnd_profile%%&quot; where tid = %%_rnd_uid%% &lt;/mysql&gt;
         &lt;/request&gt;
        &lt;/for&gt;
        &lt;thinktime min=&quot;2&quot; max=&quot;5&quot; random=&quot;true&quot; /&gt;
      &lt;/for&gt;

      &lt;request&gt;
        &lt;mysql type=&quot;close&quot;&gt;&lt;/mysql&gt;
      &lt;/request&gt;
  &lt;/session&gt;

 &lt;/sessions&gt;
&lt;/tsung&gt;
</pre>
<p>祝压测开心！</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/858/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>如何在TILEPro64多核心板卡上编译和运行Erlang</title>
		<link>http://blog.yufeng.info/archives/791</link>
		<comments>http://blog.yufeng.info/archives/791#comments</comments>
		<pubDate>Tue, 02 Nov 2010 02:25:35 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[工具介绍]]></category>
		<category><![CDATA[64]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[otp]]></category>
		<category><![CDATA[Tilera]]></category>
		<category><![CDATA[并发，并行]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=791</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: 如何在TILEPro64多核心板卡上编译和运行Erlang 参考文章： 1. https://groups.google.com/group/erlang-programming/msg/2d61b1083a10a7b6 2. http://erlang.2086793.n4.nabble.com/How-to-Cross-compile-Erlang-OTP-R13B04-for-TileraPro64-td2119304.html 美国Tilera公司的众核服务器，单颗内核包含64颗CPU。硬件架构图： 卡长这样的： Erlang已经可以在这款CPU上成功运行，我们可以参考Ulf Wiger在Multicore ☺ Message-passing Concurrency 文档中关于Erlang在Tilera上的性能图. Erlang系统前2年就开始正式支持Tilera，一直用这个CPU来调整他的调度器，所以性能和基础的编译运行支持都很到位。 Linux内核2.6.36起就开始支持Tilera的CPU架构了，看起来前途不错。 最近 上海泛腾电子科技 开始在国内销售 Tilera机器， 我公司也得到一台样机，使得我有机会把玩下这个高科技！ 该测试机是PCI-e的形式，是单板机，直接安装在PC机或者是服务器里,好处是可以通过主机的VGA口接显示器直接调试。当然也可以作为智能网卡来使用。构成一个与Host的异构结构，通过PCI-e总线进行通讯。 还需要相应的配套SDK: 目前有TileraMDE-2.1.2.112814 和 TileraMDE-3.0.alpha3.116173 二个版本, 来负责和板卡的通信。 推荐用2.0的，好像不容易出问题。 废话少说，让我们开始享受64核心快乐旅程吧！ 好吧到此为止，我们在目标机器上/tmp/otp目录下有个完整的erlang系统。 我们开个console连接到板载的linux系统去： Bingo! 我们顺利的跑了数学计算，同时绑定调度器到CPU core上去了。接下来就可以按照平常那样进行Erlang并发编程了。 祝玩的开心！ Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/791">如何在TILEPro64多核心板卡上编译和运行Erlang</a></p>
</div>
<p>参考文章：<br />
1. <a href="https://groups.google.com/group/erlang-programming/msg/2d61b1083a10a7b6">https://groups.google.com/group/erlang-programming/msg/2d61b1083a10a7b6</a></p>
<p>2. <a href="http://erlang.2086793.n4.nabble.com/How-to-Cross-compile-Erlang-OTP-R13B04-for-TileraPro64-td2119304.html">http://erlang.2086793.n4.nabble.com/How-to-Cross-compile-Erlang-OTP-R13B04-for-TileraPro64-td2119304.html</a></p>
<p>美国Tilera公司的众核服务器，单颗内核包含64颗CPU。硬件架构图：<br />
<a href="http://blog.yufeng.info/wp-content/uploads/2010/11/Tile_Processor_Hardware_Architecture.jpg"><img src="http://blog.yufeng.info/wp-content/uploads/2010/11/Tile_Processor_Hardware_Architecture.jpg" alt="" title="Tile_Processor_Hardware_Architecture" width="792" height="439" class="alignnone size-full wp-image-806" /></a><br />
卡长这样的：<br />
<a href="http://blog.yufeng.info/wp-content/uploads/2010/11/tilera_board.jpg"><img src="http://blog.yufeng.info/wp-content/uploads/2010/11/tilera_board.jpg" alt="" title="tilera_board" width="208" height="148" class="alignnone size-full wp-image-820" /></a><br />
Erlang已经可以在这款CPU上成功运行，我们可以参考Ulf Wiger在Multicore ☺ Message-passing Concurrency 文档中关于Erlang在Tilera上的性能图.<br />
<a href="http://blog.yufeng.info/wp-content/uploads/2010/11/multi_core_message_passing_concurrency_erlang.jpg"><img src="http://blog.yufeng.info/wp-content/uploads/2010/11/multi_core_message_passing_concurrency_erlang.jpg" alt="" title="multi_core_message_passing_concurrency_erlang" width="627" height="405" class="alignnone size-full wp-image-798" /></a></p>
<p>Erlang系统前2年就开始正式支持Tilera，一直用这个CPU来调整他的调度器，所以性能和基础的编译运行支持都很到位。</p>
<p>Linux内核2.6.36起就开始支持Tilera的CPU架构了，看起来前途不错。</p>
<p>最近 上海泛腾电子科技 开始在国内销售 Tilera机器， 我公司也得到一台样机，使得我有机会把玩下这个高科技！</p>
<p>该测试机是PCI-e的形式，是单板机，直接安装在PC机或者是服务器里,好处是可以通过主机的VGA口接显示器直接调试。当然也可以作为智能网卡来使用。构成一个与Host的异构结构，通过PCI-e总线进行通讯。</p>
<p>还需要相应的配套SDK: 目前有TileraMDE-2.1.2.112814 和 TileraMDE-3.0.alpha3.116173 二个版本, 来负责和板卡的通信。 推荐用2.0的，好像不容易出问题。</p>
<p>废话少说，让我们开始享受64核心快乐旅程吧！<br />
<span id="more-791"></span></p>
<pre class="brush: bash; title: ; notranslate">
# wget http://www.erlang.org/download/otp_src_R13B03.tar.gz  %%R13B04后otp_build变了好像有点问题，编译不过去。
# tar xzf otp_src_R13B03.tar.gz
# cd otp_src_R13B03
%%由于R13B03有个小小的bug会导致segment fault,我们需要对erl_misc_utils.c打个patch,以下是要打patch的地方:
# diff -Nau otp_src_R13B04/erts/lib_src/common/erl_misc_utils.c{~,}
--- otp_src_R13B04/erts/lib_src/common/erl_misc_utils.c~
2009-11-20 14:32:23.000000000 +0100
+++ otp_src_R13B04/erts/lib_src/common/erl_misc_utils.c 2010-03-29
15:53:28.000000000 +0200
@@ -373,8 +373,8 @@
        return 0;
     memcpy((void *) topology,
           (void *) cpuinfo-&gt;topology,
-          cpuinfo-&gt;configured*sizeof(erts_cpu_topology_t));
-    return cpuinfo-&gt;configured;
+          cpuinfo-&gt;topology_size*sizeof(erts_cpu_topology_t));
+    return cpuinfo-&gt;topology_size;
 }
%%源码算是准备完毕了 

%%开始编译前的环境准备
# export ERL_TOP=`pwd`
# eval `./otp_build env_cross $ERL_TOP/xcomp/erl-xcomp-TileraMDE2.0-tilepro.conf`
# export TILERA_ROOT=/root/TileraMDE-2.1.2.112814/tilepro/  %%这个最好用2.x版本的
# export PATH=$TILERA_ROOT/bin:$PATH
# tile-monitor --pci -- uname -a  %%验证板卡确实可用
Linux localhost 2.6.26.7-MDE-2.1.2.112814 #1 SMP Wed Sep 1 00:05:06 EDT 2010 tile GNU/Linux

%%开始交叉编译
# ./otp_build configure
# touch lib/crypto/SKIP &amp;&amp;  touch lib/ssl/SKIP &amp;&amp; touch lib/ssh/SKIP   %%这几个模块用到了openssl, 编译不过去，忽略掉
# ./otp_build boot -a
# ./otp_build release -a /tmp/otp %%安装到/tmp/otp目录去

%%如果一切顺利，到这时候就编译完毕了。

%%我们开始收获成果。

# cd /tmp/otp
# ./Install `pwd`
#  tile-monitor --pci --here -- bin/erl  %%没出错的话，就说明我们成功了。

%%当然我们可以把otp系统上载到板卡去，方便日后使用
# $TILERA_ROOT/bin/tile-monitor --pci  --upload /tmp/otp /tmp/otp --quit   %% 放在板卡的/tmp/otp目录下

%%我们还可以定义个命令别名，方便我们执行命令
# tile_erl=&quot;$TILERA_ROOT/bin/tile-monitor --pci --resume --tunnel 2023 23  --env HOME=/tmp  --tiles - all ^0 - -- /tmp/otp/bin/erl&quot;
# $tile_erl +sct L10-18,1-9,19-55,57,58,61c1-55,57,58,61 +sbt db   -noshell +S 58 -s init stop
</pre>
<p>好吧到此为止，我们在目标机器上/tmp/otp目录下有个完整的erlang系统。</p>
<p>我们开个console连接到板载的linux系统去：</p>
<pre class="brush: bash; title: ; notranslate">
[root@client otp_src_R13B03]# /root/TileraMDE-2.1.2.112814/tilepro/bin/tile-console
tile-console: Assuming '--pci'.
Connecting to /dev/ttyS0, speed 115200
 Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------
# uname -a
Linux localhost 2.6.26.7-MDE-2.1.2.112814 #1 SMP Wed Sep 1 00:05:06 EDT 2010 tile GNU/Linux

# cd /tmp/otp
%%我们跑个erlang程序&lt;em&gt;64核心并行&lt;/em&gt;进行数学计算
%% 代码在这里下载 http://shootout.alioth.debian.org/u32/program.php?test=spectralnorm&amp;lang=hipe&amp;id=2
#cat &gt; spectralnorm.erl
%   The Computer Language Benchmarks Game
%   http://shootout.alioth.debian.org/
%   contributed by Fredrik Svahn

-module(spectralnorm).
-export([main/1]).
-compile( [ inline, { inline_size, 1000 } ] ).

main([Arg]) -&gt;
    register(server, self()),
    N = list_to_integer(Arg),
    {U, V} = power_method(N, 10, erlang:make_tuple(N, 1), []),
    io:format(&quot;~.9f\n&quot;, [ eigen(N, U, V, 0, 0) ]),
    erlang:halt(0).

% eigenvalue of V
eigen(0, _, _, VBV, VV) when VV /= 0 -&gt; math:sqrt(VBV / VV);

eigen(I, U, V, VBV, VV) when I /= 0 -&gt;
    VI = element(I, V),
    eigen(I-1, U, V, VBV + element(I, U)*VI, VV + VI*VI).

% 2I steps of the power method
power_method(_, 0, A, B) -&gt; {A, B};
power_method(N, I, A, _B) -&gt;
    V = atav(N, A),
    U = atav(N, V),
    power_method(N, I-1, U, V).

% return element i,j of infinite matrix A
a(II,JJ) -&gt; 1/((II+JJ-2)*(II-1+JJ)/2+II).

% multiply vector v by matrix A
av(N, V) -&gt; pmap(N, fun(Begin, End) -&gt; av(N, Begin, End, V) end).

av(N, Begin, End, V) -&gt; server ! { self(), [ avloop(N, I, V, 0.0) || I &lt;- lists:seq(Begin, End) ]}.

avloop(0, _, _, X) -&gt;  X;
avloop(J, I, V, X) -&gt;  avloop(J-1, I, V, X + a(I, J)*element(J, V) ).

% multiply vector v by matrix A transposed
atv(N, V) -&gt; pmap(N, fun(Begin, End)-&gt; atv(N, Begin, End, V) end).

atv(N, Begin, End, V) -&gt; server ! { self(), [ atvloop(N, I, V, 0.0) || I &lt;- lists:seq(Begin, End) ]}.

atvloop(0, _, _, X) -&gt; X;
atvloop(J, I, V, X) -&gt; atvloop(J-1, I, V, X + a(J, I)*element(J, V) ).

% multiply vector v by matrix A and then by matrix A transposed
atav(N, V) -&gt; atv(N, av(N, V)).

%Helper function for multicore
pmap(N, F) -&gt;
    Chunks = chunks(0, erlang:system_info(logical_processors), N, []),
    Pids = [spawn(fun()-&gt; F(Begin, End) end) || {Begin, End} &lt;- Chunks],
    Res = [ receive {Pid, X} -&gt; X end || Pid &lt;- Pids],
    list_to_tuple(lists:flatten(Res)).

chunks(I, P, N, A) when I == P-1 -&gt; lists:reverse([{I*(N div P)+1, N} | A ]);
chunks(I, P, N, A) -&gt; chunks(I+1, P, N, [{ I*(N div P)+1, (I+1)*(N div P)} | A ]).

CTRL+D

# bin/erlc spectralnorm.erl
# time bin/erl -noshell -run spectralnorm  main 500  -s init stop
1.274224116
real    0m 16.90s
user    1m 16.07s
sys     0m 0.79s
# bin/erl  +sct L10-18,1-9,19-55,57,58,61c1-55,57,58,61 +sbt db   -noshell +S 58 -eval 'io:format(&quot;schedulers: ~p~n&quot;1)' -s init stop
schedulers: 58
</pre>
<p>Bingo! 我们顺利的跑了数学计算，同时绑定调度器到CPU core上去了。接下来就可以按照平常那样进行Erlang并发编程了。</p>
<p>祝玩的开心！</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/791/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>ECUG2010分享：C1000K高性能服务器构架技术</title>
		<link>http://blog.yufeng.info/archives/776</link>
		<comments>http://blog.yufeng.info/archives/776#comments</comments>
		<pubDate>Mon, 18 Oct 2010 08:37:41 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[bonding]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[Erts]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[numa]]></category>
		<category><![CDATA[os]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=776</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: ECUG2010分享：C1000K高性能服务器构架技术 C1000K高性能服务器构建技术 View more presentations from Feng Yu. 点击这里下载 ppt 视频这里 照片这里 这次ECUG2010的讲师来自不同的国家，有点国际化的味道，也说明了这个世界越来越扁平，技术越越来越同步，我们追随技术的压力也越来越大。 Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/776">ECUG2010分享：C1000K高性能服务器构架技术</a></p>
</div>
<div style="width:425px" id="__ss_5449105"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mryufeng/c1000k" title="C1000K高性能服务器构建技术">C1000K高性能服务器构建技术</a></strong><object id="__sse5449105" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=c1000k-12871244425597-phpapp01&#038;stripped_title=c1000k&#038;userName=mryufeng" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse5449105" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=c1000k-12871244425597-phpapp01&#038;stripped_title=c1000k&#038;userName=mryufeng" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/mryufeng">Feng Yu</a>.</div>
</div>
<p><span id="more-776"></span><br />
点击<a href="http://blog.yufeng.info/C1000K.ppt">这里</a>下载 ppt<br />
<a href="http://v.ku6.com/special/show_3859073/k1k1Zhmm_ZfpxEYn.html">视频这里</a><br />
<a href="http://xushiwei.com/ecug-con-2010-photo">照片这里</a></p>
<p>这次ECUG2010的讲师来自不同的国家，有点国际化的味道，也说明了这个世界越来越扁平，技术越越来越同步，我们追随技术的压力也越来越大。</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/776/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ProcessOne releases OneCached 很好的学习Erlang的材料</title>
		<link>http://blog.yufeng.info/archives/638</link>
		<comments>http://blog.yufeng.info/archives/638#comments</comments>
		<pubDate>Tue, 27 Jul 2010 09:26:56 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[onecached]]></category>
		<category><![CDATA[学习]]></category>
		<category><![CDATA[项目]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=638</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: ProcessOne releases OneCached 很好的学习Erlang的材料 July 05, 2010 ProcessOne has just released OneCached, a Memcached server and client implementation written in Erlang. OneCached is released under the Erlang Public License (EPL),. OneCached supports the set, add, replace, get, incr, decr, delete, flush_all and quit commands. It doesn&#8217;t handle expiration time. You call pull [...]]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/638">ProcessOne releases OneCached 很好的学习Erlang的材料</a></p>
</div>
<p>July 05, 2010<br />
ProcessOne has just released OneCached, a Memcached server and client implementation written in Erlang.<br />
OneCached is released under the Erlang Public License (EPL),.</p>
<p>OneCached supports the set, add, replace, get, incr, decr, delete, flush_all and quit commands. It doesn&#8217;t handle expiration time.</p>
<p>You call pull the source code from the public repository at:<a href=" https://git.process-one.net/onecached"> https://git.process-one.net/onecached</a></p>
<p>git clone git://git.process-one.net/onecached/mainline.git</p>
<p>To compile, just run make, and to start, just type:<br />
bin/onecachedctl start</p>
<p>这个项目是非常简单的一个memcached的模仿， 亮点在于底层用ets, dest, mnesia这样的erlang特有的存储。这个项目的意义在于演示了如何编写一个严肃的Erlang工程，以及需要掌握的技能。对于初学者来讲，这是很好的一个切入点。 你可以在上面修修改改， 打造出你自己的版本。</p>
<p>玩的开心！</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/638/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tsung压力测试工具介绍PPT</title>
		<link>http://blog.yufeng.info/archives/605</link>
		<comments>http://blog.yufeng.info/archives/605#comments</comments>
		<pubDate>Wed, 14 Jul 2010 08:48:29 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[Loadrunner]]></category>
		<category><![CDATA[Tsung]]></category>
		<category><![CDATA[压力测试工具]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=605</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: Tsung压力测试工具介绍PPT 准备为测试部门的同学作个Tsung的讲座, 点击下载Tsung 需要进一步了解Tsung的同学 点这里看官方的文档! 想了解如何使用的还可以到Erlang china这里看看! Tsung 压力测试工具 View more presentations from Feng Yu. Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/605">Tsung压力测试工具介绍PPT</a></p>
</div>
<p>准备为测试部门的同学作个Tsung的讲座, <a href='http://blog.yufeng.info/wp-content/uploads/2010/07/Tsung_.pdf'>点击下载Tsung</a></p>
<p>需要进一步了解Tsung的同学 <a href="http://tsung.erlang-projects.org/user_manual.html">点这里</a>看官方的文档!<br />
想了解如何使用的还可以到<a href="http://erlang-china.org/study/tsung_your_web.html">Erlang china这里</a>看看!</p>
<div style="width:425px" id="__ss_4751310"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/mryufeng/tsung" title="Tsung 压力测试工具">Tsung 压力测试工具</a></strong><object id="__sse4751310" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=tsung-100714041332-phpapp02&#038;stripped_title=tsung&#038;userName=mryufeng" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse4751310" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=tsung-100714041332-phpapp02&#038;stripped_title=tsung&#038;userName=mryufeng" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/mryufeng">Feng Yu</a>.</div>
</div>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/605/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Inside Erlang VM(你需要知道的VM原理)</title>
		<link>http://blog.yufeng.info/archives/543</link>
		<comments>http://blog.yufeng.info/archives/543#comments</comments>
		<pubDate>Mon, 26 Apr 2010 07:51:19 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[inside]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=543</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: Inside Erlang VM(你需要知道的VM原理) 公司培训用的文档, 对于Erlang的VM会有个大体的认识, 方便设计和使用Erlang. 点解下载pdf格式的文档 Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/543">Inside Erlang VM(你需要知道的VM原理)</a></p>
</div>
<p>公司培训用的文档, 对于Erlang的VM会有个大体的认识, 方便设计和使用Erlang.<br />
<a href='http://blog.yufeng.info/wp-content/uploads/2010/04/Inside_Erlang_VM3.pdf'>点解下载pdf格式的文档</a>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/543/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Erlang源码汇编格式</title>
		<link>http://blog.yufeng.info/archives/498</link>
		<comments>http://blog.yufeng.info/archives/498#comments</comments>
		<pubDate>Fri, 16 Apr 2010 02:40:40 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA['s']]></category>
		<category><![CDATA[erlc]]></category>
		<category><![CDATA[erts_dbug:df]]></category>
		<category><![CDATA[opcode]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=498</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: Erlang源码汇编格式 我们在编码的时候, 通常会好奇, 这时候需要观察erl源码生成的VM opcode. Erlang的VM是register based的VM, 生产的opcode很容易理解. 生成汇编格式有2种方式: 1. 从源码生成抽象码. erlc +&#8221;&#8216;S&#8217;&#8221; mod.erl, 生成mod.S 2. 从beam生成Opcode. 未公开的功能. erts_debug:df 参数M或者 M, F, 生成mod.dis 来吧,实践下: 我们得到了eg.S, eg.dis这2个反汇编的结果. 我们再来参观下. 先看源码: root@ubuntu:~/exam# cat eg.erl 中间汇编码, 供transform进行处理和编译器进一步生成opcode. root@ubuntu:~/exam# cat eg.S VM opcode形式, VM就是来解释运行这些code的 收工! Post Footer automatically generated by wp-posturl plugin for wordpress.]]></description>
			<content:encoded><![CDATA[<div style="margin-top: 15px; font-style: italic">
<p><strong>原创文章，转载请注明：</strong> 转载自<a href="http://blog.yufeng.info/">Erlang非业余研究</a></p>
<p><strong>本文链接地址:</strong> <a href="http://blog.yufeng.info/archives/498">Erlang源码汇编格式</a></p>
</div>
<p>我们在编码的时候, 通常会好奇, 这时候需要观察erl源码生成的VM opcode.  Erlang的VM是register based的VM, 生产的opcode很容易理解.<br />
生成汇编格式有2种方式:<br />
1. 从源码生成抽象码. erlc +&#8221;&#8216;S&#8217;&#8221; mod.erl, 生成mod.S<br />
2. 从beam生成Opcode. 未公开的功能. erts_debug:df   参数M或者 M, F, 生成mod.dis</p>
<p>来吧,实践下:</p>
<pre class="brush: bash; title: ; notranslate">
root@ubuntu:~/exam# ls
eg.erl
root@ubuntu:~/exam# erlc +&quot;'S'&quot; eg.erl
root@ubuntu:~/exam# erlc eg.erl
root@ubuntu:~/exam# erl
Erlang R14A (erts-5.8) 1 [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false] [lock-counting]

Eshell V5.8  (abort with ^G)
1&gt;  erts_debug:df(eg).
ok
2&gt;
User switch command
 --&gt; q
root@ubuntu:~/exam# ls eg*
eg.beam  eg.dis  eg.erl  eg.S
</pre>
<p>我们得到了eg.S, eg.dis这2个反汇编的结果. 我们再来参观下.<br />
先看源码:<br />
root@ubuntu:~/exam# cat eg.erl</p>
<pre class="brush: erlang; title: ; notranslate">
-module(eg).
-import(lists).
-import(lists,[sum/1]).
-compile(export_all).

kilo_byte() -&gt;
    kilo_byte(10, [42]).
kilo_byte(0, Acc) -&gt;
    Acc;
kilo_byte(N, Acc) -&gt;
    kilo_byte(N-1, [Acc|Acc]).

loop()-&gt;
    sum(lists:seq(1,100)),
    loop().
</pre>
<p>中间汇编码, 供transform进行处理和编译器进一步生成opcode.<br />
root@ubuntu:~/exam# cat eg.S</p>
<pre class="brush: erlang; title: ; notranslate">
{module, eg}.  %% version = 0

{exports, [{kilo_byte,0},
           {kilo_byte,2},
           {loop,0},
           {module_info,0},
           {module_info,1}]}.

{attributes, []}.

{labels, 12}.

{function, kilo_byte, 0, 2}.
  {label,1}.
    {func_info,{atom,eg},{atom,kilo_byte},0}.
  {label,2}.
    {move,{literal,&quot;*&quot;},{x,1}}.
    {move,{integer,10},{x,0}}.
    {call_only,2,{f,4}}.

{function, kilo_byte, 2, 4}.
  {label,3}.
    {func_info,{atom,eg},{atom,kilo_byte},2}.
  {label,4}.
    {test,is_eq_exact,{f,5},[{x,0},{integer,0}]}.
    {move,{x,1},{x,0}}.
    return.
  {label,5}.
    {gc_bif,'-',{f,0},2,[{x,0},{integer,1}],{x,0}}.
    {test_heap,2,2}.
    {put_list,{x,1},{x,1},{x,1}}.
    {call_only,2,{f,4}}.

{function, loop, 0, 7}.
  {label,6}.
    {func_info,{atom,eg},{atom,loop},0}.
  {label,7}.
    {allocate,0,0}.
    {move,{integer,100},{x,1}}.
    {move,{integer,1},{x,0}}.
    {call_ext,2,{extfunc,lists,seq,2}}.
    {call_ext,1,{extfunc,lists,sum,1}}.
    {call_last,0,{f,7},0}.

{function, module_info, 0, 9}.
  {label,8}.
    {func_info,{atom,eg},{atom,module_info},0}.
  {label,9}.
    {move,{atom,eg},{x,0}}.
    {call_ext_only,1,{extfunc,erlang,get_module_info,1}}.

{function, module_info, 1, 11}.
  {label,10}.
    {func_info,{atom,eg},{atom,module_info},1}.
  {label,11}.
    {move,{x,0},{x,1}}.
    {move,{atom,eg},{x,0}}.
    {call_ext_only,2,{extfunc,erlang,get_module_info,2}}.
</pre>
<p>VM opcode形式, VM就是来解释运行这些code的</p>
<pre class="brush: bash; title: ; notranslate">
root@ubuntu:~/exam# cat eg.dis
B5146074: i_func_info_IaaI 0 eg kilo_byte 0
B5146088: move_cx &quot;*&quot; x(1)
B5146094: i_move_call_only_fcr eg:kilo_byte/2 10 x(0) 

B51460A0: i_func_info_IaaI 0 eg kilo_byte 2
B51460B4: i_is_eq_immed_frc f(B51460C8) x(0) 0
B51460C0: move_return_xr x(1) x(0)
B51460C8: i_fetch_rc x(0) 1
B51460D0: i_minus_jId j(00000000) 2 x(0)
B51460E0: test_heap_II 2 2
B51460EC: put_list_xxx x(1) x(1) x(1)
B51460F4: i_call_only_f eg:kilo_byte/2 

B51460FC: i_func_info_IaaI 0 eg loop 0
B5146110: allocate_tt 0 0
B5146118: move_cx 100 x(1)
B5146124: i_move_call_ext_cre 1 x(0) lists:seq/2
B5146130: i_call_ext_e lists:sum/1
B5146138: i_call_last_fP eg:loop/0 0 

B5146144: i_func_info_IaaI 0 eg module_info 0
B5146158: move_cr eg x(0)
B5146160: allocate_tt 0 1
B5146168: call_bif1_e erlang:get_module_info/1
B5146170: deallocate_return_P 0 

B5146178: i_func_info_IaaI 0 eg module_info 1
B514618C: move_rx x(0) x(1)
B5146194: move_cr eg x(0)
B514619C: allocate_tt 0 2
B51461A4: call_bif2_e erlang:get_module_info/2
B51461AC: deallocate_return_P 0
</pre>
<p>收工!</p>
<div style="margin-top: 0; margin-bottom: 15px; color: #888888; font-size: 80%; font-style: italic">
<p>Post Footer automatically generated by <a href="http://easwy.com/blog/wordpress/wp-posturl/" style="color: #8888FF; text-decoration: underline;">wp-posturl plugin</a> for wordpress.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.yufeng.info/archives/498/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

