Search in sources :

Example 1 with BufferStats

use of org.apache.zookeeper.server.quorum.BufferStats in project zookeeper by apache.

the class NIOServerCnxnTest method testClientResponseStatsUpdate.

@Test
public void testClientResponseStatsUpdate() throws IOException, InterruptedException, KeeperException {
    try (ZooKeeper zk = createClient()) {
        BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats();
        assertThat("Last client response size should be initialized with INIT_VALUE", clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE));
        zk.create("/a", "test".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        assertThat("Last client response size should be greater then zero after client request was performed", clientResponseStats.getLastBufferSize(), greaterThan(0));
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) BufferStats(org.apache.zookeeper.server.quorum.BufferStats) Test(org.junit.jupiter.api.Test)

Example 2 with BufferStats

use of org.apache.zookeeper.server.quorum.BufferStats in project zookeeper by apache.

the class NettyServerCnxnTest method testClientResponseStatsUpdate.

@Test
public void testClientResponseStatsUpdate() throws IOException, InterruptedException, KeeperException {
    try (ZooKeeper zk = createClient()) {
        BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats();
        assertThat("Last client response size should be initialized with INIT_VALUE", clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE));
        zk.create("/a", "test".getBytes(StandardCharsets.UTF_8), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        assertThat("Last client response size should be greater than 0 after client request was performed", clientResponseStats.getLastBufferSize(), greaterThan(0));
        byte[] contents = zk.getData("/a", null, null);
        assertArrayEquals("test".getBytes(StandardCharsets.UTF_8), contents, "unexpected data");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) BufferStats(org.apache.zookeeper.server.quorum.BufferStats) SSLAuthTest(org.apache.zookeeper.test.SSLAuthTest) Test(org.junit.jupiter.api.Test)

Example 3 with BufferStats

use of org.apache.zookeeper.server.quorum.BufferStats in project zookeeper by apache.

the class NettyServerCnxnTest method testServerSideThrottling.

@Test
public void testServerSideThrottling() throws IOException, InterruptedException, KeeperException {
    try (ZooKeeper zk = createClient()) {
        BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats();
        assertThat("Last client response size should be initialized with INIT_VALUE", clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE));
        zk.create("/a", "test".getBytes(StandardCharsets.UTF_8), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        assertThat("Last client response size should be greater than 0 after client request was performed", clientResponseStats.getLastBufferSize(), greaterThan(0));
        for (final ServerCnxn cnxn : serverFactory.cnxns) {
            final NettyServerCnxn nettyCnxn = ((NettyServerCnxn) cnxn);
            // Disable receiving data for all open connections ...
            nettyCnxn.disableRecv();
            // ... then force a throttled read after 1 second (this puts the read into queuedBuffer) ...
            nettyCnxn.getChannel().eventLoop().schedule(new Runnable() {

                @Override
                public void run() {
                    nettyCnxn.getChannel().read();
                }
            }, 1, TimeUnit.SECONDS);
            // ... and finally disable throttling after 2 seconds.
            nettyCnxn.getChannel().eventLoop().schedule(new Runnable() {

                @Override
                public void run() {
                    nettyCnxn.enableRecv();
                }
            }, 2, TimeUnit.SECONDS);
        }
        byte[] contents = zk.getData("/a", null, null);
        assertArrayEquals("test".getBytes(StandardCharsets.UTF_8), contents, "unexpected data");
        // input buffer until after throttling is turned off. Need to make sure both modes work.
        for (final ServerCnxn cnxn : serverFactory.cnxns) {
            final NettyServerCnxn nettyCnxn = ((NettyServerCnxn) cnxn);
            // Disable receiving data for all open connections ...
            nettyCnxn.disableRecv();
            // ... then disable throttling after 2 seconds.
            nettyCnxn.getChannel().eventLoop().schedule(new Runnable() {

                @Override
                public void run() {
                    nettyCnxn.enableRecv();
                }
            }, 2, TimeUnit.SECONDS);
        }
        contents = zk.getData("/a", null, null);
        assertArrayEquals("test".getBytes(StandardCharsets.UTF_8), contents, "unexpected data");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) BufferStats(org.apache.zookeeper.server.quorum.BufferStats) SSLAuthTest(org.apache.zookeeper.test.SSLAuthTest) Test(org.junit.jupiter.api.Test)

Example 4 with BufferStats

use of org.apache.zookeeper.server.quorum.BufferStats in project zookeeper by apache.

the class StatCommand method commandRun.

@Override
public void commandRun() {
    if (!isZKServerRunning()) {
        pw.println(ZK_NOT_SERVING);
    } else {
        pw.print("Zookeeper version: ");
        pw.println(Version.getFullVersion());
        if (zkServer instanceof ReadOnlyZooKeeperServer) {
            pw.println("READ-ONLY mode; serving only read-only clients");
        }
        if (len == FourLetterCommands.statCmd) {
            LOG.info("Stat command output");
            pw.println("Clients:");
            for (ServerCnxn c : factory.getConnections()) {
                c.dumpConnectionInfo(pw, true);
                pw.println();
            }
            pw.println();
        }
        ServerStats serverStats = zkServer.serverStats();
        pw.print(serverStats.toString());
        pw.print("Node count: ");
        pw.println(zkServer.getZKDatabase().getNodeCount());
        if (serverStats.getServerState().equals("leader")) {
            Leader leader = ((LeaderZooKeeperServer) zkServer).getLeader();
            BufferStats proposalStats = leader.getProposalStats();
            pw.printf("Proposal sizes last/min/max: %s%n", proposalStats.toString());
        }
    }
}
Also used : ServerCnxn(org.apache.zookeeper.server.ServerCnxn) Leader(org.apache.zookeeper.server.quorum.Leader) ServerStats(org.apache.zookeeper.server.ServerStats) BufferStats(org.apache.zookeeper.server.quorum.BufferStats) ReadOnlyZooKeeperServer(org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer) LeaderZooKeeperServer(org.apache.zookeeper.server.quorum.LeaderZooKeeperServer)

Aggregations

BufferStats (org.apache.zookeeper.server.quorum.BufferStats)4 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 Test (org.junit.jupiter.api.Test)3 SSLAuthTest (org.apache.zookeeper.test.SSLAuthTest)2 ServerCnxn (org.apache.zookeeper.server.ServerCnxn)1 ServerStats (org.apache.zookeeper.server.ServerStats)1 Leader (org.apache.zookeeper.server.quorum.Leader)1 LeaderZooKeeperServer (org.apache.zookeeper.server.quorum.LeaderZooKeeperServer)1 ReadOnlyZooKeeperServer (org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer)1