<?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; system</title>
	<atom:link href="http://blog.yufeng.info/archives/tag/system/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/18</link>
		<comments>http://blog.yufeng.info/archives/18#comments</comments>
		<pubDate>Wed, 26 Aug 2009 05:59:18 +0000</pubDate>
		<dc:creator>Yu Feng</dc:creator>
				<category><![CDATA[Erlang探索]]></category>
		<category><![CDATA[call]]></category>
		<category><![CDATA[erl]]></category>
		<category><![CDATA[os]]></category>
		<category><![CDATA[system]]></category>

		<guid isPermaLink="false">http://blog.yufeng.info/?p=18</guid>
		<description><![CDATA[原创文章，转载请注明： 转载自Erlang非业余研究 本文链接地址: erlang到底能够并发发起多少系统调用 为了测试下erlang的多smp能够每秒并发发起多少系统调用，这个关系到erlang作为网络程序在高并发下的评估。 首先crack下otp_src,因为erlang:now() 是调用了clock_gettime这个系统调用，但是遗憾的是这个now里面设计到很多mutex会导致不可预期的futex调用，所以需要做如下修改， 调用最廉价的getuid系统调用： 重新make下otp_src 对其中一个调度器线程的trace 调用序列是非常的合理的 机器配置是： 8个核心。 1分钟 erlang发起了getuid()系统调个数 ecug的8核心机器 222，100，000 × 8个核心 = 1700M 合每秒30M个系统调用 结论是：如果合理安排的话 erlang的性能是非常高的 同时可以利用到erlang的smp的巨大优势。 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/18">erlang到底能够并发发起多少系统调用</a></p>
</div>
<p>为了测试下erlang的多smp能够每秒并发发起多少系统调用，这个关系到erlang作为网络程序在高并发下的评估。</p>
<p>首先crack下otp_src,因为erlang:now() 是调用了clock_gettime这个系统调用，但是遗憾的是这个now里面设计到很多mutex会导致不可预期的futex调用，所以需要做如下修改，<br />
调用最廉价的getuid系统调用：</p>
<pre class="brush: bash; title: ; notranslate">
root@ubuntu:~# emacs otp_src_R13B/erts/emulator/beam/erl_bif_info.c
</pre>
<pre class="brush: cpp; title: ; notranslate">
BIF_RETTYPE statistics_1(BIF_ALIST_1)
{
Eterm res;
Eterm* hp;

if (BIF_ARG_1 == am_context_switches) {
Eterm cs = erts_make_integer(erts_get_total_context_switches(), BIF_P);
hp = HAlloc(BIF_P, 3);
res = TUPLE2(hp, cs, SMALL_ZERO);
BIF_RET(res);
&lt;span style=&quot;color: red;&quot;&gt; } else if (BIF_ARG_1 == am_ok) { /* Line 2713 */
getuid();
BIF_RET( am_ok);
&lt;/span&gt; } else if (BIF_ARG_1 == am_garbage_collection) {
...
}
</pre>
<p>重新make下otp_src</p>
<pre class="brush: bash; title: ; notranslate">
[root@localhost ~]# cat tsmp.erl
</pre>
<pre class="brush: erlang; title: ; notranslate">
-module(tsmp).
-export([start/1]).

loop(I, N)-&gt;;
%%   erlang:now(),
%%   os:timestamp(),
erlang:statistics(ok), %% call getuid

case N rem 100000 of
0 -&gt;;
io:format(&quot;#~p:~p~n&quot;, [I, N]);
_-&gt;;
skip
end,

loop(I, N + 1).

start([X])-&gt;;
N = list_to_integer(atom_to_list(X)),
[spawn_opt(fun () -&gt; loop(I, 0) end, [{scheduler, I}]) || I &lt;-lists:seq(1, N)],
receive
stop -&gt;;
ok
after 60000 -&gt;;
ok
end,
init:stop().
</pre>
<pre class="brush: bash; title: ; notranslate">
#otp_src_R13B02/bin/erl  -sct db  -s tsmp start 8
。。。
#7:226500000
#1:228000000
#8:152600000
#5:150200000
#4:225600000
#3:222000000
#2:224000000
#6:226400000
#7:226600000
#1:228100000
#4:225700000
#8:152700000
#3:222100000
</pre>
<p>对其中一个调度器线程的trace</p>
<pre class="brush: bash; title: ; notranslate">
[root@wes263 ~]#  /usr/bin/strace  -c -p 4667
Process 4667 attached - interrupt to quit
PANIC: attached pid 4667 exited with 0
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
99.87    0.230051           0   3979319           getuid
0.08    0.000189           0      1924           poll
0.05    0.000116           0      1924           clock_gettime
0.00    0.000000           0       147        48 futex
------ ----------- ----------- --------- --------- ----------------
100.00    0.230356               3983314        48 total
</pre>
<p>调用序列是非常的合理的</p>
<p>机器配置是：</p>
<pre class="brush: bash; title: ; notranslate">
[yufeng@wes263 ~]$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5450  @ 3.00GHz
stepping        : 10
cpu MHz         : 1998.000
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips        : 5988.98
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:
</pre>
<p>8个核心。</p>
<p>1分钟 erlang发起了getuid()系统调个数 ecug的8核心机器 222，100，000 × 8个核心 = 1700M 合每秒30M个系统调用</p>
<p>结论是：如果合理安排的话 erlang的性能是非常高的 同时可以利用到erlang的smp的巨大优势。
<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/18/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

