Archive

Archive for March, 2010

lcnt 环境搭建

March 24th, 2010 No comments

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

本文链接地址: lcnt 环境搭建

抄书:otp_doc_html_R13B04/lib/tools-2.6.5.1/doc/html /lcnt_chapter.html#id2252207

lcnt – The Lock Profiler

Internally in the Erlang runtime system locks are used to protect resources from being updated from multiple threads in a fatal way. Locks are necessary to ensure that the runtime system works properly but it also introduces a couple of limitations. Lock contention and locking overhead.

With lock contention we mean when one thread locks a resource and another thread, or threads, tries to acquire the same resource at the same time. The lock will deny the other thread access to the resource and the thread will be blocked from continuing its execution. The second thread has to wait until the first thread has completed its access to the resource and unlocked it. The lcnt tool measures these lock conflicts.

Locks has an inherent cost in execution time and memory space. It takes time initialize, destroy, aquiring or releasing locks. To decrease lock contention it some times necessary to use finer grained locking strategies. This will usually also increase the locking overhead and hence there is a tradeoff between lock contention and overhead. In general, lock contention increases with the number of threads running concurrently. The lcnt tool does not measure locking overhead.

5.1 Enabling lock-counting

For investigation of locks in the emulator we use an internal tool called lcnt (short for lock-count). The VM needs to be compiled with this option enabled. To enable this, use:

cd $ERL_TOP
./configure --enable-lock-counter

Another way to enable this alongside a normal VM is to compile it at emulator directory level, much like a debug build. To compile it this way do the following,

cd $ERL_TOP/erts/emulator
make lcnt FLAVOR=smp

and then starting Erlang with,

$ERL_TOP/bin/cerl -lcnt

To verify that you lock-counting enabled check that [lock-counting] appears in the status text when the VM is started.

Erlang R13B03 (erts-5.7.4) [64-bit] [smp:8:8] [rq:8] [async-threads:0] [hipe]
[kernel-poll:false] [lock-counting]


5.2 Getting started

Once you have a lock counting enabled VM the module lcnt can be used. The module is intended to be used from the current running nodes shell. To access remote nodes use lcnt:clear(Node) and lcnt:collect(Node).

All locks are continuously monitored and its statistics updated. Use lcnt:clear/0 to initially clear all counters before running any specific tests. This command will also reset the duration timer internally.

To retrieve lock statistics information use, lcnt:collect/0,1. The collect operation will start a lcnt server if it not already started. All collected data will be built into an erlang term and uploaded to the server and a duration time will also be uploaded. This duration is the time between lcnt:clear/0,1 and lcnt:collect/0,1.

Once the data is collected to the server it can be filtered, sorted and printed in many different ways.

See the reference manual for a description of each function.

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

Categories: Erlang探索 Tags: ,

Erlang ERTS Async基础设施

March 24th, 2010 No comments

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

本文链接地址: Erlang ERTS Async基础设施

其实Erts的Async做的很不错的, 相当的完备, 性能又高. 但是奇怪的是只有文件driver才真正利用到了这个优势. 难道是OTP团队的人,不想为了性能把事情搞的复杂了. Driver和最近加入的NIF都提供了大量的线程,锁,同步的原语来支持最大的程度的利用单线程的优势. 俺会做小白鼠来参试这些被遗忘的设施.

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

Categories: Erlang探索 Tags: , ,

erlsnoop erlang消息监听器(调试erlang网络程序利器,支持最新的R13B04)

March 18th, 2010 No comments

由于R13B以后, Erlang的分布协议修改了格式, 添加了Atom Cache, erlsnoop在新版本下无法使用, 我特地打了patch, 使得它支持最新的版本,源码在附件中下载.

在erlang的邮件列表上看到:
Have you tried putting a snoop to see whether the delay is on the
sending/receiving side?

This might be useful: http://www.erlang.org/contrib/erlsnoop-1.0.tgz

http://www.erlang.org/contrib/看了下 模块真不少 下载了erl_snoop

先安装lib-pcap

# yum install libpcap-devel
# yum install libpcap

但是编译出错:
ip.c:77: error: label at end of compound statement
随便在default: 后面加个return 0;

utils.c: In function ‘gmt2local’:
utils.c:26: error: storage size of ‘sgmt’ isn’t known
utils.c:28: warning: implicit declaration of function ‘time’
utils.c:31: error: dereferencing pointer to incomplete type
utils.c:31: warning: implicit declaration of function ‘gmtime’
utils.c:31: error: invalid type argument of ‘unary *’
utils.c:32: warning: implicit declaration of function ‘localtime’
utils.c:32: warning: assignment makes pointer from integer without a cast
utils.c:34: error: dereferencing pointer to incomplete type
utils.c:34: error: dereferencing pointer to incomplete type
utils.c:35: error: dereferencing pointer to incomplete type
utils.c:35: error: dereferencing pointer to incomplete type
utils.c:42: error: dereferencing pointer to incomplete type
utils.c:42: error: dereferencing pointer to incomplete type
utils.c:43: error: dereferencing pointer to incomplete type
utils.c:43: error: dereferencing pointer to incomplete type
utils.c:26: warning: unused variable ‘sgmt’
make: *** [utils.o] Error 1

加个 #include

搞定 运行

[root@test98 erlsnoop-1.0]# ./erlsnoop -hpnkt
Erlsnoop 1.0 (Mar  4 2008)
using interface eth0 (mtu=1500)
using filter "tcp"
option -? gets help
type ^C to quit

[ 192.168.0.98:44683 (x@192.168.0.98) > 192.168.0.243:30141 (y@192.168.0.243) ] 160
  REG_SEND from: #Pid<x@192.168.0.98.11.0.2> to: global_name_server

[ 192.168.0.98:44683 (x@192.168.0.98) > 192.168.0.243:30141 (y@192.168.0.243) ] 49
  MONITOR from: #Pid<x@192.168.0.98.36.0.2> to: net_kernel
   ref: #Ref<x@192.168.0.98.46.0.0.2>

[ 192.168.0.243:30141 (y@192.168.0.243) > 192.168.0.98:44683 (x@192.168.0.98) ] 161
  REG_SEND from: #Pid<y@192.168.0.243.11.0.2> to: global_name_server

[ 192.168.0.98:44683 (x@192.168.0.98) > 192.168.0.243:30141 (y@192.168.0.243) ] 84
  REG_SEND from: #Pid<x@192.168.0.98.36.0.2> to: net_kernel

效果不错的哦。可以看到erlang的交互信息, 相信的请看README.txt

下载erlsnoop-1.1

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

Categories: Erlang探索 Tags: , ,