Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: message pool: change locks to RWMutexes for performance #10561

Merged
merged 8 commits into from
Mar 30, 2023

Conversation

snissn
Copy link
Contributor

@snissn snissn commented Mar 25, 2023

Related Issues

should effect #10538 because of message pool locks

Proposed Changes

message pool has two locks - change mp.lk and mp.curTsLk to RW locks for API efficiency

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@snissn snissn requested a review from a team as a code owner March 25, 2023 03:21
chain/messagepool/check.go Show resolved Hide resolved
chain/messagepool/check.go Show resolved Hide resolved
@snissn snissn marked this pull request as draft March 25, 2023 20:29
Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, we can switch to RLock in message selection as well.

chain/messagepool/selection.go Show resolved Hide resolved
snissn added 2 commits March 28, 2023 08:11
… also verify that the the calculation is cached after grabbing the write lock. if it is not cached, give up the lock, calculate, and then grab the write lock again
@snissn snissn marked this pull request as ready for review March 28, 2023 08:25
@snissn
Copy link
Contributor Author

snissn commented Mar 28, 2023

closed #10545 for this --

The lock contention seems gone from the eth rpc path now! 100 requests per second compared with 8 seconds per request :) :)

$ cat bench.sh
ab -p post_data.json -T application/json  -c 10 -n 20000 http://localhost:1234/rpc/v1
ubuntu@ip-10-0-4-29:~$ bash bench.sh |tee bench-PR.out
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:
Server Hostname:        localhost
Server Port:            1234

Document Path:          /rpc/v1
Document Length:        45 bytes

Concurrency Level:      10
Time taken for tests:   189.902 seconds
Complete requests:      20000
Failed requests:        0
Total transferred:      3240000 bytes
Total body sent:        6700000
HTML transferred:       900000 bytes
Requests per second:    105.32 [#/sec] (mean)
Time per request:       94.951 [ms] (mean)
Time per request:       9.495 [ms] (mean, across all concurrent requests)
Transfer rate:          16.66 [Kbytes/sec] received
                        34.45 kb/s sent
                        51.12 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    29   95  59.0     83     843
Waiting:       29   95  59.0     83     843
Total:         29   95  59.0     83     843

Percentage of the requests served within a certain time (ms)
  50%     83
  66%     93
  75%    112
  80%    124
  90%    163
  95%    210
  98%    268
  99%    316
 100%    843 (longest request)

@snissn
Copy link
Contributor Author

snissn commented Mar 28, 2023

I'm looking into the failing tests not sure if actual or flaky

@snissn snissn marked this pull request as draft March 28, 2023 08:30
@snissn
Copy link
Contributor Author

snissn commented Mar 28, 2023

hmm definitely still seeing problems with this - not ready just yet

@snissn snissn marked this pull request as ready for review March 28, 2023 09:06
@snissn
Copy link
Contributor Author

snissn commented Mar 28, 2023

Ok great! I think the last issue was repub needs Lock not RLock
831f8a4

tests are passing now, ready for review

chain/messagepool/messagepool.go Outdated Show resolved Hide resolved
chain/messagepool/messagepool.go Outdated Show resolved Hide resolved
chain/messagepool/messagepool.go Outdated Show resolved Hide resolved
chain/messagepool/repub.go Show resolved Hide resolved
chain/messagepool/check.go Show resolved Hide resolved
chain/messagepool/messagepool.go Show resolved Hide resolved
chain/messagepool/messagepool.go Outdated Show resolved Hide resolved
Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com>
chain/messagepool/repub.go Show resolved Hide resolved
chain/messagepool/messagepool.go Outdated Show resolved Hide resolved
chain/messagepool/check.go Show resolved Hide resolved
chain/messagepool/repub.go Show resolved Hide resolved
chain/messagepool/messagepool.go Outdated Show resolved Hide resolved
chain/messagepool/messagepool.go Show resolved Hide resolved
chain/messagepool/selection.go Show resolved Hide resolved
chain/messagepool/repub.go Show resolved Hide resolved
chain/messagepool/messagepool.go Show resolved Hide resolved
chain/messagepool/check.go Show resolved Hide resolved
chain/messagepool/check.go Show resolved Hide resolved
chain/messagepool/repub.go Show resolved Hide resolved
@snissn
Copy link
Contributor Author

snissn commented Mar 30, 2023

latest bench from #41ea5a6f638ca5108a51f70a4cef85d9b98802b7

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:
Server Hostname:        localhost
Server Port:            1234

Document Path:          /rpc/v1
Document Length:        45 bytes

Concurrency Level:      10
Time taken for tests:   200.514 seconds
Complete requests:      20000
Failed requests:        0
Total transferred:      3240000 bytes
Total body sent:        6700000
HTML transferred:       900000 bytes
Requests per second:    99.74 [#/sec] (mean)
Time per request:       100.257 [ms] (mean)
Time per request:       10.026 [ms] (mean, across all concurrent requests)
Transfer rate:          15.78 [Kbytes/sec] received
                        32.63 kb/s sent
                        48.41 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    52  100  48.6     82     624
Waiting:       52  100  48.6     82     624
Total:         52  100  48.6     82     624

Percentage of the requests served within a certain time (ms)
  50%     82
  66%     90
  75%    103
  80%    120
  90%    156
  95%    203
  98%    262
  99%    297
 100%    624 (longest request)

@arajasek arajasek merged commit 139bde3 into master Mar 30, 2023
@arajasek arajasek deleted the mikers/messagepoolRWMutexes branch March 30, 2023 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants