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 18B0011CCF for ; Wed, 6 Aug 2014 18:17:53 +0000 (UTC) Received: (qmail 97214 invoked by uid 500); 6 Aug 2014 18:17:52 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 96992 invoked by uid 500); 6 Aug 2014 18:17:52 -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 96506 invoked by uid 99); 6 Aug 2014 18:17:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Aug 2014 18:17:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id AD35492486E; Wed, 6 Aug 2014 18:17:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org Date: Wed, 06 Aug 2014 18:18:07 -0000 Message-Id: <7f7f370aee3c4ac4a3e2626e32fcfac3@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [17/27] couch-replicator commit: updated refs/heads/windsor-merge to 75e5ba1 Rate limit the retrieval of pending changes This limits the update of the changes_pending field to once every `connection_timeout` milliseconds. BugzId: 26015 Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/06cf6995 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/06cf6995 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/06cf6995 Branch: refs/heads/windsor-merge Commit: 06cf69957b1bb0272cc4a0e679275bab8c7a16d1 Parents: f10dec7 Author: Paul J. Davis Authored: Wed Dec 11 10:08:23 2013 -0600 Committer: Robert Newson Committed: Tue Jul 29 15:17:38 2014 +0100 ---------------------------------------------------------------------- src/couch_replicator.erl | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/06cf6995/src/couch_replicator.erl ---------------------------------------------------------------------- diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl index 8041283..82c1360 100644 --- a/src/couch_replicator.erl +++ b/src/couch_replicator.erl @@ -875,7 +875,28 @@ db_monitor(_HttpDb) -> nil. -get_pending_count(#rep_state{source = #httpdb{} = Db0}=St) -> +get_pending_count(St) -> + Rep = St#rep_state.rep_details, + Timeout = get_value(connection_timeout, Rep#rep.options), + TimeoutMicro = Timeout * 1000, + case get(pending_count_state) of + {LastUpdate, PendingCount} -> + case timer:now_diff(os:timestamp(), LastUpdate) > TimeoutMicro of + true -> + NewPendingCount = get_pending_count_int(St), + put(pending_count_state, {os:timestamp(), NewPendingCount}), + NewPendingCount; + false -> + PendingCount + end; + undefined -> + NewPendingCount = get_pending_count_int(St), + put(pending_count_state, {os:timestamp(), NewPendingCount}), + NewPendingCount + end. + + +get_pending_count_int(#rep_state{source = #httpdb{} = Db0}=St) -> {_, Seq} = St#rep_state.highest_seq_done, Db = Db0#httpdb{retries = 3}, case (catch couch_replicator_api_wrap:get_pending_count(Db, Seq)) of @@ -884,7 +905,7 @@ get_pending_count(#rep_state{source = #httpdb{} = Db0}=St) -> _ -> null end; -get_pending_count(#rep_state{source = Db}=St) -> +get_pending_count_int(#rep_state{source = Db}=St) -> {_, Seq} = St#rep_state.highest_seq_done, {ok, Pending} = couch_replicator_api_wrap:get_pending_count(Db, Seq), Pending.