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));
}
}
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");
}
}
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");
}
}
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());
}
}
}
Aggregations