zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eribeiro <...@git.apache.org>
Subject [GitHub] zookeeper pull request #205: ZOOKEEPER-2736 Add a connection rate limiter
Date Fri, 24 Mar 2017 02:43:19 GMT
Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/205#discussion_r107825507
  
    --- 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 --
    
    Please, make cnxnSet final.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message