Skip to content
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

STM - Next level #863

Merged
merged 3 commits into from May 17, 2019
Merged

STM - Next level #863

merged 3 commits into from May 17, 2019

Conversation

jdegoes
Copy link
Member

@jdegoes jdegoes commented May 17, 2019

A little light airplane coding to improve performance of STM, as well as Promise and Queue. A quick look at Queue reveals lots of low hanging fruit. STM is getting in good shape (performance competitive with and in some cases better than Ref + Promise) but still needs some intelligence around overlapping retries.

for {
surplus <- IO.effectTotal {
val as = unsafeOfferAll(queue, remaining.toList)
unsafeCompleteTakers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add () otherwise dotty complains.
Nice simplification!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

def suspend(journal: Journal): Unit = {
addTodo(txnId, journal, () => tryCommitAsync(null, platform, stm, txnId, done)(k))

if (isInvalid(journal)) tryCommit(platform, stm) match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is super clean, but I don't understand this line. Isn't it redundant with the line above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In between the time when the STM was executed and the "todo" was added, it may happen that the variables underlying the transaction have changed (by some other transaction), and the "todo" lists cleared by that transaction. In this case, the suspended transaction would never be retried. This line detects this case, and re-runs the transaction again if necessary.

This way of structuring the code allows dramatic minimization of the commit lock, albeit at the cost of trickier reasoning about correctness.

Copy link
Member

@regiskuckaertz regiskuckaertz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yesterday I did a presentation of STM at the guardian, super psyched to start using it on our projects 🎉

@jdegoes jdegoes merged commit dfbb551 into zio:master May 17, 2019
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.

None yet

3 participants