diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-10-02 16:53:06 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-10-02 16:53:06 +0100 |
commit | 959c2cdbd1622e0cfdd95866af0f1344d48eb3b0 (patch) | |
tree | 6e092513e4694e22fb7f22e8266d2a3c4bfb21f5 | |
parent | c176dd0e4febbfe0ac24469a5a462652ebdb7039 (diff) | |
download | rabbitmq-server-959c2cdbd1622e0cfdd95866af0f1344d48eb3b0.tar.gz |
Various tweaks.
-rw-r--r-- | src/rabbit_misc.erl | 14 | ||||
-rw-r--r-- | src/rabbit_vm.erl | 57 |
2 files changed, 36 insertions, 35 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index a0536a50..7e79ef8c 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -63,6 +63,7 @@ -export([version/0]). -export([sequence_error/1]). -export([json_encode/1, json_decode/1, json_to_term/1, term_to_json/1]). +-export([interval_operation/3]). %% Horrible macro to use in guards -define(IS_BENIGN_EXIT(R), @@ -227,6 +228,9 @@ -spec(json_decode/1 :: (string()) -> {'ok', any()} | 'error'). -spec(json_to_term/1 :: (any()) -> any()). -spec(term_to_json/1 :: (any()) -> any()). +-spec(interval_operation/3 :: + (fun (() -> any()), non_neg_integer(), non_neg_integer()) + -> {any(), non_neg_integer()}). -endif. @@ -987,3 +991,13 @@ term_to_json(L) when is_list(L) -> term_to_json(V) when is_binary(V) orelse is_number(V) orelse V =:= null orelse V =:= true orelse V =:= false -> V. + +%% Ideally, you'd want Fun to run every IdealInterval. but you don't +%% want it to take more than MaxRatio of IdealInterval. So if it takes +%% more then you want to run it less often. So we time how long it +%% takes to run, and then suggest how long you should wait before +%% running it again. Times are in millis. +interval_operation(Fun, MaxRatio, IdealInterval) -> + {Micros, Res} = timer:tc(Fun), + Ratio = lists:max([1, Micros / (MaxRatio * IdealInterval) / 1000]), + {Res, round(IdealInterval * Ratio)}. diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl index 9f9b9fbe..1323512b 100644 --- a/src/rabbit_vm.erl +++ b/src/rabbit_vm.erl @@ -16,25 +16,24 @@ -module(rabbit_vm). --export([memory/0, interval_operation/3]). +-export([memory/0]). --define(MAGIC_PLUGINS, [mochiweb, webmachine, cowboy, sockjs, rfc4627_jsonrpc]). +-define(MAGIC_PLUGINS, ["mochiweb", "webmachine", "cowboy", "sockjs", + "rfc4627_jsonrpc"]). %%---------------------------------------------------------------------------- -ifdef(use_specs). -spec(memory/0 :: () -> rabbit_types:infos()). --spec(interval_operation/3 :: - (fun (() -> any()), non_neg_integer(), non_neg_integer()) - -> {any(), non_neg_integer()}). + -endif. %%---------------------------------------------------------------------------- %% Like erlang:memory(), but with awareness of rabbit-y things memory() -> - ConnChs = sup_memory(rabbit_tcp_client_sup) + + Conns = sup_memory(rabbit_tcp_client_sup) + sup_memory(ssl_connection_sup) + sup_memory(amqp_sup), Qs = sup_memory(rabbit_amqqueue_sup) + sup_memory(rabbit_mirror_queue_slave_sup), @@ -53,37 +52,26 @@ memory() -> {code, Code}, {system, System}] = erlang:memory([total, processes, ets, atom, binary, code, system]), - OtherProc = Processes - ConnChs - Qs - MsgIndexProc - MgmtDbProc - Plugins, - [{total, Total}, - {connection_channel_procs, ConnChs}, - {queue_procs, Qs}, - {plugins, Plugins}, - {other_proc, lists:max([0, OtherProc])}, %% [1] - {mnesia, Mnesia}, - {mgmt_db, MgmtDbETS + MgmtDbProc}, - {msg_index, MsgIndexETS + MsgIndexProc}, - {other_ets, ETS - Mnesia - MsgIndexETS - MgmtDbETS}, - {binary, Bin}, - {code, Code}, - {atom, Atom}, - {other_system, System - ETS - Atom - Bin - Code}]. + OtherProc = Processes - Conns - Qs - MsgIndexProc - MgmtDbProc - Plugins, + [{total, Total}, + {connection_procs, Conns}, + {queue_procs, Qs}, + {plugins, Plugins}, + {other_proc, lists:max([0, OtherProc])}, %% [1] + {mnesia, Mnesia}, + {mgmt_db, MgmtDbETS + MgmtDbProc}, + {msg_index, MsgIndexETS + MsgIndexProc}, + {other_ets, ETS - Mnesia - MsgIndexETS - MgmtDbETS}, + {binary, Bin}, + {code, Code}, + {atom, Atom}, + {other_system, System - ETS - Atom - Bin - Code}]. %% [1] - erlang:memory(processes) can be less than the sum of its %% parts. Rather than display something nonsensical, just silence any %% claims about negative memory. See %% http://erlang.org/pipermail/erlang-questions/2012-September/069320.html - -%% Ideally, you'd want Fun to run every IdealInterval. but you don't -%% want it to take more than MaxTime per IdealInterval. So if it takes -%% more then you want to run it less often. So we time how long it -%% takes to run, and then suggest how long you should wait before -%% running it again. Times are in millis. -interval_operation(Fun, MaxTime, IdealInterval) -> - {Micros, Res} = timer:tc(Fun), - Ratio = lists:max([1, Micros / MaxTime / 1000]), - {Res, round(IdealInterval * Ratio)}. - %%---------------------------------------------------------------------------- sup_memory(Sup) -> @@ -121,7 +109,7 @@ bytes(Words) -> Words * erlang:system_info(wordsize). plugins_memory() -> lists:sum([plugin_memory(App) || {App, _, _} <- application:which_applications(), - is_plugin(App)]). + is_plugin(atom_to_list(App))]). plugin_memory(App) -> case catch application_master:get_child( @@ -130,6 +118,5 @@ plugin_memory(App) -> _ -> 0 end. -is_plugin(App) -> - lists:member(App, ?MAGIC_PLUGINS) orelse - string:left(atom_to_list(App), 9) =:= "rabbitmq_". +is_plugin("rabbitmq_" ++ _) -> true; +is_plugin(App) -> lists:member(App, ?MAGIC_PLUGINS). |