summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-13 10:29:13 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-13 10:29:13 +0100
commitf9d2b2387e82170bb19e58df1e425942c1d240eb (patch)
tree3ab9d69902976f935d98135f9dc7bfcf05e28388
parent3f3e75b835347f7eaf6c13bd25efbffb6a050fe5 (diff)
downloadrabbitmq-server-f9d2b2387e82170bb19e58df1e425942c1d240eb.tar.gz
add a dedicated process for running io actions
-rw-r--r--src/file2.erl2
-rw-r--r--src/io_runner.erl83
-rw-r--r--src/rabbit.erl6
3 files changed, 90 insertions, 1 deletions
diff --git a/src/file2.erl b/src/file2.erl
index b20c7d91..d9ee1da8 100644
--- a/src/file2.erl
+++ b/src/file2.erl
@@ -900,7 +900,7 @@ mode_list(_) ->
%% Functions for communicating with the file server
call(Command, Args) when is_list(Args) ->
- worker_pool:submit(
+ io_runner:submit(
fun () ->
gen_server:call(?FILE_SERVER, list_to_tuple([Command | Args]),
infinity)
diff --git a/src/io_runner.erl b/src/io_runner.erl
new file mode 100644
index 00000000..8a252158
--- /dev/null
+++ b/src/io_runner.erl
@@ -0,0 +1,83 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is VMware, Inc.
+%% Copyright (c) 2011 VMware, Inc. All rights reserved.
+%%
+
+-module(io_runner).
+
+-behaviour(gen_server2).
+
+-export([start_link/0, submit/1]).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+%%----------------------------------------------------------------------------
+
+-ifdef(use_specs).
+
+-spec(start_link/0 :: () -> {'ok', pid()} | {'error', any()}).
+-spec(submit/1 :: (fun (() -> A) | {atom(), atom(), [any()]}) -> A).
+
+-endif.
+
+%%----------------------------------------------------------------------------
+
+-define(SERVER, ?MODULE).
+-define(HIBERNATE_AFTER_MIN, 1000).
+-define(DESIRED_HIBERNATE, 10000).
+
+%%----------------------------------------------------------------------------
+
+start_link() ->
+ gen_server2:start_link({local, ?SERVER}, ?MODULE, [],
+ [{timeout, infinity}]).
+
+submit(Fun) ->
+ %% If the io_runner is not running, just run the Fun in the
+ %% current process.
+ case whereis(?SERVER) of
+ undefined -> run(Fun);
+ _ -> gen_server2:call(?SERVER, {run, Fun}, infinity)
+ end.
+
+%%----------------------------------------------------------------------------
+
+init([]) ->
+ {ok, nostate, hibernate,
+ {backoff, ?HIBERNATE_AFTER_MIN, ?HIBERNATE_AFTER_MIN, ?DESIRED_HIBERNATE}}.
+
+handle_call({run, Fun}, _From, State) ->
+ {reply, run(Fun), State, hibernate};
+handle_call(Msg, _From, State) ->
+ {stop, {unexpected_call, Msg}, State}.
+
+handle_cast(Msg, State) ->
+ {stop, {unexpected_cast, Msg}, State}.
+
+handle_info(Msg, State) ->
+ {stop, {unexpected_info, Msg}, State}.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+terminate(_Reason, State) ->
+ State.
+
+%%----------------------------------------------------------------------------
+
+run({M, F, A}) ->
+ apply(M, F, A);
+run(Fun) ->
+ Fun().
diff --git a/src/rabbit.erl b/src/rabbit.erl
index b8dbccc7..ffa40583 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -58,6 +58,12 @@
{requires, pre_boot},
{enables, external_infrastructure}]}).
+-rabbit_boot_step({io_runner,
+ [{description, "IO runner"},
+ {mfa, {rabbit_sup, start_child, [io_runner]}},
+ {requires, pre_boot},
+ {enables, external_infrastructure}]}).
+
-rabbit_boot_step({external_infrastructure,
[{description, "external infrastructure ready"}]}).