Comments (5)
bool UThreadEpollScheduler::Run() 中
业务线程开启协程时,epoll_wait可能会被业务fd唤醒,但handler_new_request_func_被注册,
就会被调用处理新请求,Worker::HandlerNewRequestFunc()函数中貌似是阻塞取io线程的消息的,这样的话业务中的其他协程就会暂时挂起,影响性能。
Worker::HandlerNewRequestFunc
里是用 ThdQueue::pick
来取消息的,这里并不会阻塞。
PS:从性能测试看,短连接、长连接的性能差距蛮大的,有没有考虑cache 协程的方案?
即:进程启动后就开启N个IO协程,当accept到连接时使用缓存的协程等待读,读取完数据不销毁协程;业务协程同理。
协程池是有的,可以看看UThreadRuntime :: Create
,一开始会从context_list_
中取空闲协程,而不是每次都创建新的。
协程任务完成后,UThreadRuntime :: UThreadDoneCallback
会负责回收协程,塞回到context_list_
。
from phxrpc.
感谢回复,没有认真看代码,不好意思。
1.ThdQueue::pick确实是非阻塞,但是每次激活都要干这个事,感觉怪怪的,放在EpollNotifier :: Func()更好些吧
2.缓存我觉得libco中这个样例做的更好(https://github.com/Tencent/libco/blob/master/example_echosvr.cpp),业务层可以更多的cache资源,节省的底层调度,改造也非常简单。
3.
EpollNotifier :: Notify() 也许会有问题,socket的buffer不够用,通知失败,业务线程是一次通知取一次消息,有消息会未被取走,1中业务线程也会取到不该自己取的消息,ps请原谅我的强迫症,嘎嘎!
from phxrpc.
补链接
https://github.com/Tencent/libco/blob/master/example_echosvr.cpp
from phxrpc.
1.ThdQueue::pick确实是非阻塞,但是每次激活都要干这个事,感觉怪怪的,放在EpollNotifier :: Func()更好些吧
3.EpollNotifier :: Notify() 也许会有问题,socket的buffer不够用,通知失败,业务线程是一次通知取一次消息,有消息会未被取走,1中业务线程也会取到不该自己取的消息,ps请原谅我的强迫症,嘎嘎!
1和3都提到了EpollNotifier
,我合在一起说哈。
首先,worker收到通知后,并非一定要取触发了EpollNotifier :: Notify
的那个数据包。数据包给哪一个worker处理都是一样的。
另外,EpollNotifier
只是一个优化,即使没有EpollNotifier
,也不影响数据包在IO层和worker层之间传递的。
EpollNotifier
的作用是,在低吞吐场景下,减少单个请求的处理耗时。背景是,在无事件的情况下, epoll_wait即使传入的超时时间为0, 也会等待4ms左右,这可能会导致数据包从IO层传递到worker层中间卡4ms。这时候通过EpollNotifier
来产生事件,可以让epoll_wait马上返回,避免这种卡顿。
2.缓存我觉得libco中这个样例做的更好(https://github.com/Tencent/libco/blob/master/example_echosvr.cpp),业务层可以更多的cache资源,节省的底层调度,改造也非常简单。
其实流程是一样的,都是协程完成任务后,将自己塞到一个 空闲协程列表 里;再有任务到来时,从列表里取空闲协程。
from phxrpc.
感谢解答,学到了不少,哈哈!
from phxrpc.
Related Issues (20)
- 是否有Windows 平台支持的计划? HOT 1
- 服务自动发现,rpc故障切换 HOT 1
- 关于用protobuf定义接口以及通信数据结构的疑问 HOT 5
- sample下面的例子,启动的时候该怎么测试,Search函数 -q后面参数和Notify -m后面参数该写什么 HOT 1
- 不知道能否加入更多的基于场景的用例?
- 每次rpc调用都要新开一个进程吗? HOT 1
- 编译plugin_boost出错 HOT 2
- 支持双向通信吗? HOT 1
- 不支持多进程模式什么意思? HOT 1
- readme中的描述和代码根本对应不上 HOT 1
- epoll_wait的最后参数为什么是4MS ? HOT 1
- 一直没搞懂,它是干嘛的
- 编译pb失败? HOT 1
- protoc各种参数生成的命名规则为什么那么奇怪?
- 关于phxrpc中服务端c++调用tensorflow脚本,Tensorflow Protobuf版本和phxrpc Protobuf版本
- 协程调度器UThreadEpollScheduler中EpollNotifier作用是什么? HOT 1
- libco和phxrpc如何融合
- 老项目是C++98可以用这个吗? HOT 1
- phxrpc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phxrpc.