You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have case where valueLoader for populating RedisCache is calling external service with long response time.
All value loads for same cache are synchronized, so N different values loaded in parallel takes N x external service response time for last one. What are possible risks if value loading is done concurrently?
I do not feel ready to submit PR (concurrent programming is hard), but I have created example (java 11) with something which seems to run concurrently :)
I'm using private key as discussed here: #2079 (comment)
Results:
23:57:24.568315 started 4 threads
23:57:24.569955 thread 1 acquiring value for key 2
23:57:24.569982 thread 0 acquiring value for key 1
23:57:24.569977 thread 3 acquiring value for key 4
23:57:24.569963 thread 2 acquiring value for key 3
23:57:24.570787 calculating value for key 1
23:57:26.571701 calculating value for key 3
23:57:26.571693 thread 0 got value for key 1
23:57:28.571964 thread 2 got value for key 3
23:57:28.571970 calculating value for key 2
23:57:30.572547 thread 1 got value for key 2
23:57:30.572562 calculating value for key 4
23:57:32.573019 thread 3 got value for key 4
23:57:32.573315 all done
Took 8 seconds
Concurrent implementation
23:57:32.574645 started 4 threads
23:57:32.574852 thread 0 acquiring value for key 1
23:57:32.574869 thread 1 acquiring value for key 2
23:57:32.574888 thread 2 acquiring value for key 3
23:57:32.574916 thread 3 acquiring value for key 4
23:57:32.577271 calculating value for key 1
23:57:32.577307 calculating value for key 3
23:57:32.577292 calculating value for key 2
23:57:32.577290 calculating value for key 4
23:57:34.578093 thread 0 got value for key 1
23:57:34.578093 thread 3 got value for key 4
23:57:34.578119 thread 1 got value for key 2
23:57:34.578098 thread 2 got value for key 3
23:57:34.578778 all done
Took 2 seconds
The text was updated successfully, but these errors were encountered:
Great to hear that you have a solution that works for you. We want to keep the RedisCache implementation as-is because this approach works for most of our users.
This is follow up to #2079
I have case where valueLoader for populating RedisCache is calling external service with long response time.
All value loads for same cache are synchronized, so N different values loaded in parallel takes N x external service response time for last one. What are possible risks if value loading is done concurrently?
I do not feel ready to submit PR (concurrent programming is hard), but I have created example (java 11) with something which seems to run concurrently :)
I'm using private key as discussed here: #2079 (comment)
Results:
23:57:24.568315 started 4 threads
23:57:24.569955 thread 1 acquiring value for key 2
23:57:24.569982 thread 0 acquiring value for key 1
23:57:24.569977 thread 3 acquiring value for key 4
23:57:24.569963 thread 2 acquiring value for key 3
23:57:24.570787 calculating value for key 1
23:57:26.571701 calculating value for key 3
23:57:26.571693 thread 0 got value for key 1
23:57:28.571964 thread 2 got value for key 3
23:57:28.571970 calculating value for key 2
23:57:30.572547 thread 1 got value for key 2
23:57:30.572562 calculating value for key 4
23:57:32.573019 thread 3 got value for key 4
23:57:32.573315 all done
Took 8 seconds
Concurrent implementation
23:57:32.574645 started 4 threads
23:57:32.574852 thread 0 acquiring value for key 1
23:57:32.574869 thread 1 acquiring value for key 2
23:57:32.574888 thread 2 acquiring value for key 3
23:57:32.574916 thread 3 acquiring value for key 4
23:57:32.577271 calculating value for key 1
23:57:32.577307 calculating value for key 3
23:57:32.577292 calculating value for key 2
23:57:32.577290 calculating value for key 4
23:57:34.578093 thread 0 got value for key 1
23:57:34.578093 thread 3 got value for key 4
23:57:34.578119 thread 1 got value for key 2
23:57:34.578098 thread 2 got value for key 3
23:57:34.578778 all done
Took 2 seconds
The text was updated successfully, but these errors were encountered: