如何在 Thrift 中使用不同的线程池处理请求? [英] How to handle requests using different thread pools in Thrift?

查看:31
本文介绍了如何在 Thrift 中使用不同的线程池处理请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有两种方法的节俭服务
1. Response processSync(Request req) :该方法同步处理请求并返回响应.客户端线程被阻塞,直到请求被服务器完全处理.
2. void processAsync(Request req) :该方法用于异步处理.在这里,一旦服务器完全接收到请求,调用就会返回而没有输出.客户端线程不会等到服务器处理完请求.

I have a thrift service that has two methods
1. Response processSync(Request req) : This method synchronously processes requests and returns a response. The client thread gets blocked until the request is completely processed by the server.
2. void processAsync(Request req) : This method is for asynchronous processing. Here as soon as the server completely receives the request, the call returns with no output. Client thread does not wait until the request is processed by the server.

使用 ThreadedSelectorServer 时,它具有用于读取/写入和处理线程的单独线程.要求是在方法级别使用单独的线程池.这是因为可能发生所有处理线程都忙于同步请求的情况.使用异步 API 的客户端可能会超时.我希望给两个 api 的同等权重,以便如果服务器被同步请求淹没;异步请求不会受到影响.

While using ThreadedSelectorServer that has separate threads for reading/writing and processing of threads. The requirement is to use separate thread pools at the method level. This is because it might happen that the all the processing threads get busy with synchronous requests. Clients using the asynchronous api might timeout. I wish to give both api's equal weightage so that if the server is flooded with sync requests; the async requests do not suffer.

考虑有两种不同的服务,一种只有同步方法,另一种具有异步方法.但在那种情况下,必须启动两个需要两个不同端口的 thrift 服务器.我希望避免这样做.

Thought of having two different services, one with only sync method and another one with async. But in that case two thrift servers have to be started which shall require two different ports.I wish to avoid doing that.

有什么建议可以实现吗?

Any suggestions how this can be achieved ?

推荐答案

是的,使用 Multiplex 协议 随 Thrift 0.9.1 引入.它允许多个服务共享相同的传输.请注意,服务器和客户端都必须使用 Multiplex 协议层才能成功.

Yes, use the multiplex protocol introduced with Thrift 0.9.1. It allows having multiple services sharing the same transport. Note that both server and client must use the multiplex protocol layer to succeed.

顺便说一下,考虑使异步方法成为单向:

By the way, consider making the async method a oneway:

Service whatever {
  oneway void processAsync(1: Request req) 
}

这篇关于如何在 Thrift 中使用不同的线程池处理请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆