From dev-return-80218-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Sun Apr 14 15:20:05 2019 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 [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 2E34D180638 for ; Sun, 14 Apr 2019 17:20:05 +0200 (CEST) Received: (qmail 50289 invoked by uid 500); 14 Apr 2019 15:20:01 -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 50265 invoked by uid 99); 14 Apr 2019 15:20:01 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Apr 2019 15:20:01 +0000 Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 693C4E02FD for ; Sun, 14 Apr 2019 15:20:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 157B524593 for ; Sun, 14 Apr 2019 15:20:00 +0000 (UTC) Date: Sun, 14 Apr 2019 15:20:00 +0000 (UTC) From: "David Mollitor (JIRA)" To: dev@zookeeper.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (ZOOKEEPER-3365) Use Concurrent HashMap in NettyServerCnxnFactory MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/ZOOKEEPER-3365?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] David Mollitor updated ZOOKEEPER-3365: -------------------------------------- Description: {code:java|title=NettyServerCnxnFactory.java} // Access to ipMap or to any Set contained in the map needs to be // protected with synchronized (ipMap) { ... } private final Map> ipMap = new HashMap<>(); private void addCnxn(NettyServerCnxn cnxn) { cnxns.add(cnxn); synchronized (ipMap){ InetAddress addr = ((InetSocketAddress)cnxn.getChannel().remoteAddress()).getAddress(); Set s = ipMap.get(addr); if (s == null) { s = new HashSet<>(); ipMap.put(addr, s); } s.add(cnxn); } } {code} This can be done better (less code, less contention) with Java 8 Map API. Although, as I look at this, the only thing this is used for is a count of the number of connections from each address. Maybe this should just store a count instead of a collection. https://github.com/apache/zookeeper/blob/f69ad1b0fed88da3c1b67fd73031e7248c0564f7/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java Also note that an exclusive lock is required with each interaction of the table. By moving to a {{ConcurrentHashMap}}: bq. Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove). https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html Removing this lock should improve ZK's performance for highly concurrent client workloads, especially since its Async Netty operations, unless of course there are other locks elsewhere. was: {code:java|title=NettyServerCnxnFactory.java} // Access to ipMap or to any Set contained in the map needs to be // protected with synchronized (ipMap) { ... } private final Map> ipMap = new HashMap<>(); private void addCnxn(NettyServerCnxn cnxn) { cnxns.add(cnxn); synchronized (ipMap){ InetAddress addr = ((InetSocketAddress)cnxn.getChannel().remoteAddress()).getAddress(); Set s = ipMap.get(addr); if (s == null) { s = new HashSet<>(); ipMap.put(addr, s); } s.add(cnxn); } } {code} This can be done better (less code, less contention) with Java 8 Map API. Although, as I look at this, the only thing this is used for is a count of the number of connections from each address. Maybe this should just store a count instead of a collection. https://github.com/apache/zookeeper/blob/f69ad1b0fed88da3c1b67fd73031e7248c0564f7/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java > Use Concurrent HashMap in NettyServerCnxnFactory > ------------------------------------------------- > > Key: ZOOKEEPER-3365 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-3365 > Project: ZooKeeper > Issue Type: Improvement > Components: server > Affects Versions: 3.6.0 > Reporter: David Mollitor > Assignee: David Mollitor > Priority: Minor > Labels: pull-request-available > Fix For: 3.6.0 > > Time Spent: 1.5h > Remaining Estimate: 0h > > {code:java|title=NettyServerCnxnFactory.java} > // Access to ipMap or to any Set contained in the map needs to be > // protected with synchronized (ipMap) { ... } > private final Map> ipMap = new HashMap<>(); > private void addCnxn(NettyServerCnxn cnxn) { > cnxns.add(cnxn); > synchronized (ipMap){ > InetAddress addr = > ((InetSocketAddress)cnxn.getChannel().remoteAddress()).getAddress(); > Set s = ipMap.get(addr); > if (s == null) { > s = new HashSet<>(); > ipMap.put(addr, s); > } > s.add(cnxn); > } > } > {code} > This can be done better (less code, less contention) with Java 8 Map API. Although, as I look at this, the only thing this is used for is a count of the number of connections from each address. Maybe this should just store a count instead of a collection. > https://github.com/apache/zookeeper/blob/f69ad1b0fed88da3c1b67fd73031e7248c0564f7/zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java > Also note that an exclusive lock is required with each interaction of the table. By moving to a {{ConcurrentHashMap}}: > bq. Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove). > https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html > Removing this lock should improve ZK's performance for highly concurrent client workloads, especially since its Async Netty operations, unless of course there are other locks elsewhere. -- This message was sent by Atlassian JIRA (v7.6.3#76005)