1. 程式人生 > >系統技術非業餘研究 » Erlang R16B03釋出,R17已發力

系統技術非業餘研究 » Erlang R16B03釋出,R17已發力

Erlang R16B03釋出了,通常03版本是bug fix版本,進入生產版本,官方的說明如下:

OTP R16B03 is a service release with mostly a number of small corrections and user contributions. But there are some new functions worth mentioning as well, here are some of them:

A new memory allocation feature called “super carrier” has been introduced. It can for example be used for pre-allocation of all memory that the runtime system should be able to use. It is enabled by passing the +MMscs (size in MB) command line argument. For more information see the documentation of the +MMsco, +MMscrfsd, +MMscrpm, +MMscs, +MMusac, and, +Mlpm command line arguments in the erts_alloc(3) documentation.
The LDAP client (eldap application) now supports the start_tls operation. This upgrades an existing tcp connection to encryption using TLS, see eldap:start_tls/2 and /3.
The FTP client (inets application) now supports FTP over TLS (ftps).

其中最大的改進就是super carrier, 參見我之前寫的博文, 這個特性在於專機專用的系統,記憶體的使用效率就高很多,同時這個版本對多個核心之間記憶體倒騰的效率和利用率也高很多,值得大家去用。記憶體的利用率和碎片率通常不會引起大家的關注,在生產的伺服器中,這點非常值得關注。

R16B03釋出了後,官方馬不停蹄的就進入R17的開發。其中最大的期待就是語言方面的改進,包括eep37和map資料結構。 eep37特性已經進入master, commit在這裡, 該特性的具體描述在這裡.

簡單的說:就是你過去在shell下寫如下的fun過去是不可能的。

fun Fact(N) when N > 0 ->
            N * Fact(N - 1);
        Fact(0) ->
            1
end.

但是我們又經常需要這樣的匿名函式,比如spawn函式,很不方便。 eep37就是解決這樣的事情的。

我們來演示下,首先安裝R17:

$ kerl build git git://github.com/erlang/otp.git master r17 && kerl install r17  r17
$ r17/bin/erl   
Erlang/OTP 17.0-rc0 [erts-6.0] [source-7d4e5e2] [64-bit] [smp:16:16] [async-threads:10] [hipe] [kernel-poll:false] [type-assertions] [debug-compiled] [lock-checking] [systemtap]

Eshell V6.0  (abort with ^G)
1> fun Fact(N) when N > 0 ->
1>             N * Fact(N - 1);
1>         Fact(0) ->
1>             1
1>     end.
#Fun<erl_eval.29.42696066>
2> F=e(-1).
#Fun<erl_eval.29.42696066>
3> F(10).
3628800

eep37這個特性涉及到的改變還是很大的:語言規格,編譯器,偵錯程式,dialyzer, tracer, shell, emacs外掛等等,全系列的改變,所以要放在R17裡面來,雖然看提交,程式碼早在1年前準備好了。我們再來體驗下:

$ cat eep37.erl 
-module(eep37).

-compile(export_all).

-spec self() -> fun(() -> fun()).
self() ->
    fun Self() -> Self end.

-spec fact() -> fun((non_neg_integer()) -> non_neg_integer()).
fact() ->
    fun Fact(N) when N > 0 ->
            N * Fact(N - 1);
        Fact(0) ->
            1
    end.

$ r17/bin/erl 
Erlang/OTP 17.0-rc0 [erts-6.0] [source-7d4e5e2] [64-bit] [smp:16:16] [async-threads:10] [hipe] [kernel-poll:false] [type-assertions] [debug-compiled] [lock-checking] [systemtap]

Eshell V6.0  (abort with ^G)
1> eep37:fact().    
#Fun<eep37.1.16748913>
2> F=e(-1).
#Fun<eep37.1.16748913>
3> F(10).
3628800
4> 

小結: 語言也在不停的讓使用者爽。

祝玩得開心!

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