今天在Mac Os X系統下啓動erlang應用時報錯誤:
driver_select(0x0000000000000288, 1053, ERL_DRV_WRITE ERL_DRV_USE, 1) by tcp_inet driver #Port<0.2696> failed: fd=1053 is larger than the largest allowed fd=1023
文件描述符限制,先ulimit -n查看一下,設置值遠大於1024,沒問題;再查看系統內核設置,sysctl -a一下,kern.maxfiles=12288,kern.maxfilesperproc=10240,也沒問題,納悶了,再+P -env ERL_MAX_PORTS各種啓動參數調試,依然不好使,抓狂中google、百度各種折騰,最後搜到原因是在erts/emulator/sys/common/erl_poll.c中max_fds的值設置爲FD_SETSIZE,而Mac Os X系統中FD_SETSIZE在/usr/include/sys/_structs.h中限制爲1024。原因找到了,看解決辦法,貌似有兩種解決辦法:
1、修改系統頭文件/usr/include/sys/_structs.h中__DARWIN_FD_SETSIZE的值
> 1) Save old epmd.
>
> 2) Modify __DARWIN_FD_SETSIZE in /usr/include/sys/_structs.h and make it, say, 16384.
>
> 3) Recompile Erlang.
>
> 4) Restore old epmd since it can't handle more than 1024 fds.
2、編譯erlang時在./configure的參數中加入CFLAGS="-DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT"
兩種方法我都還沒嘗試,好不好使不知道,先記下來再研究,但貌似回答問題的有說這個值不要輕易修改,有可能影響性能。
更詳細的信息看鏈接:
https://github.com/mxcl/homebrew/issues/6143
http://erlang.2086793.n4.nabble.com/kpoll-still-using-select-td2116370.html