Skip to content

Conversation

@bitfaster
Copy link
Owner

@bitfaster bitfaster commented Nov 14, 2023

When valueFactory fails, all the threads queuing on the lock inside Initializer will call valueFactory one by one. If 100 threads are queued, and the valueFactory takes 1 second to fail, the valueFactory will be invoked 100 times, and the last thread in the list will wait for 100 seconds before getting the exception. This is a lock convoy introducing unnecessary overhead.

With this change, the 100 queued threads will all instantly fail with the same exception, and there will be 100 times fewer valueFactory calls. Subsequent calls will start from scratch.

This solution is adapted from LazyWithRetry here:
https://stackoverflow.com/a/72579523/131345

@coveralls
Copy link

coveralls commented Nov 14, 2023

Coverage Status

coverage: 98.604% (-0.08%) from 98.681%
when pulling 24a79aa on users/alexpeck/atomicex
into 47a547e on main.

@bitfaster bitfaster marked this pull request as ready for review November 14, 2023 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants