`
chensx
  • 浏览: 48900 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

TThreadedServer vs. TNonblockingServer

 
阅读更多

原文转载于:https://github.com/

TThreadedServer vs. TNonblockingServer

Introduction

Which Thrift RPC server should MapKeeper use, TThreadedServer or TNonblockingServer? This benchmark compares 2 Thrift C++ RPC servers using StubServer. The focus of this benchmark is to test these 2 servers on a multi-core servers with a limited number (<1000) of concurrent client connections.

TThreadedServer

TThreadedServer spawns a new thread for each client connection, and each thread remains alive until the client connection is closed. This means that if there are 1000 concurrent client connections, TThreadedServer needs to run 1000 threads simultaneously.

TNonblockingServer

TNonblockingServer has one thread dedicated for network I/O. The same thread can also process requests, or you can create a separate pool of worker threads for request processing. The server can handle many concurrent connections with a small number of threads since it doesn’t need to spawn a new thread for each connection.

TThreadPoolServer (not benchmarked here)

TThreadPoolServer is similar to TThreadedServer; each client connection gets its own dedicated server thread. It’s different from TThreadedServer in 2 ways:

  1. Server thread goes back to the thread pool after client closes the connection for reuse.
  2. There is a limit on the number of threads. The thread pool won’t grow beyond the limit.

Client hangs if there is no more thread available in the thread pool. It’s much more difficult to use compared to the other 2 servers.

Configurations

Hardware

  • 2 x Xeon E5620 2.40GHz (HT enabled, 8 cores, 16 threads)

Operating System

  • RHEL Server 5.4, Linux 2.6.18-164.2.1.el5 x86_64, 64-bit

Software

  • Thrift 0.6.1
  • TNonblockingServer thread pool size: 32 threads
  • Client and server run on the same box.

YCSB Workload

  • Number of client threads: 300
  • Number of requests: 10 million
  • Request size: ~60 bytes
  • Response size: ~30 bytes

Results

In this benchmark, TThreadedServer performs much better than TNonblockingServer. CPU is maxed out with TThreadedServer, while TNonblockingServer only uses about 20% of CPU time. I’m guessing it’s because the I/O thread is being the bottleneck and worker threads are not getting enough things to do .

Conclusion

TThreadedServer seems like a better fit for MapKeeper since I’m not planning to support thousands of concurrent connections (yet). TNonblockingServer might be a better choice when you face the C10K problem, but you need to make sure the I/O thread doesn’t become the bottleneck. It would be an interesting project to add a new type of Thrift server with a single accept() thread and multiple worker threads handling network I/O and request processing. There is already an open JIRA for this feature in Java. Is anybody interested in working on a similar feature in C++?

分享到:
评论

相关推荐

    Thrift结构分析及增加取客户端IP功能实现

    另外,请注意本文针对的是TNonblockingServer,不包含TThreadPoolServer、TThreadedServer和TSimpleServer。  thrift对网络连接没有使用内存池,最直接简单的性能优化是绑定Google gperftools中的TCMalloc。

    Thrift的服务器和客户端Python案例

    thrift.server.TServer.TThreadedServer 多线程服务器 thrift.server.TServer.TThreadPoolServer 线程池服务器 thrift.server.TServer.TForkingServer 多进程服务器 我们以线程池服务器为例,其他方式相同。 ...

    pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

    pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

    matlab建立计算力学课程的笔记和文件.zip

    matlab建立计算力学课程的笔记和文件.zip

    FT-Prog-v3.12.38.643-FTD USB 工作模式设定及eprom读写

    FT_Prog_v3.12.38.643--FTD USB 工作模式设定及eprom读写

    matlab基于RRT和人工势场法混合算法的路径规划.zip

    matlab基于RRT和人工势场法混合算法的路径规划.zip

    matlab基于matlab的两步定位软件定义接收机的开源GNSS直接位置估计插件模块.zip

    matlab基于matlab的两步定位软件定义接收机的开源GNSS直接位置估计插件模块.zip

    office 2016三和一精简版

    office 2016三和一精简版

    Scrapy-1.0.2-py2-none-any.whl

    文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    麦肯锡咨询顾问必备宝典-时间管理.ppt

    麦肯锡咨询顾问必备宝典-时间管理.ppt

    setuptools-0.6c10-py2.4.egg

    文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    麦肯锡顾问的黄金思考方法.pptx

    麦肯锡顾问的黄金思考方法.pptx

    91fdd461elb59a4ce8dfcfc46bc283a7.msi

    91fdd461elb59a4ce8dfcfc46bc283a7.msi

    ansys maxwell

    ansys maxwell

    5-5.py

    5-5

    xx广告促销计划流程实施手册.ppt

    xx广告促销计划流程实施手册.ppt

    仿小米商城微信小程序源码+项目说明.zip

    仿小米商城微信小程序源码+项目说明.zip

    pytest-4.6.0.tar.gz

    文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    Scrapy-2.10.1.tar.gz

    文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    麦肯锡xx客户满意服务.ppt

    麦肯锡xx客户满意服务.ppt

Global site tag (gtag.js) - Google Analytics