`
chensx
  • 浏览: 48896 次
  • 性别: 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 多进程服务器 我们以线程池服务器为例,其他方式相同。 ...

    课程设计基于python+mediapipe+opencv开发的手势识别系统源码(含超详细注释).zip

    课程设计基于python+mediapipe+opencv开发的手势识别系统源码(含超详细注释).zip个人经导师指导并认可通过的98分大作业设计项目,适用人群:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业或毕业设计,作为“参考资料”使用。 课程设计基于python+mediapipe+opencv开发的手势识别系统源码(含超详细注释).zip个人经导师指导并认可通过的98分大作业设计项目,适用人群:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业或毕业设计,作为“参考资料”使用。 课程设计基于python+mediapipe+opencv开发的手势识别系统源码(含超详细注释).zip个人经导师指导并认可通过的98分大作业设计项目,适用人群:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业或毕业设计,作为“参考资料”使用。 课程设计基于python+mediapipe+opencv开发的手势识别系统源码(含超详细注释).zip个人经导师指导并认可通过的98分大作业设计项目,适用人群:计算机,电子信息工程、数学等专业的大学生课程设计。

    yolov7 车牌检测 车牌识别 中文车牌识别 检测 支持双层车牌 支持12种中文车牌

    yolov7

    基于MQTT的智能宠物投喂系统.zip

    基于MQTT的智能宠物投喂系统:STM32、ESP8266、LCDST7789、压力传感器、按键中断修改定时投喂时间、云平台

    Qt进阶:优秀QT开源项目

    详细说明:https://blog.csdn.net/u010168781/article/details/138924179 1、Krita 2、QGIS 3、Kdenlive 4、Clementine 5、Syncthing 6、KDevelop

    2023-04-06-项目笔记 - 第一百三十四阶段 - 4.4.2.132全局变量的作用域-132 -2024.05.15

    2023-04-06-项目笔记-第一百三十四阶段-课前小分享_小分享1.坚持提交gitee 小分享2.作业中提交代码 小分享3.写代码注意代码风格 4.3.1变量的使用 4.4变量的作用域与生命周期 4.4.1局部变量的作用域 4.4.2全局变量的作用域 4.4.2.1全局变量的作用域_1 4.4.2.132全局变量的作用域_132 - 2024-05-15

    matlab基于区间知识的大脑情绪学习算法.zip

    matlab基于区间知识的大脑情绪学习算法.zip

    Scrapy-0.8.win32.exe

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

    setuptools-34.1.0-py2.py3-none-any.whl

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

    基于python+PyQt5开发的智能照明控制系统上位机软件源码.zip

    基于python+PyQt5开发的智能照明控制系统上位机软件源码.zip

    pytest-4.6.3.tar.gz

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

    麦肯锡战略咨询经验.ppt

    麦肯锡战略咨询经验.ppt

    Redis入门基础篇+源码(springboot、maven)

    Redis入门基础篇-源码

    基于Python+flask+echarts实现的天气展示系统源码.zip

    基于Python+flask+echarts实现的天气展示系统源码.zip

    人工水母优化算法JS MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用

    人工水母优化算法JS MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用

    pytest-3.2.5.tar.gz

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

    四旋翼双环pid控制matlab版本R2020b源码.zip

    四旋翼双环pid控制matlab版本R2020b源码.zip

    1-3.py

    1-3

Global site tag (gtag.js) - Google Analytics