summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2018-06-18 12:34:02 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2018-06-19 09:28:14 -0500
commitf040d7531273ce77754ab29e08506951ee228fd6 (patch)
treed69a58219f2180aab9cea396fa5a81032fff6049
parent3c9838528972ec55165fdd98bc70cec0bff4db3d (diff)
downloadcouchdb-f040d7531273ce77754ab29e08506951ee228fd6.tar.gz
Add set_mqd_off_heap utility function
In Erlang VMs starting with version 19.0 have a new process_flag to store messages off the process heap. This is extremely useful for processes that can have huge numbers of messages in their mailbox. For CouchDB this is most usually observed when couch_server backs up with a large message queue which wedges the entire node. This utility function will set a process's message_queue_data flag to off_heap in a way that doesn't break builds of CouchDB on older Erlang VMs while automatically enabling the flag on VMs that do support it.
-rw-r--r--src/couch/src/couch_util.erl10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/couch/src/couch_util.erl b/src/couch/src/couch_util.erl
index f3a9249f7..af1c0ef87 100644
--- a/src/couch/src/couch_util.erl
+++ b/src/couch/src/couch_util.erl
@@ -37,6 +37,7 @@
-export([unique_monotonic_integer/0]).
-export([check_config_blacklist/1]).
-export([check_md5/2]).
+-export([set_mqd_off_heap/0]).
-include_lib("couch/include/couch_db.hrl").
@@ -639,6 +640,15 @@ check_md5(Sig, Sig) -> ok;
check_md5(_, _) -> throw(md5_mismatch).
+set_mqd_off_heap() ->
+ try
+ erlang:process_flag(message_queue_data, off_heap),
+ ok
+ catch error:badarg ->
+ ok
+ end.
+
+
ensure_loaded(Module) when is_atom(Module) ->
case code:ensure_loaded(Module) of
{module, Module} ->