summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2018-09-19 14:39:09 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2020-01-04 15:50:25 -0600
commit879ebf388947c86928400ceeba2194c91eaec89f (patch)
tree5374009216c397eec2c1b52e0b45bd7cf5df5719
parent2c38bda5911de75c50db844fb05a87163513e7f6 (diff)
downloadcouchdb-optimize-couch-server.tar.gz
Set a high priority on couch_serveroptimize-couch-server
In a VM with lots of processes couch_server can end up slowing down purely to not being scheduled which in turn will cause its message queue to backup. We've attempted this before but due to message passing have never seen it have a significant effect. However, now that we're actively avoiding synchronous message passing inside the man loop this has a significant effect by being able to process messages as soon as it has one in its mailbox.
-rw-r--r--rel/overlay/etc/default.ini7
-rw-r--r--src/couch/src/couch_server.erl1
-rw-r--r--src/couch/src/couch_util.erl11
3 files changed, 18 insertions, 1 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 7bfbbe941..4f49cb6d2 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -90,6 +90,11 @@ users_db_security_editable = false
; having to ask every configured engine.
couch = couch_bt_engine
+[process_priority]
+; Selectively disable altering process priorities
+; for modules that request it.
+; couch_server = true
+
[cluster]
q=2
n=3
@@ -522,4 +527,4 @@ min_priority = 2.0
; value will be rejected. If this config setting is not defined,
; CouchDB will use the value of `max_limit` instead. If neither is
; defined, the default is 2000 as stated here.
-; max_limit_partitions = 2000 \ No newline at end of file
+; max_limit_partitions = 2000
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 2919ed524..d70fd0b92 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -229,6 +229,7 @@ close_db_if_idle(DbName) ->
init([]) ->
couch_util:set_mqd_off_heap(?MODULE),
+ couch_util:set_process_priority(?MODULE, high),
% Mark pluggable storage engines as a supported feature
config:enable_feature('pluggable-storage-engines'),
diff --git a/src/couch/src/couch_util.erl b/src/couch/src/couch_util.erl
index e2885a15e..b5c93ce51 100644
--- a/src/couch/src/couch_util.erl
+++ b/src/couch/src/couch_util.erl
@@ -39,6 +39,7 @@
-export([check_config_blacklist/1]).
-export([check_md5/2]).
-export([set_mqd_off_heap/1]).
+-export([set_process_priority/2]).
-include_lib("couch/include/couch_db.hrl").
@@ -690,6 +691,16 @@ set_mqd_off_heap(Module) ->
end.
+set_process_priority(Module, Level) ->
+ case config:get_boolean("process_priority", atom_to_list(Module), true) of
+ true ->
+ process_flag(priority, Level),
+ ok;
+ false ->
+ ok
+ end.
+
+
ensure_loaded(Module) when is_atom(Module) ->
case code:ensure_loaded(Module) of
{module, Module} ->