From commits-return-29944-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Mon Jul 10 18:29:28 2017 Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0FECC1ADBE for ; Mon, 10 Jul 2017 18:29:28 +0000 (UTC) Received: (qmail 78678 invoked by uid 500); 10 Jul 2017 18:29:27 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 78618 invoked by uid 500); 10 Jul 2017 18:29:27 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 78436 invoked by uid 99); 10 Jul 2017 18:29:27 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2017 18:29:27 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id B55B1811C1; Mon, 10 Jul 2017 18:29:24 +0000 (UTC) Date: Mon, 10 Jul 2017 18:29:35 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 12/17: FIXUP: Make the refresh timeout configurable MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: davisp@apache.org Reply-To: "commits@couchdb.apache.org" In-Reply-To: <149971136380.14618.6535268986419846198@gitbox.apache.org> References: <149971136380.14618.6535268986419846198@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/optimize-ddoc-cache X-Git-Reftype: branch X-Git-Rev: cd3687ac39ef42e602de5b8e35f169efc8d3fe1a X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20170710182924.B55B1811C1@gitbox.apache.org> 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 cd3687ac39ef42e602de5b8e35f169efc8d3fe1a Author: Paul J. Davis AuthorDate: Thu Jul 6 14:11:13 2017 -0500 FIXUP: Make the refresh timeout configurable --- rel/overlay/etc/default.ini | 8 ++++++++ src/ddoc_cache/src/ddoc_cache_entry.erl | 13 ++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini index eaa0801..be178e2 100644 --- a/rel/overlay/etc/default.ini +++ b/rel/overlay/etc/default.ini @@ -188,6 +188,14 @@ credentials = false ; List of accepted methods ; methods = +; Configuration for the design document cache +;[ddoc_cache] +; The maximum number of entries to keep in the cache +;max_size = 1000 +; The period each cache entry should wait before +; automatically refreshing in milliseconds +;refresh_timeout = 67000 + [x_frame_options] ; Settings same-origin will return X-Frame-Options: SAMEORIGIN. ; If same origin is set, it will ignore the hosts setting diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl index 79c3dcf..db5e0b1 100644 --- a/src/ddoc_cache/src/ddoc_cache_entry.erl +++ b/src/ddoc_cache/src/ddoc_cache_entry.erl @@ -123,11 +123,10 @@ init({Key, Default}) -> NewTs = os:timestamp(), true = ets:update_element(?CACHE, Key, Updates), true = ets:insert(?LRU, {{NewTs, Key, self()}}), - Msg = {'$gen_cast', refresh}, St = #st{ key = Key, val = {open_ok, {ok, Default}}, - opener = erlang:send_after(?REFRESH_TIMEOUT, self(), Msg), + opener = start_timer(), waiters = undefined, ts = NewTs, accessed = 1 @@ -230,11 +229,9 @@ handle_info({'DOWN', _, _, Pid, Resp}, #st{key = Key, opener = Pid} = St) -> case Resp of {open_ok, Key, {ok, Val}} -> update_cache(St, Val), - Msg = {'$gen_cast', refresh}, - Timer = erlang:send_after(?REFRESH_TIMEOUT, self(), Msg), NewSt1 = St#st{ val = {open_ok, {ok, Val}}, - opener = Timer + opener = start_timer() }, NewSt2 = update_lru(NewSt1), if not is_list(St#st.waiters) -> ok; true -> @@ -267,6 +264,12 @@ spawn_opener(Key) -> Pid. +start_timer() -> + TimeOut = config:get_integer( + "ddoc_cache", "refresh_timeout", ?REFRESH_TIMEOUT), + erlang:send_after(TimeOut, self(), {'$gen_cast', refresh}). + + do_open(Key) -> try recover(Key) of Resp -> -- To stop receiving notification emails like this one, please contact "commits@couchdb.apache.org" .