You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by GitBox <gi...@apache.org> on 2022/03/22 17:12:30 UTC

[GitHub] [incubator-brpc] jiangdongzi opened a new issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

jiangdongzi opened a new issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724


   我开始以为bthread要快一个数量级。如果都是3us的话,直接使用pthread线程池不就可以了么


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076339851


   > bthread 和 pthread 是 M:N 的关系,也就是说一个 pthread 上可以运行多个 bthread,并且相对于建立一个pthred,建立一个bthread的时间是非常快的,同时由于 worksteal 的调度方式,可以高效的利用多核。 具体可以参考:[bthread](https://github.com/apache/incubator-brpc/blob/master/docs/cn/bthread.md) 和 [bthread-or-not](https://github.com/apache/incubator-brpc/blob/master/docs/cn/bthread_or_not.md) 两篇文档,应该可以解答你的疑问。
   
   我知道建立bthread很快, 但是可以使用pthread线程池啊.  看到bthread的调度和pthead的调度时间都是3us左右, 挺失落的. 另外linux内核内也有多核任务 balance 也可以高效利用多核的. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076345256


   @jamesge @wwbmmm 求救, 信仰崩塌了.  我开始以为bthread模式与纯异步性能差距不大,  这么看其实跟纯异步还是有不小的差距?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076341448


   我现在只能猜测是bthread不会被抢占, 所以总体可能比pthread的切换次数少? 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jamesge commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jamesge commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076350118


   你比较的是bthread vs. ”pthread线程池“,还是bthread vs. “纯异步"? pthread线程池的代价是一旦阻塞只能阻塞pthread,影响并发度(也就是pthread线程的个数),后者代码难写。bthread就是平衡一下这两者。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1077330183


   > 你比较的是bthread vs. ”pthread线程池“,还是bthread vs. “纯异步"? pthread线程池的代价是一旦阻塞只能阻塞pthread,影响并发度(也就是pthread线程的个数),后者代码难写。bthread就是平衡一下这两者。
   
   我的认知里, 一直线程池与纯异步有相当的性能差距, 而协程与纯异步的差距很小, 所以看到bthead调度也是3us还是蛮失落的, 戈神有测过bthread与纯异步的性能么, 不知道差距有多大


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] ehds commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
ehds commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076255767


   bthread 和 pthread 是 M:N 的关系,也就是说一个 pthread 上可以运行多个 bthread,并且相对于建立一个pthred,建立一个bthread的时间是非常快的,同时由于 worksteal 的调度方式,可以高效的利用多核。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jamesge closed issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jamesge closed issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] wwbmmm commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
wwbmmm commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1077016514


   同意jamesge的观点,bthread的好处就是能让业务用同步的方式写代码,而在性能上能接近纯异步的效果。在pthread情况下如果坚持写同步代码,就会阻塞pthread,为了得到足够的并发度就得开很多的pthread,占用过多的系统资源,而且在pthread数量很多的情况下,切换的开销就会变大,而且锁之类的操作开销也会变大。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] jiangdongzi commented on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
jiangdongzi commented on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1077331152


   > 同意jamesge的观点,bthread的好处就是能让业务用同步的方式写代码,而在性能上能接近纯异步的效果。在pthread情况下如果坚持写同步代码,就会阻塞pthread,为了得到足够的并发度就得开很多的pthread,占用过多的系统资源,而且在pthread数量很多的情况下,切换的开销就会变大,而且锁之类的操作开销也会变大。
   
   如果可以接近纯异步心里上倒也释怀了. 强迫症, 不到不得已,shared_ptr都不舍得用


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] ehds edited a comment on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
ehds edited a comment on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076255767


   bthread 和 pthread 是 M:N 的关系,也就是说一个 pthread 上可以运行多个 bthread,并且相对于建立一个pthred,建立一个bthread的时间是非常快的,同时由于 worksteal 的调度方式,可以高效的利用多核。
   具体可以参考:[bthread](https://github.com/apache/incubator-brpc/blob/master/docs/cn/bthread.md) 和 [bthread-or-not](https://github.com/apache/incubator-brpc/blob/master/docs/cn/bthread_or_not.md) 两篇文档,应该可以解答你的疑问。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


[GitHub] [incubator-brpc] ehds edited a comment on issue #1724: 看到戈神回复中,切换bthread和切换pthread都是3us左右,为什么bthread还有存在的必要呢

Posted by GitBox <gi...@apache.org>.
ehds edited a comment on issue #1724:
URL: https://github.com/apache/incubator-brpc/issues/1724#issuecomment-1076255767


   bthread 和 pthread 是 M:N 的关系,也就是说一个 pthread 上可以运行多个 bthread,并且相对于建立一个pthred,建立一个bthread的时间是非常快的,同时由于 worksteal 的调度方式,可以高效的利用多核。
   具体可以参考:[bthread](https://github.com/apache/incubator-brpc/blob/master/docs/cn/bthread.md) 和 [bthread-or-not](https://github.com/apache/incubator-brpc/blob/master/docs/cn/bthread_or_not.md)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org