Archive
Tsung压力测试工具介绍PPT
准备为测试部门的同学作个Tsung的讲座, 点击下载Tsung
需要进一步了解Tsung的同学 点这里看官方的文档!
想了解如何使用的还可以到Erlang china这里看看!
OTP R14A今天正式发布了
点击这里下载R14A
以下是这次发布的亮点,没有太大的性能改进, 主要是修理了很多BUG!
— HIGHLIGHTS ———————————————————-
OTP-8217 == erts stdlib compiler ==
The module binary from EEP31 (and EEP9) is implemented.
OTP-8485 == common_test ==
It is now possible for the user to provide specific callback
modules that handle test configuration data, so that data on
arbitray form can be accessed (e.g. by reading files or by
communicating with a configuration server process). Two
default callback modules have been introduced in Common Test:
ct_config_plain and ct_config_xml. The former is used to
handle the traditional Common Test configuration files (with
terms on key-value tuple form) and the latter to handle
configuration data on XML representation.
OTP-8555 == erts ==
New NIF features:
Send messages from a NIF, or from thread created by NIF, to
any local process (enif_send)
Store terms between NIF calls (enif_alloc_env,
enif_make_copy)
Create binary terms with user defined memory management
(enif_make_resource_binary)
And some incompatible changes made to the API. For more
information see the warning text in erl_nif(3).
OTP-8623 == compiler erts hipe stdlib ==
Receive statements that can only read out a newly created
reference are now specially optimized so that it will execute
in constant time regardless of the number of messages in the
receive queue for the process. That optimization will benefit
calls to gen_server:call(). (See gen:do_call/4 for an example
of a receive statement that will be optimized.)
OTP-8650 == common_test ==
The run_test script has been replaced by a program (with the
same name) which can be executed without explicit
installation. The start flags are the same as for the legacy
start script.
OTP-8706 == erts hipe tools ==
eprof has been reimplemented with support in the Erlang
virtual machine and is now both faster (i.e. slows down the
code being measured less) and scales much better. In
measurements we saw speed-ups compared to the old eprof
ranging from 6 times (for sequential code that only uses one
scheduler/core) up to 84 times (for parallel code that uses 8
cores).
Note: The API for the eprof has been cleaned up and extended.
See the documentation.
期待R14B有大的动作!
我的emacs配置
贴上来方便有用emacs的同学。配置部分是从网上淘来的,忘记出处了,见谅!
;;(keyboard-translate ?\C-h ?\C-?)
(defalias 'yes-or-no-p 'y-or-n-p)
(setq time-stamp-active t)
(setq time-stamp-warn-inactive t)
(setq time-stamp-format "%:y-%02m-%02d %3a %02H:%02M:%02S")
(add-hook 'write-file-hooks 'time-stamp)
(global-set-key [f2] 'rgrep)
(global-set-key [(f5)] 'eshell)
(global-set-key [C-f5] 'shell)
(global-set-key (kbd "M-3") 'capitalize-word)
(global-set-key [f6] 'find-file)
(global-set-key [C-Z] nil)
(global-set-key [C-f4] 'kill-this-buffer)
(global-set-key [(f4)] 'ibuffer)
(global-set-key [(f8)] 'other-window)
(require 'color-theme)
;;(color-theme-initialize)
(color-theme-dark-blue2)
(setq font-lock-verbose t)
;;(set-default-font "Bitstream Vera Sans Mono-12")
(global-font-lock-mode t)
(tool-bar-mode -1)
(setq column-number-mode t)
(setq display-battery-mode t)
(setq size-indication-mode t)
(setq default-major-mode 'outline-mode)
(add-hook 'outline-mode-hook 'turn-off-auto-fill)
(setq transient-mark-mode t)
(setq-default shell-cd-regexp nil)
(setq-default shell-pushd-regexp nil)
(setq-default shell-popd-regexp nil)
(setq inhibit-startup-message t)
(setq visible-bell t)
(setq mouse-yank-at-point t)
(setq kill-ring-max 100)
(setq default-fill-column 60)
(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "M-o") 'ff-find-related-file)
(setq require-final-newline t)
(setq track-eol t)
(setq gnus-inhibit-startup-message t)
(setq enable-recursive-minibuffers t)
(setq auto-save-mode nil)
(setq Man-notify-method 'pushy)
(display-time-mode 1)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(setq display-time-use-mail-icon t)
(setq display-time-interval 10)
(tool-bar-mode -1)
(customize-set-variable 'scroll-bar-mode 'right)
(setq speedbar-show-unknown-files t)
(setq speedbar-update-flag nil)
(setq speedbar-use-images nil)
(setq speedbar-verbosity-level 0)
(global-set-key [f9] 'speedbar)
;; set paren mode
(show-paren-mode t)
(setq show-paren-style 'parentheses)
(mouse-avoidance-mode 'animate)
;; set the default username and email
(setq user-full-name "yufeng")
(setq user-mail-address "mryufeng@gmail.com")
;; set the title name
(setq frame-title-format "Emacs - %f")
;;-------------------------Shell 使用 ansi color-------------
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(require 'uniquify)
(setq
uniquify-buffer-name-style 'post-forward
uniquify-separator ":")
;;
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(require 'ido)
(ido-mode t)
;;-------------------------让Emacs拥有tabs-------------------
(require 'tabbar)
(setq tabbar-buffer-groups-function
(lambda ()
(list "All")))
(tabbar-mode)
(global-set-key [(control shift tab)] 'tabbar-backward)
(global-set-key [(control tab)] 'tabbar-forward)
(global-set-key (kbd "M-1") 'tabbar-backward)
(global-set-key (kbd "M-2") 'tabbar-forward)
;;(require 'session)
;;(add-hook 'after-init-hook 'session-initialize)
;;(load "desktop")
;;(desktop-load-default)
;;(desktop-read)
;;(setq desktop-save-mode t)
(require 'browse-kill-ring)
(global-set-key [(control c)(k)] 'browse-kill-ring)
(browse-kill-ring-default-keybindings)
;;erlang
;;(require 'erlang-eunit)
;;(load "erlang_appwiz" t nil)
(global-set-key [f3] 'erlang-next-error)
(global-set-key [C-f7] 'erlang-compile)
(global-set-key [f7] 'compile)
(global-set-key [f10] 'linum-mode)
;;distel
(add-to-list 'load-path "/usr/local/share/distel/elisp")
(require 'distel)
(distel-setup)
;; Some Erlang customizations
(add-hook 'erlang-mode-hook
(lambda ()
;; when starting an Erlang shell in Emacs, default in the node name
` (setq inferior-erlang-machine-options '("-sname" "emacs"))
;; add Erlang functions to an imenu menu
(imenu-add-to-menubar "imenu")))
;; A number of the erlang-extended-mode key bindings are useful in the shell too
(defconst distel-shell-keys
'(("\C-\M-i" erl-complete)
("\M-?" erl-complete)
("\M-." erl-find-source-under-point)
("\M-," erl-find-source-unwind)
("\M-*" erl-find-source-unwind)
)
"Additional keys to bind when in Erlang shell.")
(add-hook 'erlang-shell-mode-hook
(lambda ()
;; add some Distel bindings to the Erlang shell
(dolist (spec distel-shell-keys)
(define-key erlang-shell-mode-map (car spec) (cadr spec)))))
;wrangler
(add-to-list 'load-path "/usr/local/share/wrangler/elisp")
(require 'wrangler)
;;ecb
(require 'xcscope)
(require 'cedet) ;;load cedet
(require 'ecb) ;;load ecb
(setq ecb-tip-of-the-day nil
inhibit-startup-message t
ecb-auto-compatibility-check nil
ecb-version-check nil)
(global-set-key [f12] 'ecb-activate)
(global-set-key [C-f12] 'ecb-deactivate)
(global-set-key [f11] 'delete-other-windows)
(global-set-key [(meta return)] 'semantic-ia-complete-symbol-menu)
(global-set-key (kbd "C-c e") 'ecb-goto-window-edit-last)
(global-set-key (kbd "C-c s") 'ecb-goto-window-sources)
(global-set-key (kbd "C-c d") 'ecb-goto-window-directories)
(global-set-key (kbd "C-c m") 'ecb-goto-window-methods)
(global-set-key (kbd "C-c h") 'ecb-goto-window-history)
(global-set-key (kbd "C-c r") 'ecb-redraw-layout)
(global-set-key (kbd "C-.") 'cscope-find-global-definition-no-prompting)
(global-set-key (kbd "C-,") 'cscope-pop-mark)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ecb-options-version "2.32")
'(safe-local-variable-values (quote ((erlang-indent-level . 2)))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;;msf abbrev
(add-to-list 'load-path "~/emacs")
;; ensure abbrev mode is always on
(setq-default abbrev-mode t)
;; do not bug me about saving my abbreviations
(setq save-abbrevs nil)
;; load up modes I use
(require 'cc-mode)
;;(require 'perl-mode)
;;(require 'cperl-mode)
;;(require 'sh-script)
;;(require 'shell)
;;(require 'lua-mode)
;;(require 'erlang)
;; load up abbrevs for these modes
(require 'msf-abbrev)
(setq msf-abbrev-verbose t) ;; optional
(setq msf-abbrev-root "~/emacs/mode-abbrevs")
(global-set-key (kbd "C-c l") 'msf-abbrev-goto-root)
(global-set-key (kbd "C-c a") 'msf-abbrev-define-new-abbrev-this-mode)
(msf-abbrev-load)
;;go mode
(require 'go-mode-load)
(require 'tramp)
;;gud
(add-hook 'gdb-mode-hook '(lambda ()
(define-key c-mode-base-map [(f5)] 'gud-go)
(define-key c-mode-base-map [(f7)] 'gud-step)
(define-key c-mode-base-map [(f8)] 'gud-next)))
(defvar no-easy-keys-minor-mode-map (make-keymap)
"no-easy-keys-minor-mode keymap.")
(let ((f (lambda (m)
`(lambda () (interactive)
(message (concat "No! use " ,m " instead."))))))
(dolist (l '(("<left>" . "C-b") ("<right>" . "C-f") ("<up>" . "C-p")
("<down>" . "C-n")
("<C-left>" . "M-f") ("<C-right>" . "M-b") ("<C-up>" . "M-{")
("<C-down>" . "M-}")
("<M-left>" . "M-f") ("<M-right>" . "M-b") ("<M-up>" . "M-{")
("<M-down>" . "M-}")
("<delete>" . "C-d") ("<C-delete>" . "M-d")
("<M-delete>" . "M-d") ("<next>" . "C-v") ("<C-next>" . "M-x <")
("<prior>" . "M-v") ("<C-prior>" . "M-x >")
("<home>" . "C-a") ("<C-home>" . "M->")
("<C-home>" . "M-<") ("<end>" . "C-e") ("<C-end>" . "M->")))
(define-key no-easy-keys-minor-mode-map
(read-kbd-macro (car l)) (funcall f (cdr l)))))
(define-minor-mode no-easy-keys-minor-mode
"A minor mode that disables the arrow-keys, pg-up/down, delete
and backspace." t " no-easy-keys"
'no-easy-keys-minor-mode-map :global t)
(no-easy-keys-minor-mode 1)
(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(setq transient-mark-mode t) ; highlight text selection
(setq delete-selection-mode t) ; delete seleted text when typing
; highlight current line
(require 'hl-line)
(global-hl-line-mode t)
R14A实现了EEP31,添加了binary模块
Erlang的binary数据结构非常强大,而且偏向底层,在作网络程序的时候,很方便的能够和二进制协议对应起来。但是由于这个数据结构加入erlang语言的时间不是很长,相关的配套模块不是很多。 在binary的匹配,替换,修改就显的非常麻烦。 于是有了EEP31 。 R14A昨天已经实现了这个功能, 在stdlib下添加了个binary模块。 这个模块大部分功能是由BIF实现的, 同时充分考虑了CPU使用的公平性,源码大部分在erl_bif_binary.c下。 还添加了个gurad函数: binary_part进一步方便我们写匹配条件。
我们在源码里面发现了以下注释:
/*
* The native implementation functions for the module binary.
* Searching is implemented using aither Boyer-More or Aho-Corasick
* depending on number of searchstrings (BM if one, AC if more than one).
* Native implementation is mostly for efficiency, nothing
* (except binary:referenced_byte_size) really *needs* to be implemented
* in native code.
*/
这个模块兼顾了效率和方便性,使用起来就大大简化了代码的复杂度,有福气了。
R14A添加新指令优化Ref消息的接收
Erlang的惯用法之一就是在消息匹配的时候,如果需要唯一性,通常会通过make_ref搞个唯一的Ref来作为消息的一部分来匹配。这个惯用法用在gen_server:call或者demonitor这样的使用频度很高的函数里面。由于erlang的消息匹配是再消息队列里面挨个遍历来匹配,特别是消息队列特别长的时候,会有很大的性能瓶颈。于是新的优化出现了,以下是编译器beam_receive.erl里面的解释,写的很清楚:
%%%
%%% In code such as:
%%%
%%% Ref = make_ref(), %Or erlang:monitor(process, Pid)
%%% .
%%% .
%%% .
%%% receive
%%% {Ref,Reply} -> Reply
%%% end.
%%%
%%% we know that none of the messages that exist in the message queue
%%% before the call to make_ref/0 can be matched out in the receive
%%% statement. Therefore we can avoid going through the entire message
%%% queue if we introduce two new instructions (here written as
%%% BIFs in pseudo-Erlang):
%%%
%%% recv_mark(SomeUniqInteger),
%%% Ref = make_ref(),
%%% .
%%% .
%%% .
%%% recv_set(SomeUniqInteger),
%%% receive
%%% {Ref,Reply} -> Reply
%%% end.
%%%
%%% The recv_mark/1 instruction will save the current position and
%%% SomeUniqInteger in the process context. The recv_set
%%% instruction will verify that SomeUniqInteger is still stored
%%% in the process context. If it is, it will set the current pointer
%%% for the message queue (the next message to be read out) to the
%%% position that was saved by recv_mark/1.
%%%
%%% The remove_message instruction must be modified toinvalidate
%%% the information stored by the previous recv_mark/1, in case there
%%% is another receive executed between the calls to recv_mark/1 and
%%% recv_set/1.
%%%
%%% We use a reference to a label (i.e. a position in the loaded code)
%%% as the SomeUniqInteger.
%%%
结论: 点滴优化成就高性能。
非阻塞connect的一个细节
昨天听zhuzhaoyuan说的一个connect细节. 通常我们connect的时候都是非阻塞的, 在connect调用后把句柄挂到poll去, 等poll通知可写的时候, 我们就认为connect成功了. 但是在linux平台下实际上不一定成功, 具体的要用socket get_opt来检查下出错码来决定.
以下是从man 2 connnect摘抄的:
EINPROGRESS
The socket(2,7,n) is non-blocking and the connection cannot be com-
pleted immediately. It is possible to select(2,7,2 select_tut)(2) or poll(2) for
completion by selecting the socket(2,7,n) for writing. After select(2,7,2 select_tut)
indicates writability, use getsockopt(2) to read(2,n,1 builtins) the SO_ERROR
option at level SOL_SOCKET to determine whether connect com-
pleted successfully (SO_ERROR is zero) or unsuccessfully
(SO_ERROR is one of the usual error(8,n) codes listed here, explain-
ing the reason for the failure).
我们看下erlang的inet_drv是如何处理的.
./erts/emulator/drivers/common/inet_drv.c:
{
int error = 0; /* Has to be initiated, we check it */
unsigned int sz = sizeof(error); /* even if we get -1 */
int code = sock_getopt(desc->inet.s, SOL_SOCKET, SO_ERROR,
(void *)&error, &sz);
if ((code < 0) || error) {
desc->inet.state = TCP_STATE_BOUND; /* restore state */
ret = async_error(INETP(desc), error);
goto done;
}
}
结论: 细节决定品质.



Recent Comments