summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2010-02-03 21:57:14 +0000
committerMatthias Radestock <matthias@lshift.net>2010-02-03 21:57:14 +0000
commit1ee896c9f0735434a75a646570a48cec613c8994 (patch)
tree61cac837d49a5891a499ce9a777d817c2ff83b22 /src
parent8cf09dc169c95b378c4e5a94bff260e50b8cbd48 (diff)
parent2ce7e4b604f2750ee5031d67cee2d20a8f2f5a53 (diff)
downloadrabbitmq-server-git-1ee896c9f0735434a75a646570a48cec613c8994.tar.gz
merge default into bug21966
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_amqqueue.erl5
-rw-r--r--src/rabbit_amqqueue_process.erl7
-rw-r--r--src/rabbit_exchange.erl5
-rw-r--r--src/rabbit_networking.erl12
-rw-r--r--src/rabbit_reader.erl5
-rw-r--r--src/rabbit_tests.erl20
-rw-r--r--src/vm_memory_monitor.erl36
7 files changed, 53 insertions, 37 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl
index 9e8e5d6cdb..db7461b09f 100644
--- a/src/rabbit_amqqueue.erl
+++ b/src/rabbit_amqqueue.erl
@@ -36,7 +36,7 @@
-export([pseudo_queue/2]).
-export([lookup/1, with/2, with_or_die/2,
stat/1, stat_all/0, deliver/2, redeliver/2, requeue/3, ack/4]).
--export([list/1, info/1, info/2, info_all/1, info_all/2]).
+-export([list/1, info_keys/0, info/1, info/2, info_all/1, info_all/2]).
-export([claim_queue/2]).
-export([basic_get/3, basic_consume/8, basic_cancel/4]).
-export([notify_sent/2, unblock/2]).
@@ -69,6 +69,7 @@
-spec(with/2 :: (queue_name(), qfun(A)) -> A | not_found()).
-spec(with_or_die/2 :: (queue_name(), qfun(A)) -> A).
-spec(list/1 :: (vhost()) -> [amqqueue()]).
+-spec(info_keys/0 :: () -> [info_key()]).
-spec(info/1 :: (amqqueue()) -> [info()]).
-spec(info/2 :: (amqqueue(), [info_key()]) -> [info()]).
-spec(info_all/1 :: (vhost()) -> [[info()]]).
@@ -222,6 +223,8 @@ list(VHostPath) ->
rabbit_queue,
#amqqueue{name = rabbit_misc:r(VHostPath, queue), _ = '_'}).
+info_keys() -> rabbit_amqqueue_process:info_keys().
+
map(VHostPath, F) -> rabbit_misc:filter_exit_map(F, list(VHostPath)).
info(#amqqueue{ pid = QPid }) ->
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl
index a3b0814cfa..06e68a1b16 100644
--- a/src/rabbit_amqqueue_process.erl
+++ b/src/rabbit_amqqueue_process.erl
@@ -39,7 +39,7 @@
-define(HIBERNATE_AFTER_MIN, 1000).
-define(DESIRED_HIBERNATE, 10000).
--export([start_link/1]).
+-export([start_link/1, info_keys/0]).
-export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]).
@@ -88,9 +88,10 @@
%%----------------------------------------------------------------------------
-start_link(Q) ->
- gen_server2:start_link(?MODULE, Q, []).
+start_link(Q) -> gen_server2:start_link(?MODULE, Q, []).
+info_keys() -> ?INFO_KEYS.
+
%%----------------------------------------------------------------------------
init(Q) ->
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl
index c72ff7f9f7..33bfe89399 100644
--- a/src/rabbit_exchange.erl
+++ b/src/rabbit_exchange.erl
@@ -35,7 +35,7 @@
-include("rabbit_framing.hrl").
-export([recover/0, declare/5, lookup/1, lookup_or_die/1,
- list/1, info/1, info/2, info_all/1, info_all/2,
+ list/1, info_keys/0, info/1, info/2, info_all/1, info_all/2,
publish/2]).
-export([add_binding/4, delete_binding/4, list_bindings/1]).
-export([delete/2]).
@@ -68,6 +68,7 @@
-spec(lookup/1 :: (exchange_name()) -> {'ok', exchange()} | not_found()).
-spec(lookup_or_die/1 :: (exchange_name()) -> exchange()).
-spec(list/1 :: (vhost()) -> [exchange()]).
+-spec(info_keys/0 :: () -> [info_key()]).
-spec(info/1 :: (exchange()) -> [info()]).
-spec(info/2 :: (exchange(), [info_key()]) -> [info()]).
-spec(info_all/1 :: (vhost()) -> [[info()]]).
@@ -165,6 +166,8 @@ list(VHostPath) ->
rabbit_exchange,
#exchange{name = rabbit_misc:r(VHostPath, exchange), _ = '_'}).
+info_keys() -> ?INFO_KEYS.
+
map(VHostPath, F) ->
%% TODO: there is scope for optimisation here, e.g. using a
%% cursor, parallelising the function invocation
diff --git a/src/rabbit_networking.erl b/src/rabbit_networking.erl
index 84be7918e9..06e2b40e47 100644
--- a/src/rabbit_networking.erl
+++ b/src/rabbit_networking.erl
@@ -32,10 +32,11 @@
-module(rabbit_networking).
-export([boot/0, start/0, start_tcp_listener/2, start_ssl_listener/3,
- stop_tcp_listener/2, on_node_down/1, active_listeners/0,
- node_listeners/1, connections/0, connection_info/1,
- connection_info/2, connection_info_all/0,
- connection_info_all/1]).
+ stop_tcp_listener/2, on_node_down/1, active_listeners/0,
+ node_listeners/1, connections/0, connection_info_keys/0,
+ connection_info/1, connection_info/2,
+ connection_info_all/0, connection_info_all/1]).
+
%%used by TCP-based transports, e.g. STOMP adapter
-export([check_tcp_listener_address/3]).
@@ -70,6 +71,7 @@
-spec(active_listeners/0 :: () -> [listener()]).
-spec(node_listeners/1 :: (erlang_node()) -> [listener()]).
-spec(connections/0 :: () -> [connection()]).
+-spec(connection_info_keys/0 :: () -> [info_key()]).
-spec(connection_info/1 :: (connection()) -> [info()]).
-spec(connection_info/2 :: (connection(), [info_key()]) -> [info()]).
-spec(connection_info_all/0 :: () -> [[info()]]).
@@ -214,6 +216,8 @@ connections() ->
[Pid || {_, Pid, _, _} <- supervisor:which_children(
rabbit_tcp_client_sup)].
+connection_info_keys() -> rabbit_reader:info_keys().
+
connection_info(Pid) -> rabbit_reader:info(Pid).
connection_info(Pid, Items) -> rabbit_reader:info(Pid, Items).
diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl
index 503e2fb4ae..f5bdb98593 100644
--- a/src/rabbit_reader.erl
+++ b/src/rabbit_reader.erl
@@ -33,7 +33,7 @@
-include("rabbit_framing.hrl").
-include("rabbit.hrl").
--export([start_link/0, info/1, info/2]).
+-export([start_link/0, info_keys/0, info/1, info/2]).
-export([system_continue/3, system_terminate/4, system_code_change/4]).
@@ -129,6 +129,7 @@
-ifdef(use_specs).
+-spec(info_keys/0 :: () -> [info_key()]).
-spec(info/1 :: (pid()) -> [info()]).
-spec(info/2 :: (pid(), [info_key()]) -> [info()]).
@@ -155,6 +156,8 @@ system_terminate(Reason, _Parent, _Deb, _State) ->
system_code_change(Misc, _Module, _OldVsn, _Extra) ->
{ok, Misc}.
+info_keys() -> ?INFO_KEYS.
+
info(Pid) ->
gen_server:call(Pid, info, infinity).
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 66bdd4cdc7..833ccc2638 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -695,18 +695,10 @@ test_server_status() ->
false, false, []),
%% list queues
- ok = info_action(
- list_queues,
- [name, durable, auto_delete, arguments, pid,
- messages_ready, messages_unacknowledged, messages_uncommitted,
- messages, acks_uncommitted, consumers, transactions, memory],
- true),
+ ok = info_action(list_queues, rabbit_amqqueue:info_keys(), true),
%% list exchanges
- ok = info_action(
- list_exchanges,
- [name, type, durable, auto_delete, arguments],
- true),
+ ok = info_action(list_exchanges, rabbit_exchange:info_keys(), true),
%% list bindings
ok = control_action(list_bindings, []),
@@ -721,12 +713,8 @@ test_server_status() ->
{ok, C} = gen_tcp:connect(H, P, []),
timer:sleep(100),
- ok = info_action(
- list_connections,
- [pid, address, port, peer_address, peer_port, state,
- channels, user, vhost, timeout, frame_max,
- recv_oct, recv_cnt, send_oct, send_cnt, send_pend],
- false),
+ ok = info_action(list_connections,
+ rabbit_networking:connection_info_keys(), false),
ok = gen_tcp:close(C),
passed.
diff --git a/src/vm_memory_monitor.erl b/src/vm_memory_monitor.erl
index 91788caae8..02bd04991e 100644
--- a/src/vm_memory_monitor.erl
+++ b/src/vm_memory_monitor.erl
@@ -37,8 +37,6 @@
%%
%% This module tries to warn Rabbit before such situations occur, so
%% that it has a higher chance to avoid running out of memory.
-%%
-%% This code depends on Erlang os_mon application.
-module(vm_memory_monitor).
@@ -78,6 +76,7 @@
('ignore' | {'error', any()} | {'ok', pid()})).
-spec(update/0 :: () -> 'ok').
-spec(get_total_memory/0 :: () -> (non_neg_integer() | 'unknown')).
+-spec(get_vm_limit/0 :: () -> (non_neg_integer() | 'unknown')).
-spec(get_memory_limit/0 :: () -> (non_neg_integer() | 'undefined')).
-spec(get_check_interval/0 :: () -> non_neg_integer()).
-spec(set_check_interval/1 :: (non_neg_integer()) -> 'ok').
@@ -97,6 +96,9 @@ update() ->
get_total_memory() ->
get_total_memory(os:type()).
+get_vm_limit() ->
+ get_vm_limit(os:type()).
+
get_check_interval() ->
gen_server:call(?MODULE, get_check_interval, infinity).
@@ -208,17 +210,26 @@ start_timer(Timeout) ->
{ok, TRef} = timer:apply_interval(Timeout, ?MODULE, update, []),
TRef.
+%% According to http://msdn.microsoft.com/en-us/library/aa366778(VS.85).aspx
+%% Windows has 2GB and 8TB of address space for 32 and 64 bit accordingly.
+get_vm_limit({win32,_OSname}) ->
+ case erlang:system_info(wordsize) of
+ 4 -> 2*1024*1024*1024; %% 2 GB for 32 bits 2^31
+ 8 -> 8*1024*1024*1024*1024 %% 8 TB for 64 bits 2^42
+ end;
+
%% On a 32-bit machine, if you're using more than 2 gigs of RAM you're
%% in big trouble anyway.
-get_vm_limit() ->
+get_vm_limit(_OsType) ->
case erlang:system_info(wordsize) of
- 4 -> 4294967296; %% 4 GB for 32 bits 2^32
- 8 -> 281474976710656 %% 256 TB for 64 bits 2^48
+ 4 -> 4*1024*1024*1024; %% 4 GB for 32 bits 2^32
+ 8 -> 256*1024*1024*1024*1024 %% 256 TB for 64 bits 2^48
%%http://en.wikipedia.org/wiki/X86-64#Virtual_address_space_details
end.
get_mem_limit(MemFraction, TotalMemory) ->
- lists:min([trunc(TotalMemory * MemFraction), get_vm_limit()]).
+ AvMem = lists:min([TotalMemory, get_vm_limit()]),
+ trunc(AvMem * MemFraction).
%%----------------------------------------------------------------------------
%% Internal Helpers
@@ -250,11 +261,14 @@ get_total_memory({unix,freebsd}) ->
PageCount * PageSize;
get_total_memory({win32,_OSname}) ->
- [Result|_] = os_mon_sysinfo:get_mem_info(),
- {ok, [_MemLoad, TotPhys, _AvailPhys,
- _TotPage, _AvailPage, _TotV, _AvailV], _RestStr} =
- io_lib:fread("~d~d~d~d~d~d~d", Result),
- TotPhys;
+ %% Due to the Erlang print format bug, on Windows boxes the memory size is
+ %% broken. For example Windows 7 64 bit with 4Gigs of RAM we get negative
+ %% memory size:
+ %% > os_mon_sysinfo:get_mem_info().
+ %% ["76 -1658880 1016913920 -1 -1021628416 2147352576 2134794240\n"]
+ %% Due to this bug, we don't actually know anything. Even if the number is
+ %% postive we can't be sure if it's correct.
+ unknown;
get_total_memory({unix, linux}) ->
File = read_proc_file("/proc/meminfo"),