-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Profiling for crypter's decryption for ALTS Channel. #6761
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
Comments
Interesting. Just wondering, what optimization can gRPC do here? The interaction you described is between Conscrypt and Javax.crypto and I didn't see a way gRPC can avoid/minimize the ShortBufferException. |
If there is a way for |
Okay, looks like it is the |
With help of @ejona86, I ran a benchmark again with the change on |
Closing, since it seems there isn't any better method for gRPC at the moment. That isn't to say there isn't an optimization that could be done here, but it seems like it will need noticeable changes to Conscrypt first |
Note that Java 11 addressed this problem with JDK-8178374. |
To avoid having too many ShortBufferException thrown in ALTS code path on Java 8, we came up with this workaround creating new managed buffer, filling it, and passing it to underlying Conscrypt not to hit the code path throwing the exception. This might look to introduce another inefficiency but it's more like making it explicit because Conscrypt will do for non-managed buffer which gRPC uses. Fix: #6761
To avoid having too many ShortBufferException thrown in ALTS code path on Java 8, we came up with this workaround creating new managed buffer, filling it, and passing it to underlying Conscrypt not to hit the code path throwing the exception. This might look to introduce another inefficiency but it's more like making it explicit because Conscrypt will do for non-managed buffer which gRPC uses. Fix: grpc#6761
Under heavy traffic using ALTS, I briefly profiled the client to see where the cpu time went through VisualVM. It seems that it spent significant time running
javax.crypto.ShortBufferException.<init> ()
Hot spots (VisualVM)
Callstack for javax.crypto.ShortBufferException. (VisualVM)
Not sure how much these numbers reflect reality but it seems that there is room to improve. The reason why
ShortBufferException
is created and thrown is to trigger the caller to allocate a bigger output buffer. (code) Once it's caught, the callerCipherSpi
will create a temporary big enough buffer, decrypt the data into it by recalling the cipher, and copy it into the origianl output buffer. (code)Since this routine is being heavily called, it'd be great to have some optimization not to have
ShortBufferException
and cost caused by a temporary buffering.Environment
gRPC Java: 1.27.1
Conscrypt: 1.4.1
OpenJDK 64-Bit: 1.8.0_242
The text was updated successfully, but these errors were encountered: