Author Archives: azunyanmoe

Implementation of the Erlang Timer Module

The timer module provides useful functions related to time. For example: send_after: send a message to a process after some time send_interval: send a message to a process repeatedly after some time cancel: cancels a previously requested timeout sleep: suspend … Continue reading

Posted in erlang | Tagged | Leave a comment

The erlangrc file

There could be an erlang resource file named as “.erlang” in your working directory or home directory. This file is loaded and evaled when erlang is started. So you can do some initialization in this file. Let’s look into start_clean.script … Continue reading

Posted in erlang | Tagged | Leave a comment

How to get parent of an erlang process

The erlang application monitor, i.e. appmon, could build a process tree for an erlang application. To build such a tree, we need to find out all processes that belong to the same application and the hierarchy relations between those processes. … Continue reading

Posted in erlang | Tagged | Leave a comment

Getting Process Information of Erlang Runtime System

In an erlang shell we can get process information by calling i(). 1> i(). Pid Initial Call Heap Reds Msgs Registered Current Function Stack otp_ring0:start/2 610 2419 0 init init:loop/1 2 erlang:apply/2 1597 169165 0 erl_prim_loader erl_prim_loader:loop/3 6 gen_event:init_it/6 377 … Continue reading

Posted in erlang | Tagged | Leave a comment

erl_ddll and dlopen

In Erlang we can use module erl_ddll to dynamically load a native driver library. The process is very complicated. It is implemented in these files:     otp_src_R14B01/erts/emulator/beam/erl_bif_ddll.c     otp_src_R14B01/erts/emulator/sys/unix/erl_unix_sys_ddll.c     otp_src_R14B01/erts/emulator/sys/win32/erl_win32_sys_ddll.c     … Both erl_unix_sys_dll.c and erl_win32_sys_ddll.c have implemented a common interface which is … Continue reading

Posted in erlang | Tagged , | Leave a comment

Another ehttpd Performance Test

1. The hello-world http server – ehttpd 2. Start ehttpd [root@localhost azunyanmoe]# ulimit -n 99999 [azunyanmoe@localhost ~]$ cat /proc/cpuinfo | grep GHz model name : Pentium(R) Dual-Core  CPU      E5500  @ 2.80GHz model name : Pentium(R) Dual-Core  CPU      E5500  @ 2.80GHz [azunyanmoe@localhost ~]$ free -m              total       used       free     shared    buffers     cached Mem:          1980       1276        703          0         34        635 -/+ buffers/cache:        606       1373 Swap:         4998         70       4928 [azunyanmoe@localhost ~]$ erlc ehttpd.erl [azunyanmoe@localhost ~]$ taskset -c 1 erl +K true +h 99999  +P 99999 -smp enable +S 2:1 -s ehttpd Erlang R14B01 (erts-5.8.2) [ source] [smp:2:1] [rq:2] [async-threads:0] [hipe] [kernel-poll:true] ehttpd ready with 2 schedulers on port 8888 Eshell V5.8.2  (abort with ^G) 1>  3. Run test with ab from another host azunyanmoe@localhost:~$ ab -c 60 -n 100000 http://192.168.1.100:8888/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.1.100 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Completed 100000 requests Finished 100000 requests Server Software:         … Continue reading

Posted in erlang | Tagged , | Leave a comment

Erlang VM Opcodes

The Opcodes of Erlang’s emulator BEAM are listed as follow: -spec opname(1..152) -> {atom(),0..8}. opname(1) -> {label,1}; opname(2) -> {func_info,3}; opname(3) -> {int_code_end,0}; opname(4) -> {call,2}; opname(5) -> {call_last,3}; opname(6) -> {call_only,2}; opname(7) -> {call_ext,2}; opname(8) -> {call_ext_last,3}; opname(9) -> {bif0,2}; opname(10) -> {bif1,4}; opname(11) -> {bif2,5}; opname(12) -> {allocate,2}; opname(13) -> {allocate_heap,3}; opname(14) -> {allocate_zero,2}; opname(15) -> {allocate_heap_zero,3}; opname(16) -> {test_heap,2}; opname(17) -> {init,1}; opname(18) -> {deallocate,1}; opname(19) -> {return,0}; opname(20) -> {send,0}; opname(21) -> {remove_message,0}; opname(22) -> {timeout,0}; opname(23) -> {loop_rec,2}; opname(24) -> {loop_rec_end,1}; opname(25) -> {wait,1}; opname(26) -> {wait_timeout,2}; opname(27) -> {m_plus,4}; opname(28) -> {m_minus,4}; opname(29) -> {m_times,4}; opname(30) -> {m_div,4}; opname(31) -> {int_div,4}; opname(32) -> {int_rem,4}; opname(33) -> {int_band,4}; opname(34) -> {int_bor,4}; opname(35) -> {int_bxor,4}; opname(36) -> {int_bsl,4}; opname(37) -> {int_bsr,4}; opname(38) -> {int_bnot,3}; … Continue reading

Posted in erlang | Tagged | Leave a comment