-
Notifications
You must be signed in to change notification settings - Fork 10
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
Improve multithreaded performance #173
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #173 +/- ##
==========================================
+ Coverage 90.73% 90.81% +0.07%
==========================================
Files 31 31
Lines 6436 6410 -26
==========================================
- Hits 5840 5821 -19
+ Misses 596 589 -7 ☔ View full report in Codecov by Sentry. |
The connections are only recreated if the calls have enough latency for the connections to go back to the idle pool. Ideally this should not be the case. There should probably be as many concurrent connections as there are opened sessions. I will look if this is a possibility. |
It looks like to actually observe this behaviour it is necessary to have a delay in the operations, so it does not really work on a localhost machine. I worked around that in testing by using a proxy introducing an arbitrary delay before the testing docker image. Bumping the number of idle connections seems to indeed solve the issue of having many unnecessary connections re-opening. |
ae94791
to
f69de7a
Compare
f69de7a
to
f19f08c
Compare
We could make the number of max connections configurable. Since the throughput is mostly sensitive to the network latency, an application can obtain better performance with a higher number of opened connections. I believe that could scale even after there are more opened connections than CPUs. Leaving to a high default could make sense. What is an acceptable number of open connections for the nethsm? |
In #157 I was suggesting 100 and nobody complained, thus I would go for 100 as a first shot. |
According to the PKCS11 Spec a single session is not allowed to be used concurrently by multiple threads IIRC. So basically each session could have one connection. Then it would grow dynamically. Not sure how feasible that is. In case of nginx I believe every fork would only open one session and not use threads, and therefore only needs one connection (because every fork has its own), right? |
We could create the agent in the session instead of the instance. That would however degrade performance if the application creates and closes sessions regurlarly. I don't know if it ever makes sense to have more than 100 connections to the nethsm. There is sadly no way to dynamically change the pooling configuration once the agent is built in |
Yes, pretty sure, that's why we had the issues with tokio. Nginx creates worker-forks, not threads. @nponsard can probably confirm that. |
https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/#update-upgrade |
@sosthene-nitrokey ok, can you summarize the changes in this PR shortly? I lost track. |
My current understanding is, that for optimal latency we would need one connection per thread. But in no case it should be necessary to close connections, because also several threads could sequentially use one connection, so that is the first problem that should be solved. because HTTP1 doesn’t support concurrent requests, that would not be optimal latency wise, so we would need a maximum of parallel connections as there are threads. Since ureq doesn’t support increasing the pool dynamically, we need to set a pool size as a configuration setting. Does that make sense? |
The changes are maybe not as atomic as they should be. So this PR has multiple improvements:
|
Yes we could have the pool size be a configuration setting. We could also make the max number of idle connections infinite. |
I made it configurable with at default to the number of CPUs. |
okok, I will merge this - as this will likely solve the initial issue, please feel free to continue the discussion in an issue. |
@sosthene-nitrokey so, do you have an explanation what mechanism is closing the connection in the first place as reported in the original issue? |
The |
Fix #157