Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/205#discussion_r107822018
  
    --- Diff: 
src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java ---
    @@ -607,9 +618,28 @@ public static ByteBuffer getDirectBuffer() {
         // sessionMap is used by closeSession()
         private final ConcurrentHashMap<Long, NIOServerCnxn> sessionMap =
             new ConcurrentHashMap<Long, NIOServerCnxn>();
    -    // ipMap is used to limit connections per IP
    -    private final ConcurrentHashMap<InetAddress, Set<NIOServerCnxn>> ipMap 
=
    -        new ConcurrentHashMap<InetAddress, Set<NIOServerCnxn>>( );
    +    // ipMap is used to limit connections and connection rate per IP
    +    private final ConcurrentHashMap<InetAddress, IpCnxns> ipMap
    +        = new ConcurrentHashMap<InetAddress, IpCnxns>();
    +
    +    // for each IP, we keep a RateLimiter to limit connection rate,
    +    // as well as a set of connections to limit total number of connections
    +    private static class IpCnxns {
    +        private IpCnxns(RateLimiter rateLimiter) {
    +            this.rateLimiter = rateLimiter;
    +        }
    +
    +        // 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
    +        private Set<NIOServerCnxn> cnxnSet = Collections
    --- End diff --
    
    We put the fields before the constructor here, so these fields should be 
moved up.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to