Thrift 服务端实现类 - 概览

继承体系

thrift_server_inheritance_hierarchy

TServer

Thrift 服务端通用接口

TSimpleServer

Thrift 服务端单线程简单实现,个般只用于测试 详见

TThreadPoolServer

Thrift 服务端 java 内置线程池实现方式

参数及默认值:

  • int minWorkerThreads = 5; 最小工作线程数
  • int maxWorkerThreads = Integer.MAX_VALUE; 最大工作线程数
  • int stopTimeoutVal = 60; 停止超时时间
  • TimeUnit stopTimeoutUnit = TimeUnit.SECONDS; 时间单位
  • int requestTimeout = 20; 请求worker超时时间
  • TimeUnit requestTimeoutUnit = TimeUnit.SECONDS;
  • int beBackoffSlotLength = 100; (Binary exponential backoff slot length<看不懂, 看源码猜测为等待时间系数>)
  • TimeUnit beBackoffSlotLengthUnit = TimeUnit.MILLISECONDS;

AbstractNonblockingServer

Thrift 服务端 非阻塞实现 的公共方法及类实现

TNonblockingServer

Thrift 服务端 非阻塞实现. 此类可以接受任意类型客户端的连接请求。此类为单线程实现, 如果需要以线程池方式,参见THsHaServer. 使用这个类时,最外层传输必须使用,TFramedTransport,否则服务将不能确定调用是否读取完。客户端也必须使用TFramedTransport。

This allows for fairness amongst all connected clients in terms of invocations. This server is inherently single-threaded. If you want a limited thread pool coupled with invocation-fairness, see THsHaServer. To use this server, you MUST use a TFramedTransport at the outermost transport, otherwise this server will be unable to determine when a whole method call has been read off the wire. Clients must also use TFramedTransport.

TThreadedSelectorServer

Thrift 服务端 半同步/半异步实现。使用一个独立的线程池处理非阻塞式IO. 由一个线程接收请求,由可配置数量的非阻塞式选择线程管理客户端的读写。由一个同步worker的线程池处理请求 A Half-Sync/Half-Async server with a separate pool of threads to handle non-blocking I/O. Accepts are handled on a single thread, and a configurable number of nonblocking selector threads manage reading and writing of client connections. A synchronous worker thread pool handles processing of requests.

在多核心环境中,如果瓶颈是单线程处理IO时CPU不足,会比TNonblockingServer/THsHaServer有更好的性能; 而且,因为实现有接受请求与处理读写,调用解耦,服务具有更好的接收新请求的能力。 Performs better than TNonblockingServer/THsHaServer in multi-core environments when the the bottleneck is CPU on the single selector thread handling I/O. In addition, because the accept handling is decoupled from reads/writes and invocation, the server has better ability to handle back- pressure from new connections (e.g. stop accepting when busy).

与 TNonblockingServer相似, 服务端和客户端都要使用 TFramedTransport.

参数及默认值:

  • int selectorThreads = 2; 选择已经接收连接的线程数量
  • int workerThreads = 5; 调用服务线程池数量,如果设置为0则由选择线程直接处理(同TNonblockingServer)
  • int stopTimeoutVal = 60; 为服务被优雅地关闭而等待的时间
  • TimeUnit stopTimeoutUnit = TimeUnit.SECONDS;
  • int acceptQueueSizePerThread = 4; 最大堆积数
  • AcceptPolicy acceptPolicy = AcceptPolicy.FAST_ACCEPT; FAIR_ACCEPT: 当worker 全部占用时不再接受请求

THsHaServer

将TNonblockingServer扩展为半同步/半异步实现. 与 TNonblockingServer相似, 服务端和客户端都要使用 TFramedTransport.

参数及默认值:

  • int minWorkerThreads = 5; 最小工作线程数
  • int maxWorkerThreads = Integer.MAX_VALUE;
  • int stopTimeoutVal = 60; 为服务被优雅地关闭而等待的时间
  • TimeUnit stopTimeoutUnit = TimeUnit.SECONDS;

转载于:https://my.oschina.net/u/915811/blog/893462

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值