diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2012-09-27 15:45:48 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2012-09-27 15:45:48 +0100 |
| commit | f06a17d60713b1bd8d801445608921d8649855d6 (patch) | |
| tree | 00c3f5b40ecad5aa113b7a22080f4069923a9cdc /src | |
| parent | 92822c51ca66b296ce7c09e435dd3a8b648f606f (diff) | |
| download | rabbitmq-server-git-f06a17d60713b1bd8d801445608921d8649855d6.tar.gz | |
interval_operation/3
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_vm.erl | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/rabbit_vm.erl b/src/rabbit_vm.erl index cc9d963545..9f9b9fbe2f 100644 --- a/src/rabbit_vm.erl +++ b/src/rabbit_vm.erl @@ -16,7 +16,7 @@ -module(rabbit_vm). --export([memory/0]). +-export([memory/0, interval_operation/3]). -define(MAGIC_PLUGINS, [mochiweb, webmachine, cowboy, sockjs, rfc4627_jsonrpc]). @@ -25,7 +25,9 @@ -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. %%---------------------------------------------------------------------------- @@ -71,6 +73,17 @@ memory() -> %% 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) -> |
