简体   繁体   English

Apache Thrift:终止服务器连接

[英]Apache Thrift: Terminate Connection from the Server

I am using thrift to provide an interface between a device and a management console. 我正在使用Thrift在设备和管理控制台之间提供接口。 It is possible for there to be up to 4 active connections to the device at one time, and I have this working using a TThreadPool server. 一次最多可能有4个活动连接到该设备,而我使用TThreadPool服务器进行此工作。

The issue arises around client disconnections; 问题出在客户端断开连接上。 If a client disconnects correctly, there is no issue, however if one does not (ie the client crashes out or doesn't call client->close()) then the server seems to keep that clients thread alive. 如果客户端正确断开连接,则没有问题,但是如果客户端没有断开连接(即,客户端崩溃或不调用client-> close()),则服务器似乎使该客户端线程保持活动状态。 This means that when the next connection attempt is made, the client hangs, as the server has used up its allocated thread pool so cannot service the new request. 这意味着在进行下一次连接尝试时,客户端将挂起,因为服务器已经用完了分配的线程池,因此无法为新请求提供服务。

I haven't been able to find any standard, public mechanism by which the server can stop, and hence free up, a clients thread if that client has not used the interface for a set time period? 如果该客户端在设定的时间内未使用该接口,我还无法找到任何标准的公共机制来使服务器停止并因此释放该客户端的线程?

Is there a standard way to facilitate this in thrift? 是否有标准的方式来节省开支?

Set the receive/send timeout on the server socket might help. 在服务器套接字上设置接收/发送超时可能会有所帮助。 Server will close the connection on timeout. 服务器将在超时时关闭连接。

https://github.com/apache/thrift/blob/129f332d72facda5d06f87e2b4e5e08bea0b6b44/lib/cpp/src/thrift/transport/TServerSocket.h#L103 https://github.com/apache/thrift/blob/129f332d72facda5d06f87e2b4e5e08bea0b6b44/lib/cpp/src/thrift/transport/TServerSocket.h#L103

  void setSendTimeout(int sendTimeout);
  void setRecvTimeout(int recvTimeout);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM