Package org.apache.zookeeper.server
Class NIOServerCnxnFactory
java.lang.Object
org.apache.zookeeper.server.ServerCnxnFactory
org.apache.zookeeper.server.NIOServerCnxnFactory
- Direct Known Subclasses:
ControllableConnectionFactory
NIOServerCnxnFactory implements a multi-threaded ServerCnxnFactory using
NIO non-blocking socket calls. Communication between threads is handled via
queues.
- 1 accept thread, which accepts new connections and assigns to a
selector thread
- 1-N selector threads, each of which selects on 1/N of the connections.
The reason the factory supports more than one selector thread is that
with large numbers of connections, select() itself can become a
performance bottleneck.
- 0-M socket I/O worker threads, which perform basic socket reads and
writes. If configured with 0 worker threads, the selector threads
do the socket I/O directly.
- 1 connection expiration thread, which closes idle connections; this is
necessary to expire connections on which no session is established.
Typical (default) thread counts are: on a 32 core machine, 1 accept thread,
1 connection expiration thread, 4 selector threads, and 64 worker threads.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe SelectorThread receives newly accepted connections from the AcceptThread and is responsible for selecting for I/O readiness across the connections. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected WorkerServicestatic final StringDefault: 64kBstatic final StringWith 500 connections to an observer with watchers firing on each, is unable to exceed 1GigE rates with only 1 selector.static final StringDefault: 2 * numCoresstatic final StringDefault sessionless connection timeout in ms: 10000 (10s)static final StringDefault worker pool shutdown timeout in ms: 5000 (5s)Fields inherited from class org.apache.zookeeper.server.ServerCnxnFactory
cnxns, login, maxCnxns, saslServerCallbackHandler, secure, zkServer, ZOOKEEPER_MAX_CONNECTION_DEFAULT, ZOOKEEPER_SERVER_CNXN_FACTORY -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new server connection factory which will accept an unlimited number of concurrent connections from each client (up to the file descriptor limits of the operating system). -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseAll(ServerCnxn.DisconnectReason reason) clear all the connections in the selectorvoidconfigure(InetSocketAddress addr, int maxcc, int backlog, boolean secure) protected NIOServerCnxncreateConnection(SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory.SelectorThread selectorThread) voiddumpConnections(PrintWriter pwriter) getAllConnectionInfo(boolean brief) static ByteBufferintintMaximum number of connections allowed from particular host (ip)intThe maximum queue length of the ZooKeeper server's socketvoidjoin()voidreconfigure(InetSocketAddress addr) booleanremoveCnxn(NIOServerCnxn cnxn) De-registers the connection from the various mappings maintained by the factory.voidvoidsetMaxClientCnxnsPerHost(int max) Maximum number of connections allowed from particular host (ip)voidshutdown()voidstart()voidstartup(ZooKeeperServer zks, boolean startServer) voidstop()voidtouchCnxn(NIOServerCnxn cnxn) Add or update cnxn in our cnxnExpiryQueueMethods inherited from class org.apache.zookeeper.server.ServerCnxnFactory
addSession, closeSession, configure, configure, configureSaslLogin, createFactory, createFactory, createFactory, createFactory, createFactory, getMaxCnxns, getNumAliveConnections, getUserName, getZooKeeperServer, initMaxCnxns, isSecure, limitTotalNumberOfCnxns, registerConnection, removeCnxnFromSessionMap, setZooKeeperServer, startup, unregisterConnection
-
Field Details
-
ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT
Default sessionless connection timeout in ms: 10000 (10s)- See Also:
-
ZOOKEEPER_NIO_NUM_SELECTOR_THREADS
With 500 connections to an observer with watchers firing on each, is unable to exceed 1GigE rates with only 1 selector. Defaults to using 2 selector threads with 8 cores and 4 with 32 cores. Expressed as sqrt(numCores/2). Must have at least 1 selector thread.- See Also:
-
ZOOKEEPER_NIO_NUM_WORKER_THREADS
Default: 2 * numCores- See Also:
-
ZOOKEEPER_NIO_DIRECT_BUFFER_BYTES
Default: 64kB- See Also:
-
ZOOKEEPER_NIO_SHUTDOWN_TIMEOUT
Default worker pool shutdown timeout in ms: 5000 (5s)- See Also:
-
maxClientCnxns
protected int maxClientCnxns -
workerPool
-
-
Constructor Details
-
NIOServerCnxnFactory
public NIOServerCnxnFactory()Construct a new server connection factory which will accept an unlimited number of concurrent connections from each client (up to the file descriptor limits of the operating system). startup(zks) must be called subsequently.
-
-
Method Details
-
getDirectBuffer
-
configure
public void configure(InetSocketAddress addr, int maxcc, int backlog, boolean secure) throws IOException - Specified by:
configurein classServerCnxnFactory- Throws:
IOException
-
reconfigure
- Specified by:
reconfigurein classServerCnxnFactory
-
getMaxClientCnxnsPerHost
public int getMaxClientCnxnsPerHost()Maximum number of connections allowed from particular host (ip)- Specified by:
getMaxClientCnxnsPerHostin classServerCnxnFactory
-
setMaxClientCnxnsPerHost
public void setMaxClientCnxnsPerHost(int max) Maximum number of connections allowed from particular host (ip)- Specified by:
setMaxClientCnxnsPerHostin classServerCnxnFactory
-
getSocketListenBacklog
public int getSocketListenBacklog()The maximum queue length of the ZooKeeper server's socket- Specified by:
getSocketListenBacklogin classServerCnxnFactory
-
start
public void start()- Specified by:
startin classServerCnxnFactory
-
startup
public void startup(ZooKeeperServer zks, boolean startServer) throws IOException, InterruptedException - Specified by:
startupin classServerCnxnFactory- Throws:
IOExceptionInterruptedException
-
getLocalAddress
- Specified by:
getLocalAddressin classServerCnxnFactory
-
getLocalPort
public int getLocalPort()- Specified by:
getLocalPortin classServerCnxnFactory
-
removeCnxn
De-registers the connection from the various mappings maintained by the factory. -
touchCnxn
Add or update cnxn in our cnxnExpiryQueue- Parameters:
cnxn-
-
createConnection
protected NIOServerCnxn createConnection(SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory.SelectorThread selectorThread) throws IOException - Throws:
IOException
-
closeAll
clear all the connections in the selector- Specified by:
closeAllin classServerCnxnFactory
-
stop
public void stop() -
shutdown
public void shutdown()- Specified by:
shutdownin classServerCnxnFactory
-
join
- Specified by:
joinin classServerCnxnFactory- Throws:
InterruptedException
-
getConnections
- Specified by:
getConnectionsin classServerCnxnFactory
-
dumpConnections
-
resetAllConnectionStats
public void resetAllConnectionStats()- Specified by:
resetAllConnectionStatsin classServerCnxnFactory
-
getAllConnectionInfo
- Specified by:
getAllConnectionInfoin classServerCnxnFactory
-