-
Notifications
You must be signed in to change notification settings - Fork 383
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
Secret Connection: Remove sync.Pool, and put those buffers in the connection struct #3197
Comments
The problem is that Actually, we have other mutexes in those methods that are based on the same assumption. And this is because it implements generic Go interfaces that assume that |
Thats not what I mean, the Read method itself already has the mutex! So these buffers would already be mutex protected |
They are protected by different mutexes: cometbft/p2p/conn/secret_connection.go Lines 232 to 234 in 67b2987
cometbft/p2p/conn/secret_connection.go Lines 188 to 190 in 67b2987
We use the |
What we can have, to reduce contention, are two unsynchronized pools, one for reads, another for writes. By the way, we import |
Feature Request
Summary
In secret connection we use sync.Pool's for some 1024 byte buffers. However these buffers are only ever needed locally within the same thread, so this is a wasted synchronization primitive that does cost us. All reads and writes in secret connection are under a mutex, so we should just make a new buffer in each secret conn struct.
Impact is ~8% of the current secret connection read time (Get and Put in following pprof):
![image](https://private-user-images.githubusercontent.com/6440154/337284065-a885d7a1-976f-4f84-8051-54d10fdcf267.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxMTA3MDUsIm5iZiI6MTcxOTExMDQwNSwicGF0aCI6Ii82NDQwMTU0LzMzNzI4NDA2NS1hODg1ZDdhMS05NzZmLTRmODQtODA1MS01NGQxMGZkY2YyNjcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjNUMDI0MDA1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzE5ZjVkZGFjYzIwYjc5M2U4ZmEzM2Y4ZTAyMjAxYTY1ZjU1NmM5MGViNzNhZDk2NjY5YmE2YmIwMmM5ZmE3ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.f5mpkdjODQUFBhkJeAjw5jxReHjIO2HphFyDXf_7oPo)
Problem Definition
Slight speedup to secret conn
The text was updated successfully, but these errors were encountered: