Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Deprecate parTraverseN/parSequenceN with semaphore limit as Long #331

Conversation

satyamagarwal
Copy link
Contributor

Issue

324

Status

READY

Description

The current apis parTraverseN and parSequenceN use semaphore limit as Long type, and convert to Int which can lead to overflow issue.

This pr deprecates these methods, sets a validation check to fail the api if limit is more than Int range, and introduces new apis that takes limit as Int type.

Todos

  • Tests
  • Documentation

Deploy Notes

Would like help on if I need to do something about deploying @nomisRev

Related PRs

  • None

Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

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

Couple of small nits. Great catch @satyamagarwal! Thanks for keeping such a close eye on this!! 👏 👏 👏

PULL_REQUEST_TEMPLATE Outdated Show resolved Hide resolved
PULL_REQUEST_TEMPLATE Show resolved Hide resolved
@satyamagarwal
Copy link
Contributor Author

satyamagarwal commented Dec 14, 2020

I don't know what previous build integration does, but it is failing everytime it runs.

Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

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

Not sure how the build step managed to pass. The integration steps builds this project together with master of Arrow Core
There was a mistake in the tests, I tested this locally with the following stress test.

I also saw that we can add inline to the parTraverse.kt implementations, it requires the lambdas to be defined as crossinline f: suspend () -> Ato work properly.

checkAll(5000, Arb.constant(Unit)) { _ ->
  val ref = Atomic(0)
  (0 until 10_000)
    .map { suspend { ref.update { it + 1 } } }
    .parSequenceN(5)
  ref.get() shouldBe 10_00
}

Thanks again for the contribution @satyamagarwal! 👏 👏

@satyamagarwal
Copy link
Contributor Author

"parSequenceN can traverse effect full computations" {
    checkAll(5000, Arb.constant(Unit)) { _ ->
      val ref = Atomic(0)
      (0 until 10_000)
        .map { suspend { ref.update { it + 1 } } }
        .parSequenceN(5)
      ref.get() shouldBe 10_000
    }
  }

this test doesn't finish on my machine.

@satyamagarwal
Copy link
Contributor Author

I also saw that we can add inline to the parTraverse.kt implementations, it requires the lambdas to be defined as crossinline f: suspend () -> A to work properly.

This should probably be a new PR right ?

I can find time do it in a few days.

@nomisRev

@nomisRev
Copy link
Member

@satyamagarwal a new PR for that is fine! Doesn't need to be in this one 👍

Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

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

That stress test runs fine on my machine 🤔 It takes quite some time tho since it's launching 10_000 coroutines 5000 times, and it's doing so by limiting the parallelism to 5. 😀

}
}

"parSequenceN can traverse effect full computations" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this finally completed in 32 minutes. :D

Copy link
Member

Choose a reason for hiding this comment

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

Oh we probably don't want to push that test to CI 😅 I just linked it because that's what I tried locally before I realized we were using i from IntRange instead of from update.
It passed in 2-3 minutes locally for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay. I'll revert it :)

@satyamagarwal satyamagarwal force-pushed the deprecate-par-traverse-for-semaphore-argument branch from 0fa1172 to e0f85f5 Compare December 14, 2020 19:19
Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

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

Looks perfect! 👏 👏 Thank you so much for taking care of this @satyamagarwal

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

Thanks @satyamagarwal !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants