[ 
https://issues.apache.org/jira/browse/TS-2137?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Yunkai Zhang updated TS-2137:
-----------------------------

    Description: 
pthread_cond_signal/wait is used in several places in ATS, including but not 
limited:
1) Logging system.
2) 


As we known, pthread_cond_signal() need to take lock, it'll cause more context 
switch than eventfd.

The logging speed is very important for us which will affect RT, it is worth 
optimizing. 

I can confirm that evenfd is supported in Linux platform. 

Let's optimize it in Linux firstly.

===
I have wrote a simple benchmark program to compare the speed of eventfd and 
pthread_cond notify mechanism.

You can get the benchmark program from attachment: 
https://issues.apache.org/jira/secure/attachment/12598570/eventfd_vs_pthread_cond_benchmark.tar.gz,
 and test it by yourself if interesting.

What the program do is that:
1) Create 10 producer threads and 1 consumer thread.
2) Producer threads will notify consumer concurrently in a loop.
3) The consumer thread will receive notification up to a given loop times.

Here is my testing result, the command line argument is loop times(1000000) of 
consumer:
{code}
[eventfd_vs_pthread_cond_benchmark]$ ls
main.cc  Makefile
[eventfd_vs_pthread_cond_benchmark]$ make
g++ -g -o eventfd_test main.cc -DHAVE_EVENTFD -lpthread
g++ -g -o pthread_cond_test main.cc -lpthread
[eventfd_vs_pthread_cond_benchmark]$ ls
eventfd_test  main.cc  Makefile  pthread_cond_test
[eventfd_vs_pthread_cond_benchmark]$ time ./eventfd_test 1000000

real    0m11.644s
user    0m1.517s
sys     1m31.179s
[eventfd_vs_pthread_cond_benchmark]$ time ./pthread_cond_test 1000000

real    0m57.438s
user    0m30.152s
sys     6m7.289s

{code}

We can see that eventfd is about 5 times faster than pthread_cond notify 
mechanism.

  was:
At the end of lifetime of each http connection, the logging action will call 
pthread_cond_signal() to notify flush threads.

As we known, pthread_cond_signal() need to take lock, it'll cause more context 
switch than eventfd.

The logging speed is very important for us which will affect RT, it is worth 
optimizing. 

I can confirm that evenfd is supported in Linux platform. 

Let's optimize it in Linux firstly.

===
I have wrote a simple benchmark program to compare the speed of eventfd and 
pthread_cond notify mechanism.

You can get the benchmark program from attachment: 
https://issues.apache.org/jira/secure/attachment/12598570/eventfd_vs_pthread_cond_benchmark.tar.gz,
 and test it by yourself if interesting.

What the program do is that:
1) Create 10 producer threads and 1 consumer thread.
2) Producer threads will notify consumer concurrently in a loop.
3) The consumer thread will receive notification up to a given loop times.

Here is my testing result, the command line argument is loop times(1000000) of 
consumer:
{code}
[eventfd_vs_pthread_cond_benchmark]$ ls
main.cc  Makefile
[eventfd_vs_pthread_cond_benchmark]$ make
g++ -g -o eventfd_test main.cc -DHAVE_EVENTFD -lpthread
g++ -g -o pthread_cond_test main.cc -lpthread
[eventfd_vs_pthread_cond_benchmark]$ ls
eventfd_test  main.cc  Makefile  pthread_cond_test
[eventfd_vs_pthread_cond_benchmark]$ time ./eventfd_test 1000000

real    0m11.644s
user    0m1.517s
sys     1m31.179s
[eventfd_vs_pthread_cond_benchmark]$ time ./pthread_cond_test 1000000

real    0m57.438s
user    0m30.152s
sys     6m7.289s

{code}

We can see that eventfd is about 5 times faster than pthread_cond notify 
mechanism.

    
> Use eventfd instread of pthread signal/wait in ATS
> --------------------------------------------------
>
>                 Key: TS-2137
>                 URL: https://issues.apache.org/jira/browse/TS-2137
>             Project: Traffic Server
>          Issue Type: Improvement
>          Components: Logging
>            Reporter: Yunkai Zhang
>            Assignee: Yunkai Zhang
>             Fix For: 3.5.0
>
>         Attachments: 
> 0001-TS-2137-Use-eventfd-instread-of-pthread-signal-wait-.patch, 
> 0001-TS-2137-Use-eventfd-instread-of-pthread-signal-wait-.V2.patch, 
> eventfd_vs_pthread_cond_benchmark.tar.gz
>
>
> pthread_cond_signal/wait is used in several places in ATS, including but not 
> limited:
> 1) Logging system.
> 2) 
> As we known, pthread_cond_signal() need to take lock, it'll cause more 
> context switch than eventfd.
> The logging speed is very important for us which will affect RT, it is worth 
> optimizing. 
> I can confirm that evenfd is supported in Linux platform. 
> Let's optimize it in Linux firstly.
> ===
> I have wrote a simple benchmark program to compare the speed of eventfd and 
> pthread_cond notify mechanism.
> You can get the benchmark program from attachment: 
> https://issues.apache.org/jira/secure/attachment/12598570/eventfd_vs_pthread_cond_benchmark.tar.gz,
>  and test it by yourself if interesting.
> What the program do is that:
> 1) Create 10 producer threads and 1 consumer thread.
> 2) Producer threads will notify consumer concurrently in a loop.
> 3) The consumer thread will receive notification up to a given loop times.
> Here is my testing result, the command line argument is loop times(1000000) 
> of consumer:
> {code}
> [eventfd_vs_pthread_cond_benchmark]$ ls
> main.cc  Makefile
> [eventfd_vs_pthread_cond_benchmark]$ make
> g++ -g -o eventfd_test main.cc -DHAVE_EVENTFD -lpthread
> g++ -g -o pthread_cond_test main.cc -lpthread
> [eventfd_vs_pthread_cond_benchmark]$ ls
> eventfd_test  main.cc  Makefile  pthread_cond_test
> [eventfd_vs_pthread_cond_benchmark]$ time ./eventfd_test 1000000
> real    0m11.644s
> user    0m1.517s
> sys     1m31.179s
> [eventfd_vs_pthread_cond_benchmark]$ time ./pthread_cond_test 1000000
> real    0m57.438s
> user    0m30.152s
> sys     6m7.289s
> {code}
> We can see that eventfd is about 5 times faster than pthread_cond notify 
> mechanism.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to