From f040d7531273ce77754ab29e08506951ee228fd6 Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Mon, 18 Jun 2018 12:34:02 -0500 Subject: 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. --- src/couch/src/couch_util.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) 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} -> -- cgit v1.2.1