节俭中大量的同步连接 [英] Large number of simulteneous connections in thrift

查看:115
本文介绍了节俭中大量的同步连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Thrift写一个简单的服务器。在开始它看起来有希望,但我偶然发现了一个问题与许多客户端连接在同一时间。我使用TThreadPoolServer,它允许4客户端连接,然后阻止其他客户端,直到我杀了一个从连接。我可以做什么,以允许更多(可能几百)客户端同时连接,而不增加线程数。我假设工作线程允许一次执行一个客户端请求,但它看起来像一个线程处理一个连接,直到它被关闭。

I'm trying to write a simple server with Thrift. At the beginning it looked promising, but I've stumbled into a problem with a number of clients connected at the same time. I'm using TThreadPoolServer, which allows 4 client to connect and then blocks other clients until I kill one from the connected. What can I do to allow more (possibly several hundreds) clients to be connected at the same time, without increasing the number of threads. I assumed that the worker threads allow to perform one client request at a time, but it looks like one thread handles one connection until it is closed. I'd like to avoid a situation when my clients has to reopen a socket to perform an action.

推荐答案

采取另一种方法,如果你使用C ++来构建你的服务器,你可以使用TNonblockingServer而不是TThreadPoolServer,这将允许你一次接受许多连接,不管有多少线程是活动的,等等...

Taking another approach, if you are using C++ to build your server, you can use TNonblockingServer instead of TThreadPoolServer, which will allow you to accept many connections at once, regardless of how many threads are active, etc...

话虽如此,你不一定能更快地工作(处理程序仍然在线程池中执行),但更多的客户端将能够立即连接到您。

That being said, you won't necessarily be able to actually do work faster (handlers still execute in a thread pool), but more clients will be able to connect to you at once.

下面是NB服务器的代码:

Here's what the code looks like for the NB server:

shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
shared_ptr<MyHandler> handler(new MyHandler());
shared_ptr<TProcessor> processor(new MyProcessor(handler));
TNonblockingServer server(processor, protocolFactory, port);

这篇关于节俭中大量的同步连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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