PhotonLibOS icon indicating copy to clipboard operation
PhotonLibOS copied to clipboard

benchmark of context switch? (latency)

Open jayden5414 opened this issue 3 years ago • 3 comments
trafficstars

这个参数对我们的业务比较重要. 谢谢啊!

jayden5414 avatar Aug 10 '22 18:08 jayden5414

The context switch latency varies from 10 to 20 nano seconds depending how many coroutines you are running with.

We already have a test case for this. https://github.com/alibaba/PhotonLibOS/blob/0fa93f3e58d554f935ec62538d054f4d6595838f/thread/test/test.cpp#L380-L398

You can run it on your environment.

beef9999 avatar Aug 11 '22 05:08 beef9999

But I wonder why context switch is what you are concerned. It doesn't weigh too much in the whole IO process, only a small portion, I believe.

Can you describe your scenario?

beef9999 avatar Aug 11 '22 05:08 beef9999

10 to 20 nano seconds

wonderful, can not believe, as I know the bthread which is a coroutine in brpc context switch time is 2~3 us..........

jiangdongzi avatar Aug 15 '22 07:08 jiangdongzi

But I wonder why context switch is what you are concerned. It doesn't weigh too much in the whole IO process, only a small portion, I believe.

Can you describe your scenario?

high frenquency trading. it is latency sensitive.

ghost avatar Aug 16 '22 13:08 ghost

The context switch latency varies from 10 to 20 nano seconds depending how many coroutines you are running with.

We already have a test case for this.

https://github.com/alibaba/PhotonLibOS/blob/0fa93f3e58d554f935ec62538d054f4d6595838f/thread/test/test.cpp#L380-L398

You can run it on your environment.

In my computer, AMD Ryzen 7 3700X 8-Core Processor, 3.6G hz, single context switch is 182.6550 ns. image

jiangdongzi avatar Nov 13 '23 07:11 jiangdongzi

test_thread_switch:single context switch: 12.5599 ns (79.6185 M/s)

2.6 GHz Intel Core i7, macOS

beef9999 avatar Nov 13 '23 16:11 beef9999

@jiangdongzi Did you forget to add -O2? 182ns is too high

lihuiba avatar Nov 14 '23 03:11 lihuiba