diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2018-09-06 17:31:34 -0400 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2018-09-06 18:27:40 -0400 |
commit | ee3c4b5d2e58e35a11e6995d47580554a7d7aca8 (patch) | |
tree | 8b26267365d9aa2fb599725d70108375257179c3 | |
parent | f66c734d3c056b6b391f8f8487a7d81c1d55b87f (diff) | |
download | couchdb-ee3c4b5d2e58e35a11e6995d47580554a7d7aca8.tar.gz |
Allow disabling off-heap messages
Off-heap messages is an Erlang 19 feature:
http://erlang.org/doc/man/erlang.html#process_flag_message_queue_data
It is adviseable to use that setting for processes which expect to receive a
lot of messages. CouchDB sets it for couch_server, couch_log_server and bunch
of others as well.
In some cases the off-heap behavior could alter the timing of message receives
and expose subtle bugs that have been lurking in the code for years. Or could
slightly reduce performance, so a safety measure allow disabling it.
-rw-r--r-- | src/couch/src/couch_server.erl | 2 | ||||
-rw-r--r-- | src/couch/src/couch_util.erl | 19 | ||||
-rw-r--r-- | src/couch_log/src/couch_log_server.erl | 2 | ||||
-rw-r--r-- | src/ddoc_cache/src/ddoc_cache_lru.erl | 2 | ||||
-rw-r--r-- | src/mem3/src/mem3_shards.erl | 2 | ||||
-rw-r--r-- | src/rexi/src/rexi_server.erl | 2 |
6 files changed, 17 insertions, 12 deletions
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl index 72105202c..50c8caee5 100644 --- a/src/couch/src/couch_server.erl +++ b/src/couch/src/couch_server.erl @@ -211,7 +211,7 @@ close_db_if_idle(DbName) -> init([]) -> - couch_util:set_mqd_off_heap(), + couch_util:set_mqd_off_heap(?MODULE), % 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 936b562e1..8f25edc9c 100644 --- a/src/couch/src/couch_util.erl +++ b/src/couch/src/couch_util.erl @@ -37,7 +37,7 @@ -export([unique_monotonic_integer/0]). -export([check_config_blacklist/1]). -export([check_md5/2]). --export([set_mqd_off_heap/0]). +-export([set_mqd_off_heap/1]). -include_lib("couch/include/couch_db.hrl"). @@ -670,12 +670,17 @@ 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 +set_mqd_off_heap(Module) -> + case config:get_boolean("off_heap_mqd", atom_to_list(Module), true) of + true -> + try + erlang:process_flag(message_queue_data, off_heap), + ok + catch error:badarg -> + ok + end; + false -> + ok end. diff --git a/src/couch_log/src/couch_log_server.erl b/src/couch_log/src/couch_log_server.erl index ea5def891..8432b9aa3 100644 --- a/src/couch_log/src/couch_log_server.erl +++ b/src/couch_log/src/couch_log_server.erl @@ -58,7 +58,7 @@ log(Entry) -> init(_) -> - couch_util:set_mqd_off_heap(), + couch_util:set_mqd_off_heap(?MODULE), process_flag(trap_exit, true), {ok, #st{ writer = couch_log_writer:init() diff --git a/src/ddoc_cache/src/ddoc_cache_lru.erl b/src/ddoc_cache/src/ddoc_cache_lru.erl index 248a76dc8..28a8a64c4 100644 --- a/src/ddoc_cache/src/ddoc_cache_lru.erl +++ b/src/ddoc_cache/src/ddoc_cache_lru.erl @@ -87,7 +87,7 @@ refresh(DbName, DDocIds) -> init(_) -> - couch_util:set_mqd_off_heap(), + couch_util:set_mqd_off_heap(?MODULE), process_flag(trap_exit, true), BaseOpts = [public, named_table], CacheOpts = [ diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl index da3b69a61..183f28fef 100644 --- a/src/mem3/src/mem3_shards.erl +++ b/src/mem3/src/mem3_shards.erl @@ -184,7 +184,7 @@ handle_config_terminate(_Server, _Reason, _State) -> erlang:send_after(?RELISTEN_DELAY, whereis(?MODULE), restart_config_listener). init([]) -> - couch_util:set_mqd_off_heap(), + couch_util:set_mqd_off_heap(?MODULE), ets:new(?SHARDS, [ bag, public, diff --git a/src/rexi/src/rexi_server.erl b/src/rexi/src/rexi_server.erl index 954ca88cb..58a510b68 100644 --- a/src/rexi/src/rexi_server.erl +++ b/src/rexi/src/rexi_server.erl @@ -39,7 +39,7 @@ start_link(ServerId) -> gen_server:start_link({local, ServerId}, ?MODULE, [], []). init([]) -> - couch_util:set_mqd_off_heap(), + couch_util:set_mqd_off_heap(?MODULE), {ok, #st{}}. handle_call(get_errors, _From, #st{errors = Errors} = St) -> |