-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
AWS python lambda execution time get doubled in cryptography >= 3.1 #6301
Comments
Your issue doesn't have enough details for us to actually debug. pyca/cryptography has many different features, without you providing sample code that's slowed down we have no idea what might have gotten slower. |
Here is the sample code -
Please have a look. 👍 |
Can you please provide a fully executable script that we can actually run and benchmark. This code by itself isn't enough to actually execute (I have no idea what hte value of |
@prateek-singh-wcar the sample code you provided reveals that there's another layer of abstraction by
More importantly, above code is not a sololy executable snippet. Even if To solve the issue you might also need to answer some general questions like: Had you run the code on a native environment instead of cloud? Did you use some module like |
Hi Had you run the code on a native environment instead of cloud? Yes we have run the script at different native system and its have same behavior. Did you use some module like timeit to identify the hotspot and what is the result? No , we did not use We are using jwcrypto==0.9.1 |
Here is the more specific script -
Hope that that should work for your debugging stuff. |
Could you please provide a run-able script? The code is missing several imports and function definitions for |
The request is for a script that can be run without modification that demonstrates the performance problem such that we can reproduce it with multiple versions of cryptography. The code provided quite clearly does not run as it is missing variables, has a commented out import that is required inside the function body, and the functionality in question is inside a function that is never called. I'm disappointed that we've had to make such a basic request multiple times when we're attempting to volunteer our time to assist you. To be more explicit you'll need to provide the following:
|
Closing due to lack of activity. If the problem still exists feel free to reopen and provide the information from the previous comment so we can replicate and investigate. |
Hi, sorry for not following up earlier - we had paused the bump for now. Let's see if following code can help to investigate:
Current requirements.txt (the version specified here is 2.6.1, when we bump to >3.0 - duration increases, no other changes to code / deps are done in combination to bump) asn1crypto==1.4.0 |
@reaperhulk can you please re open it. |
The code is not runable. It's missing imports and a |
Hi @tiran here's a runnable code:
env with cryptography==2.6.1:
env with Cryptography==3.2:
And here's the difference between the outputs from timeit for each version: |
Thank you, that's a perfect! I can reproduce the issue on my laptop: 2.6.1: |
It looks like the performance issue is caused by 1,000 iterations of
1,000 iterations with 2.6.1:
|
Ah, interesting. We actually have an unofficial method for bypassing that check but it will never be part of our public API because it has serious security implications. You can see where it’s set
cryptography/src/cryptography/hazmat/backends/openssl/rsa.py Lines 385 to 390 in 17aeaa6
|
Cryptography could keep a positive cache for checked keys, too. This may not help with lambdas, but it will speed up long-running processes that load the same key over and over again.
|
That check won’t be useful because definitionally if we’re hitting this case repeatedly the user is loading the key repeatedly instead of caching for reuse themselves. So we’re allocating new openssl rsa_cdata structures. |
I've dug deep into the belly of these JWT libs. It's a design issue there. The problem is that every time you attempt to do any cryptographic operation, it reloads the key from scratch: https://github.com/latchset/jwcrypto/blob/14c942d616c850e33c9fa11a38b0fc8bbb0a055c/jwcrypto/jwk.py#L826-L828 While the more comprehensive RSA primarily checks exacerbte this, it was already quite wasteful even before. The correct solution is, once you have an RSAPrivateKey object, to simply keep it around, rather than throwing it away and reparsing every time. |
Hello
We have a AWS lambda and when we are upgrading cryptography version > 3.0 like 3.1 , the lambda execution time just get doubled and working fine till cryptography<= 3.0
I can see, there are few new things added in v3.1 like PKCS7 support for certs and cipher context, So can you please suggest why its taking so much time in lambda execution for cryptography version >= 3.1 .
We are using below versions of libs -
Python == 3.7
cffi == 1.14.5
cryptography == 3.1
pip == 20.2.4
setuptools == 50.3.2
Please have a look and suggest if there is something which is causing the issue.
The text was updated successfully, but these errors were encountered: