Fix synchronization for JWT increasing performance for token validation#726
Fix synchronization for JWT increasing performance for token validation#726zyclonite wants to merge 5 commits intoeclipse-vertx:masterfrom
Conversation
73ea166 to
0ead3a2
Compare
… in JWE and JWS Signed-off-by: Lukas Prettenthaler <rdx@wsn.at>
0ead3a2 to
b3d397e
Compare
|
I'm wondering if we could not store those in a thread local when the thread is a vertx thread (excluding virtual threads) otherwise create it as we go like you are doing |
|
Even calling If your thought was in a different direction, let me know |
|
I think that what @vietj suggests is to create a something like If you have time to do this it would be great. |
|
Understood but the Random use-case is a different one as this "should" be shared by definition, sharing the Signature object does not really add a lot of benefits from what i read so far. I can do some further tests if it adds any performance gain. |
|
Did conduct some tests and the results are: Using FastThreadLocal on a 12 core system had around 52ms versus 227ms with a plain I could not find a vert.x way of checking for |
|
have a look at my last commit if this is in the direction or your idea and let me know |
|
@zyclonite sorry for the late reply. I did an update for |
Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
|
took me a while to find some time... did a quick apply of your approach on the JWS impl as well but this approach would only work if the algorithm would always be the same for the same thread... that's the reason why the test fails now |
Store algorithms in an array for fast index search. Then use this index to retrieve the corresponding signature Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
|
@zyclonite I wanted to create a pull request to your repo with c7d5d59 but incidentally pushed directly to your branch. Anyway, that should fix the problem you mentioned in your previous comment. Do we have some evidence (e.g. microbenchmarks) that creating signatures and ciphers on the fly is more expensive than reusing them? |
|
@tsegismont looks great, thanks for that solution. I fear your example has the same issue -> |
I'm not sure what you mean |
|
initially i was referring to your commit 4126825 , that needs the same change with a selector on the algorithm, there is just no test that could fail in the same way. the other statement was to the JWE implementation itself. not only that no test exist, it could have never worked based on that line (only ifuse=sig and that makes no sense)so this class needs a proper implementation first, then tests but in a different PR. i looked a bit into it but this will require a lot of refactoring of the JWK implementation as well... |
|
@zyclonite thanks for clarifying. I think our immediate goal must be to fix the performance issue where the implementation is trusted and tested.
@pmlopes any comment on this? |
|
@zyclonite is there an opportunity for you to compare the performance of single-use ciphers/signatures vs fast thread local caching when running on a |
|
sorry, i lost a bit track of that issue and did not find time to do some extended testing but i am pretty sure it adds performance shall i discard that PR as @vietj has started refactoring the whole crypto part of the implementation? |
yes, you can, this code will be moved to vertx-core, you can help review the other PR later we will introduce fast thread local in the code moved to vertx-core that will be easier to implement |
Motivation:
The observation was that reusing objects like Signature, Cipher and Mac and running it within synchronization blocks has a big impact on application performance. Used in a handler it serializes all eventloop threads and potentially introduces a lot of wait for all other threads.
Using the
Signature.getInstance(String algorithm)does not add a lot of overhead and is then safe to use within the same context for the operation.Doing some performance tests on EC256 signatures got me nearly the same performance multiplicator as CPU cores available.