Archive

Posts Tagged ‘os’

ECUG2010分享:C1000K高性能服务器构架技术

October 18th, 2010 3 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: ECUG2010分享:C1000K高性能服务器构架技术

Read more…

Post Footer automatically generated by wp-posturl plugin for wordpress.

erlang到底能够并发发起多少系统调用

August 25th, 2009 5 comments

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: erlang到底能够并发发起多少系统调用

为了测试下erlang的多smp能够每秒并发发起多少系统调用,这个关系到erlang作为网络程序在高并发下的评估。

首先crack下otp_src,因为erlang:now() 是调用了clock_gettime这个系统调用,但是遗憾的是这个now里面设计到很多mutex会导致不可预期的futex调用,所以需要做如下修改,
调用最廉价的getuid系统调用:

root@ubuntu:~# emacs otp_src_R13B/erts/emulator/beam/erl_bif_info.c
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);
<span style="color: red;"> } else if (BIF_ARG_1 == am_ok) { /* Line 2713 */
getuid();
BIF_RET( am_ok);
</span> } else if (BIF_ARG_1 == am_garbage_collection) {
...
}

重新make下otp_src

[root@localhost ~]# cat tsmp.erl
-module(tsmp).
-export([start/1]).

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

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

loop(I, N + 1).

start([X])->;
N = list_to_integer(atom_to_list(X)),
[spawn_opt(fun () -> loop(I, 0) end, [{scheduler, I}]) || I <-lists:seq(1, N)],
receive
stop ->;
ok
after 60000 ->;
ok
end,
init:stop().
#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

对其中一个调度器线程的trace

[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

调用序列是非常的合理的

机器配置是:

[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:

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.

Categories: Erlang探索 Tags: , , ,