diff options
author | Marek Majkowski <marek@rabbitmq.com> | 2011-03-08 11:11:57 +0000 |
---|---|---|
committer | Marek Majkowski <marek@rabbitmq.com> | 2011-03-08 11:11:57 +0000 |
commit | 21343de94bc744bc430bbc2b72d9526c284432a6 (patch) | |
tree | 66fbdb899251c866d00182462bea8e62e9a8b7c7 | |
parent | 451cddf4ff9edbb8e52fb588aaff462ccd719c27 (diff) | |
download | rabbitmq-server-21343de94bc744bc430bbc2b72d9526c284432a6.tar.gz |
Use system_info(check_io)/max_fds instead of ulimit.
-rw-r--r-- | src/file_handle_cache.erl | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index 6f8241b3..de602d39 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -156,13 +156,6 @@ -define(SERVER, ?MODULE). -define(RESERVED_FOR_OTHERS, 100). -%% Googling around suggests that Windows has a limit somewhere around -%% 16M, eg -%% http://blogs.technet.com/markrussinovich/archive/2009/09/29/3283844.aspx -%% however, it turns out that's only available through the win32 -%% API. Via the C Runtime, we have just 512: -%% http://msdn.microsoft.com/en-us/library/6e3b887c%28VS.80%29.aspx --define(FILE_HANDLES_LIMIT_WINDOWS, 512). -define(FILE_HANDLES_LIMIT_OTHER, 1024). -define(FILE_HANDLES_CHECK_INTERVAL, 2000). @@ -1185,29 +1178,17 @@ track_client(Pid, Clients) -> false -> ok end. -%% For all unices, assume ulimit exists. Further googling suggests -%% that BSDs (incl OS X), solaris and linux all agree that ulimit -n -%% is file handles + ulimit() -> - case os:type() of - {win32, _OsName} -> - ?FILE_HANDLES_LIMIT_WINDOWS; - {unix, _OsName} -> - %% Under Linux, Solaris and FreeBSD, ulimit is a shell - %% builtin, not a command. In OS X and AIX it's a command. - %% Fortunately, os:cmd invokes the cmd in a shell env, so - %% we're safe in all cases. - case os:cmd("ulimit -n") of - "unlimited" -> - infinity; - String = [C|_] when $0 =< C andalso C =< $9 -> - list_to_integer( - lists:takewhile( - fun (D) -> $0 =< D andalso D =< $9 end, String)); - _ -> - %% probably a variant of - %% "/bin/sh: line 1: ulimit: command not found\n" - unknown + case proplists:get_value(max_fds, erlang:system_info(check_io)) of + MaxFds when is_integer(MaxFds) andalso MaxFds > 1 -> + case os:type() of + {win32, _OsName} -> + %% On Windows max_fds is twice the number of open files: + %% https://github.com/yrashk/erlang/blob/master/erts/emulator/sys/win32/sys.c#L2463-2466 + MaxFds / 2; + _Any -> + MaxFds end; _ -> unknown |