couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 02/02: FIXUP: Don't send possibly large messages
Date Mon, 10 Jul 2017 19:59:35 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch optimize-ddoc-cache
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit a0ae3d67ecabba066697215e932869a9a0b8f520
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Mon Jul 10 14:56:59 2017 -0500

    FIXUP: Don't send possibly large messages
    
    User design documents can be fairly large which could end up crushing
    the ddoc_cache_lru mailbox. This just converts the possibly large values
    to binaries before sending them.
---
 src/ddoc_cache/src/ddoc_cache_entry.erl |  5 +++--
 src/ddoc_cache/src/ddoc_cache_lru.erl   |  3 ++-
 src/ddoc_cache/src/ddoc_cache_value.erl | 27 +++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl
index 38bc961..f40ac40 100644
--- a/src/ddoc_cache/src/ddoc_cache_entry.erl
+++ b/src/ddoc_cache/src/ddoc_cache_entry.erl
@@ -116,7 +116,8 @@ init({Key, undefined}) ->
     ?EVENT(started, Key),
     gen_server:enter_loop(?MODULE, [], St);
 
-init({Key, Default}) ->
+init({Key, Wrapped}) ->
+    Default = ddoc_cache_value:unwrap(Wrapped),
     Updates = [
         {#entry.val, Default},
         {#entry.pid, self()}
@@ -133,7 +134,7 @@ init({Key, Default}) ->
         accessed = 1
     },
     ?EVENT(default_started, Key),
-    gen_server:enter_loop(?MODULE, [], St).
+    gen_server:enter_loop(?MODULE, [], St, hibernate).
 
 
 terminate(_Reason, St) ->
diff --git a/src/ddoc_cache/src/ddoc_cache_lru.erl b/src/ddoc_cache/src/ddoc_cache_lru.erl
index 49aa62d..12f5d10 100644
--- a/src/ddoc_cache/src/ddoc_cache_lru.erl
+++ b/src/ddoc_cache/src/ddoc_cache_lru.erl
@@ -72,7 +72,8 @@ open(Key) ->
 insert(Key, Value) ->
     case ets:lookup(?CACHE, Key) of
         [] ->
-            gen_server:call(?MODULE, {start, Key, Value}, infinity);
+            Wrapped = ddoc_cache_value:wrap(Value),
+            gen_server:call(?MODULE, {start, Key, Wrapped}, infinity);
         [#entry{}] ->
             ok
     end.
diff --git a/src/ddoc_cache/src/ddoc_cache_value.erl b/src/ddoc_cache/src/ddoc_cache_value.erl
new file mode 100644
index 0000000..21a5bb5
--- /dev/null
+++ b/src/ddoc_cache/src/ddoc_cache_value.erl
@@ -0,0 +1,27 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(ddoc_cache_value).
+
+
+-export([
+    wrap/1,
+    unwrap/1
+]).
+
+
+wrap(Value) ->
+    {?MODULE, term_to_binary(Value)}.
+
+
+unwrap({?MODULE, Bin}) when is_binary(Bin) ->
+    binary_to_term(Bin).

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <commits@couchdb.apache.org>.

Mime
View raw message