好了 , 接着上一章 , 我们回到kafka的 kafkaserver 这个重量级的类。
val handlers = new KafkaRequestHandlers(logManager)
socketServer = new SocketServer(config.port,
config.numThreads,
config.monitoringPeriodSecs,
handlers.handlerFor,
config.socketSendBuffer,
config.socketReceiveBuffer,
config.maxSocketRequestSize)
在初始化zk连接, 加载topic信息之后。kafka开始跟做一些io的东西。个人对这部分还是很感兴趣的。让我们点进去看一看。
注释写的很精彩啊:
/**
* An NIO socket server. The thread model is
* 1 Acceptor thread that handles new connections
* N Processor threads that each have their own selectors and handle all requests from their connections synchronously
*/
他都已经说了,这是 NIO 线程模型是 单线程负责处理所以的连接。n个线程异步处理这些连接。
从这个注释入手,我们看一看 Acceptor 和 Processor 是如何实现的。
/**
* Thread that accepts and configures new connections. There is only need for one of these
*/
private[kafka] class Acceptor(val port: Int, private val processors: Array[Processor], val sendBufferSize: Int, val receiveBufferSize: Int) extends AbstractServerThread {
/**
* Accept loop that checks for new connec