zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Mollitor (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (ZOOKEEPER-3365) Use Concurrent HashMap in NettyServerCnxnFactory
Date Sun, 14 Apr 2019 03:02:00 GMT

     [ https://issues.apache.org/jira/browse/ZOOKEEPER-3365?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

David Mollitor updated ZOOKEEPER-3365:
--------------------------------------
    Summary: Use Concurrent HashMap in NettyServerCnxnFactory   (was: Use New Concurrent HashMap
in NettyServerCnxnFactory )

> 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
>             Fix For: 3.6.0
>
>
> {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<InetAddress, Set<NettyServerCnxn>> ipMap = new HashMap<>();
>     private void addCnxn(NettyServerCnxn cnxn) {
>         cnxns.add(cnxn);
>         synchronized (ipMap){
>             InetAddress addr =
>                 ((InetSocketAddress)cnxn.getChannel().remoteAddress()).getAddress();
>             Set<NettyServerCnxn> 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



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message