[ https://issues.apache.org/jira/browse/ZOOKEEPER-2736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15939603#comment-15939603 ]
ASF GitHub Bot commented on ZOOKEEPER-2736: ------------------------------------------- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/205#discussion_r107824798 --- Diff: src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java --- @@ -817,24 +849,23 @@ public void touchCnxn(NIOServerCnxn cnxn) { private void addCnxn(NIOServerCnxn cnxn) { InetAddress addr = cnxn.getSocketAddress(); - Set<NIOServerCnxn> set = ipMap.get(addr); - if (set == null) { - // in general we will see 1 connection from each - // host, setting the initial cap to 2 allows us - // to minimize mem usage in the common case - // of 1 entry -- we need to set the initial cap - // to 2 to avoid rehash when the first entry is added - // Construct a ConcurrentHashSet using a ConcurrentHashMap - set = Collections.newSetFromMap( - new ConcurrentHashMap<NIOServerCnxn, Boolean>(2)); - // Put the new set in the map, but only if another thread + IpCnxns ipCnxns = ipMap.get(addr); + + if (ipCnxns == null) { + // create an IpCnxns which is a wrapper that holds a RateLimiter and + // a set of connections for each ip + RateLimiter rateLimiter = RateLimiter.Factory.create( + QuorumPeerConfig.getRateLimiterImpl(), QuorumPeerConfig.getClientCnxnBurst(), + QuorumPeerConfig.getClientCnxnRate()); + ipCnxns = new IpCnxns(rateLimiter); + // Put the ip limiter/set in the map, but only if another thread // hasn't beaten us to it - Set<NIOServerCnxn> existingSet = ipMap.putIfAbsent(addr, set); - if (existingSet != null) { - set = existingSet; + IpCnxns existingIpCnxns = ipMap.putIfAbsent(addr, ipCnxns); + if (existingIpCnxns != null) { + ipCnxns = existingIpCnxns; } } - set.add(cnxn); + ipCnxns.cnxnSet.add(cnxn); --- End diff -- Nit: direct field access... again. > Add a connection rate limiter > ----------------------------- > > Key: ZOOKEEPER-2736 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2736 > Project: ZooKeeper > Issue Type: Improvement > Components: server > Affects Versions: 3.4.9, 3.5.2 > Reporter: Vincent Poon > Attachments: ZOOKEEPER-2736.v1.patch > > > Currently the maxClientCnxns property only limits the aggregate number of > connections from a client, but not the rate at which connections can be > created. > This patch adds a configurable connection rate limiter which limits the rate > as well. -- This message was sent by Atlassian JIRA (v6.3.15#6346)