zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cami...@apache.org
Subject svn commit: r1242982 - in /zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/ src/java/test/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Fri, 10 Feb 2012 23:34:18 GMT
Author: camille
Date: Fri Feb 10 23:34:18 2012
New Revision: 1242982

URL: http://svn.apache.org/viewvc?rev=1242982&view=rev
Log:
ZOOKEEPER-1321. Add number of client connections metric in JMX and srvr. (Neha N. via camille)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Fri Feb 10 23:34:18 2012
@@ -219,6 +219,7 @@ IMPROVEMENTS:
   ZOOKEEPER-1322. Cleanup/fix logging in Quorum code. 
   (phunt via mahadev)
 
+  ZOOKEEPER-1321. Add number of client connections metric in JMX and srvr. (Neha Narkhede
via camille)
 Release 3.4.0 - 
 
 Non-backward compatible changes:

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java Fri Feb 10
23:34:18 2012
@@ -64,7 +64,7 @@ public class NIOServerCnxn extends Serve
 
     SocketChannel sock;
 
-    private SelectionKey sk;
+    private final SelectionKey sk;
 
     boolean initialized;
 
@@ -749,6 +749,7 @@ public class NIOServerCnxn extends Serve
 
             print("packets_received", stats.getPacketsReceived());
             print("packets_sent", stats.getPacketsSent());
+            print("num_alive_connections", stats.getNumAliveClientConnections());
 
             print("outstanding_requests", stats.getOutstandingRequests());
 

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxnFactory.java Fri
Feb 10 23:34:18 2012
@@ -32,14 +32,14 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.security.auth.login.Configuration;
+import javax.security.auth.login.LoginException;
+
 import org.apache.zookeeper.Login;
 import org.apache.zookeeper.server.auth.SaslServerCallbackHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.security.auth.login.Configuration;
-import javax.security.auth.login.LoginException;
-
 public class NIOServerCnxnFactory extends ServerCnxnFactory implements Runnable {
     private static final Logger LOG = LoggerFactory.getLogger(NIOServerCnxnFactory.class);
 
@@ -72,13 +72,11 @@ public class NIOServerCnxnFactory extend
     */
     final ByteBuffer directBuffer = ByteBuffer.allocateDirect(64 * 1024);
 
-    final HashSet<ServerCnxn> cnxns = new HashSet<ServerCnxn>();
     final HashMap<InetAddress, Set<NIOServerCnxn>> ipMap =
         new HashMap<InetAddress, Set<NIOServerCnxn>>( );
 
     int maxClientCnxns = 60;
 
-
     /**
      * Construct a new server connection factory which will accept an unlimited number
      * of concurrent connections from each client (up to the file descriptor
@@ -322,5 +320,4 @@ public class NIOServerCnxnFactory extend
     public Iterable<ServerCnxn> getConnections() {
         return cnxns;
     }
-
 }

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxn.java Fri Feb
10 23:34:18 2012
@@ -560,6 +560,7 @@ public class NettyServerCnxn extends Ser
 
             print("packets_received", stats.getPacketsReceived());
             print("packets_sent", stats.getPacketsSent());
+            print("num_alive_connections", stats.getNumAliveClientConnections());
 
             print("outstanding_requests", stats.getOutstandingRequests());
 

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
(original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NettyServerCnxnFactory.java
Fri Feb 10 23:34:18 2012
@@ -56,7 +56,6 @@ public class NettyServerCnxnFactory exte
     ServerBootstrap bootstrap;
     Channel parentChannel;
     ChannelGroup allChannels = new DefaultChannelGroup("zkServerCnxns");
-    HashSet<ServerCnxn> cnxns = new HashSet<ServerCnxn>();
     HashMap<InetAddress, Set<NettyServerCnxn>> ipMap =
         new HashMap<InetAddress, Set<NettyServerCnxn>>( );
     InetSocketAddress localAddress;

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java Fri Feb
10 23:34:18 2012
@@ -22,13 +22,15 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
 import java.util.HashMap;
+import java.util.HashSet;
 
 import javax.management.JMException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.jmx.MBeanRegistry;
+
 import org.apache.zookeeper.Login;
+import org.apache.zookeeper.jmx.MBeanRegistry;
 import org.apache.zookeeper.server.auth.SaslServerCallbackHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public abstract class ServerCnxnFactory {
 
@@ -49,6 +51,12 @@ public abstract class ServerCnxnFactory 
     
     public abstract Iterable<ServerCnxn> getConnections();
 
+    public int getNumAliveConnections() {
+        synchronized(cnxns) {
+            return cnxns.size();
+        }
+    }
+
     public abstract void closeSession(long sessionId);
 
     public abstract void configure(InetSocketAddress addr,
@@ -115,7 +123,9 @@ public abstract class ServerCnxnFactory 
 
     public abstract InetSocketAddress getLocalAddress();
 
-    private HashMap<ServerCnxn, ConnectionBean> connectionBeans = new HashMap<ServerCnxn,
ConnectionBean>();
+    private final HashMap<ServerCnxn, ConnectionBean> connectionBeans = new HashMap<ServerCnxn,
ConnectionBean>();
+
+    protected final HashSet<ServerCnxn> cnxns = new HashSet<ServerCnxn>();
     public void unregisterConnection(ServerCnxn serverCnxn) {
         ConnectionBean jmxConnectionBean = connectionBeans.remove(serverCnxn);
         if (jmxConnectionBean != null){

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerStats.java Fri Feb 10
23:34:18 2012
@@ -19,6 +19,7 @@
 package org.apache.zookeeper.server;
 
 
+
 /**
  * Basic Server Statistics
  */
@@ -36,6 +37,7 @@ public class ServerStats {
         public long getOutstandingRequests();
         public long getLastProcessedZxid();
         public String getState();
+        public int getNumAliveConnections();
     }
     
     public ServerStats(Provider provider) {
@@ -78,6 +80,11 @@ public class ServerStats {
         return provider.getState();
     }
     
+    /** The number of client connections alive to this server */
+    public int getNumAliveClientConnections() {
+    	return provider.getNumAliveConnections();
+    }
+
     @Override
     public String toString(){
         StringBuilder sb = new StringBuilder();
@@ -85,6 +92,8 @@ public class ServerStats {
                 + getAvgLatency() + "/" + getMaxLatency() + "\n");
         sb.append("Received: " + getPacketsReceived() + "\n");
         sb.append("Sent: " + getPacketsSent() + "\n");
+        sb.append("Connections: " + getNumAliveClientConnections() + "\n");
+
         if (provider != null) {
             sb.append("Outstanding: " + getOutstandingRequests() + "\n");
             sb.append("Zxid: 0x"+ Long.toHexString(getLastProcessedZxid())+ "\n");
@@ -123,7 +132,6 @@ public class ServerStats {
         packetsReceived = 0;
         packetsSent = 0;
     }
-    
     synchronized public void reset() {
         resetLatency();
         resetRequestCounters();

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java Fri Feb
10 23:34:18 2012
@@ -256,7 +256,6 @@ public class ZooKeeperServer implements 
         }
     }
 
-
     /**
      * This should be called from a synchronized block on this!
      */
@@ -686,6 +685,14 @@ public class ZooKeeperServer implements 
     }
 
     /**
+     * return the total number of client connections that are alive
+     * to this server
+     */
+    public int getNumAliveConnections() {
+        return serverCnxnFactory.getNumAliveConnections();
+    }
+
+    /**
      * trunccate the log to get in sync with others
      * if in a quorum
      * @param zxid the zxid that it needs to get in sync

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerBean.java Fri
Feb 10 23:34:18 2012
@@ -140,4 +140,8 @@ public class ZooKeeperServerBean impleme
         serverStats.resetRequestCounters();
         serverStats.resetLatency();
     }
+
+    public long getNumAliveConnections() {
+        return zks.getNumAliveConnections();
+    }
 }

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMXBean.java Fri
Feb 10 23:34:18 2012
@@ -103,4 +103,8 @@ public interface ZooKeeperServerMXBean {
      * Reset max latency statistics only.
      */
     public void resetMaxLatency();
+    /**
+     * @return number of alive client connections
+     */
+    public long getNumAliveConnections();
 }

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java Fri Feb
10 23:34:18 2012
@@ -282,6 +282,10 @@ public class Zab1_0Test {
         }
         public void closeAll() {
         }
+        @Override
+        public int getNumAliveConnections() {
+            return 0;
+        }
     }
     static Socket[] getSocketPair() throws IOException {
         ServerSocket ss = new ServerSocket();

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java?rev=1242982&r1=1242981&r2=1242982&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/FourLetterWordsTest.java Fri Feb
10 23:34:18 2012
@@ -94,6 +94,9 @@ public class FourLetterWordsTest extends
         verify("srvr", "Outstanding");
         verify("cons", "queued");
         verify("mntr", "zk_server_state\tstandalone");
+        verify("mntr", "num_alive_connections");
+        verify("stat", "Connections");
+        verify("srvr", "Connections");
     }
 
     private String sendRequest(String cmd) throws IOException {
@@ -136,6 +139,8 @@ public class FourLetterWordsTest extends
         line = in.readLine();
         Assert.assertTrue(Pattern.matches("^Sent: \\d+$", line));
         line = in.readLine();
+        Assert.assertTrue(Pattern.matches("^Connections: \\d+$", line));
+        line = in.readLine();
         Assert.assertTrue(Pattern.matches("^Outstanding: \\d+$", line));
         line = in.readLine();
         Assert.assertTrue(Pattern.matches("^Zxid: 0x[\\da-fA-F]+$", line));



Mime
View raw message