You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2014/10/13 19:21:38 UTC

[1/2] git commit: Update state on config changes

Repository: couchdb-ioq
Updated Branches:
  refs/heads/master c7f9ad1c0 -> c552c665d


Update state on config changes


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/commit/40d157f3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/tree/40d157f3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/diff/40d157f3

Branch: refs/heads/master
Commit: 40d157f39c0fa0d80db9ccf61b770b72103ddbed
Parents: c7f9ad1
Author: Alexander Shorin <kx...@apache.org>
Authored: Mon Sep 22 17:32:44 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Oct 13 21:21:02 2014 +0400

----------------------------------------------------------------------
 src/ioq.erl | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ioq/blob/40d157f3/src/ioq.erl
----------------------------------------------------------------------
diff --git a/src/ioq.erl b/src/ioq.erl
index b761a0b..9bfb1f8 100644
--- a/src/ioq.erl
+++ b/src/ioq.erl
@@ -12,10 +12,14 @@
 
 -module(ioq).
 -behaviour(gen_server).
+-behaviour(config_listener).
 
 -export([start_link/0, call/3]).
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
 
+% config_listener api
+-export([handle_config_change/5]).
+
 -record(state, {
     concurrency=10,
     ratio,
@@ -45,12 +49,19 @@ call(Fd, Msg, Priority) ->
     end.
 
 init(_) ->
+    ok = config:listen_for_changes(?MODULE, nil),
+    State = #state{},
+    {ok, read_config(State)}.
+
+read_config(State) ->
     Ratio = list_to_float(config:get("ioq", "ratio", "0.01")),
-    {ok, #state{ratio=Ratio}}.
+    State#state{ratio=Ratio}.
 
 handle_call(#request{}=Request, From, State) ->
     {noreply, enqueue_request(Request#request{from=From}, State), 0}.
 
+handle_cast(change, State) ->
+    {noreply, read_config(State)};
 handle_cast(_Msg, State) ->
     {noreply, State}.
 
@@ -76,6 +87,11 @@ handle_info({'DOWN', Ref, _, _, Reason}, State) ->
 handle_info(timeout, State) ->
     {noreply, maybe_submit_request(State)}.
 
+handle_config_change("ioq", _, _, _, _) ->
+    {ok, gen_server:cast(?MODULE, change)};
+handle_config_change(_, _, _, _, _) ->
+    {ok, nil}.
+
 code_change(_Vsn, State, _Extra) ->
     {ok, State}.
 


[2/2] git commit: Allow to customize concurrency value

Posted by kx...@apache.org.
Allow to customize concurrency value


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/commit/c552c665
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/tree/c552c665
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ioq/diff/c552c665

Branch: refs/heads/master
Commit: c552c665dc6af0ca750ce074c816c4fcb0f05962
Parents: 40d157f
Author: Alexander Shorin <kx...@apache.org>
Authored: Mon Sep 22 17:35:37 2014 +0400
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Oct 13 21:21:03 2014 +0400

----------------------------------------------------------------------
 src/ioq.erl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ioq/blob/c552c665/src/ioq.erl
----------------------------------------------------------------------
diff --git a/src/ioq.erl b/src/ioq.erl
index 9bfb1f8..4598c37 100644
--- a/src/ioq.erl
+++ b/src/ioq.erl
@@ -21,7 +21,7 @@
 -export([handle_config_change/5]).
 
 -record(state, {
-    concurrency=10,
+    concurrency,
     ratio,
     interactive=queue:new(),
     compaction=queue:new(),
@@ -55,7 +55,8 @@ init(_) ->
 
 read_config(State) ->
     Ratio = list_to_float(config:get("ioq", "ratio", "0.01")),
-    State#state{ratio=Ratio}.
+    Concurrency = list_to_integer(config:get("ioq", "concurrency", "10")),
+    State#state{concurrency=Concurrency, ratio=Ratio}.
 
 handle_call(#request{}=Request, From, State) ->
     {noreply, enqueue_request(Request#request{from=From}, State), 0}.