From dev-return-75389-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Fri Nov 2 07:00:50 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 8F79318062B for ; Fri, 2 Nov 2018 07:00:50 +0100 (CET) Received: (qmail 14429 invoked by uid 500); 2 Nov 2018 06:00:49 -0000 Mailing-List: contact dev-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list dev@zookeeper.apache.org Received: (qmail 14418 invoked by uid 99); 2 Nov 2018 06:00:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Nov 2018 06:00:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A82E2DFD77; Fri, 2 Nov 2018 06:00:48 +0000 (UTC) From: hanm To: dev@zookeeper.apache.org Reply-To: dev@zookeeper.apache.org References: In-Reply-To: Subject: [GitHub] zookeeper pull request #673: [ZOOKEEPER-3177] Refactor request throttle logi... Content-Type: text/plain Message-Id: <20181102060048.A82E2DFD77@git1-us-west.apache.org> Date: Fri, 2 Nov 2018 06:00:48 +0000 (UTC) Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/673#discussion_r230276535 --- Diff: zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerCnxn.java --- @@ -68,8 +68,39 @@ private volatile boolean stale = false; + AtomicLong outstandingCount = new AtomicLong(); + + /** The ZooKeeperServer for this connection. May be null if the server + * is not currently serving requests (for example if the server is not + * an active quorum participant. + */ + final ZooKeeperServer zkServer; + + public ServerCnxn(final ZooKeeperServer zkServer) { + this.zkServer = zkServer; + } + abstract int getSessionTimeout(); + public void incrOutstandingAndCheckThrottle(RequestHeader h) { + if (h.getXid() <= 0) { + return; + } + if (zkServer.shouldThrottle(outstandingCount.incrementAndGet())) { + disableRecv(false); + } + } + + // will be called from zkServer.processPacket + public void decrOutstandingAndCheckThrottle(ReplyHeader h) { --- End diff -- This is a good suggestion. This PR focus on consolidating and refactoring existing logic, and we usually prefer doing one thing at a time (so the patch is easier to review and land). Feel free to fire a PR for improvements after this patch is merged! ---