标签:write select nec map sel 时间 client react south
public class TNonblockingServerSocket extends TNonblockingServerTransport { private ServerSocketChannel serverSocketChannel = null; } protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(clientTimeout_); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } } public void registerSelector(Selector selector) { try { // Register the server socket channel, indicating an interest in // accepting new connections serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT); } catch (ClosedChannelException e) { // this shouldn‘t happen, ideally... // TODO: decide what to do with this. } } public class TServerSocket extends TServerTransport { private ServerSocket serverSocket_ = null; } protected TSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { Socket result = serverSocket_.accept(); TSocket result2 = new TSocket(result); result2.setTimeout(clientTimeout_); return result2; } catch (IOException iox) { throw new TTransportException(iox); } }
同一时候SelectorThread又维护了一个堵塞队列acceptedQueue,从acceptedQueue中拿新创建好的SocketChannel,来注冊读事件
同步的TServer有TThreadPoolServer,关联一个TServerSocket,採用同步IO的方式来Accept,然后交给一个线程池来处理兴许动作
这里有一篇老外写的文章比較各种server的性能。https://github.com/m1ch1/mapkeeper/wiki/Thrift-Java-Servers-Compared
结论是TThreadSelectorServer在吞吐量和server响应时间的表现都是最优的
Thrift源代码分析(七)-- TServerserver分析
标签:write select nec map sel 时间 client react south
原文地址:http://www.cnblogs.com/yangykaifa/p/7064218.html