From 879ebf388947c86928400ceeba2194c91eaec89f Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Wed, 19 Sep 2018 14:39:09 -0500 Subject: Set a high priority on 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. --- rel/overlay/etc/default.ini | 7 ++++++- src/couch/src/couch_server.erl | 1 + src/couch/src/couch_util.erl | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) 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} -> -- cgit v1.2.1