Archive

Posts Tagged ‘NIF’

例证NIF使用的误区

December 2nd, 2010 6 comments

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

本文链接地址: 例证NIF使用的误区

NIF是什么? A NIF library contains native implementation of some functions of an Erlang module.
不清楚的同学请参考http://www.erlang.org/doc/man/erl_nif.html.
这个功能对于扩展Erlang,利用现有的遗留c的财产,提高性能非常有帮助.
但是通常同学们会无视手册里面的一句话:

Avoid doing lengthy work in NIF calls as that may degrade the responsiveness of the VM. NIFs are called directly by the same scheduler thread that executed the calling Erlang code. The calling scheduler will thus be blocked from doing any other work until the NIF returns

导致了非常严重的设计问题. 比如在NIF里面调用mysql client api, 作费时的IO操作等等, 我已经看到好几个同学这么干了,为了揭示这个问题的严重性, davisp同学为我们写了个例子来演示这个问题: 代码在这里
https://github.com/davisp/sleepy
.

Sleepy – A misbehaving NIF
This demonstrates what happens if a NIF takes a long time and is called from as many schedulers as exist in the VM. Namely, that the VM is halted until the NIF functions return.

我们来演示下把:
Read more…

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

Categories: Erlang探索 Tags: ,

R13B04 NIF improvements

February 16th, 2010 Comments off

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

本文链接地址: R13B04 NIF improvements

OTP-8335 NIF improvements:

Driver API for multi-threading made available for NIFs.

Support for mempory managed (garbage collected) resource objects.
A way to pass “pointers” to native data structures between C and
Erlang in a safe way.

Various new functions, like enif_inspect_iolist_as_binary,
enif_make_sub_binary, enif_get_string, enif_get_atom,
enif_make_tuple_from_array, enif_make_list_from_array,
enif_make_existing_atom.

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

Categories: Erlang探索 Tags: ,