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.
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 9a8c70b..a1df080 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -93,6 +93,11 @@
 ; 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
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index a72627b..909e238 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -235,6 +235,7 @@
 
 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 e2885a1..b5c93ce 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 @@
     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} ->