[erlang-questions] {error, emfile} on windows

Kaiduan Xie <>
Tue Nov 30 17:00:39 CET 2010


Kenneth,

Setting ERL_MAX_PORT still does not resolve the problem, it can only
open 31 TLS connections.

C:\erl5.7.1\usr>..\bin\erl.exe -env ERL_MAX_PORTS 4096
Eshell V5.7.1  (abort with ^G)
1> application:start(ssl).
ok
2> Socks = test_tls_sip:connect("10.9.22.85", 5061, 512, 1).
** exception error: no match of right hand side value {error,emfile}
     in function  test_tls_sip:'-connect/4-fun-0-'/5
     in call from lists:foldl/3

connect(Addr, Port, N, TimerValue) ->
    lists:foldl(fun(_I, Acc) ->
        {ok, Socket} = ssl:connect(Addr, Port, [{active, true}]),

        {ok, Pid} = gen_server:start(erlang_tls_connection,
                                     {Socket, TimerValue}, []),
        ssl:controlling_process(Socket, Pid),
        [Pid|Acc] end, [], lists:seq(1, N)).

Thanks,

/Kaiduan

On Tue, Nov 30, 2010 at 9:08 AM, Kenneth Lundin
<> wrote:
> On Windows there is no limit to set in the shell like in UNIX/Linux
> that the Erlang VM
> can read and adjust according to.
> Therefore you can use the environment variable ERL_MAX_PORTS to set a
> higher limit
> thant the default (1024). But bevare that the number you set will
> imply an allocation
> of  memory to hold all these port data structures. So don't set a
> higher value than you really need.
> You can actually set this on the command line when you start erlang,
> like this example:
> erl -env ERL_MAX_PORTS 4096
>
> See the documentation at:
> http://www.erlang.org/doc/efficiency_guide/advanced.html#id64904
> (I admit that it is not easy to find this, but the Efficiency Guide is
> important to know
> about and to read through for all system builders)
>
> We are thinking of changing this to a totally dynamic number of ports
> only limited by the OS setup, but that work is not scheduled for a
> specific release yet.
>
>
> On Tue, Nov 30, 2010 at 12:20 PM, Matthew Sackman <> wrote:
>> On Mon, Nov 29, 2010 at 11:18:21PM -0500, Kaiduan Xie wrote:
>>> I tried to create 1K TCP/TLS client connections on a Windows box, and
>>> got {error, emfile} error, any idea to solve it? I have no problem on
>>> Linux after raising the ulimit.
>>
>> Whilst in theory windows has a limit of around 16M fds per process, the
>> Erlang windows port seems to use bits of the MS C runtime. This seems to
>> limit severely wrt number of available sockets.
>
> Well this is not a correct statement as already described.
>>
>> Whilst erlang:system_info(check_io) reports 2048 under Windows, that's
>> clearly wrong. But hey, a few years ago, I found that fsync under the
>> Windows port was implemented as "return 1;". Such is the quality of the
>> Windows port.
> This is not the case now, fsync is definitely implemented.
>
> Windows has not been our main target platform for Erlang but I still
> think the quality is good even on Windows.
>
> With an increasing number of developers doing serious applications
> with Erlang on
> Windows the functionality and quality will become even better.
>
>
> /Kenneth Erlang/OTP, Ericsson
>
>>
>> Matthew
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:
>>
>>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


More information about the erlang-questions mailing list