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

Fancy throttle #242

Merged
merged 6 commits into from
Feb 9, 2019
Merged

Fancy throttle #242

merged 6 commits into from
Feb 9, 2019

Conversation

3noch
Copy link
Member

@3noch 3noch commented Nov 5, 2018

No description provided.

@lspitzner
Copy link
Contributor

This reminds me of #184 which has some similar constructs.

Also, at a glance I wonder if there is much use to using Semigroup if you are not forcing the intermediate value.

@ElvishJerricco
Copy link
Contributor

That is a fancy throttle! Nice!

@lspitzner
Copy link
Contributor

lspitzner commented Nov 5, 2018

Does this behave as expected for a delay of 5s and a example input signal that fires once every second? If I am reading things correctly, the delayed signals are not filtered, meaning that after 5 seconds, the delayed signal fires every second too, which turns immediate mode back on at the same rate. So you get 1 output, 5s pause, 4 merged outputs, and then every (other?) second some output. Whether it is every second or every other probably is not deterministic due to continuous-time/fuzzy delays.
(edit: i did not read things correctly :p)

I'd expect proper 5s intervals of silence, as you'd get if only the non-immediate-mode-entering signals trigger, after a delay, the back-to-immediate-mode switch.

@ali-abrar
Copy link
Member

@3noch (maybe a question for James) do we have a test that would answer @lspitzner's question?

We should definitely figure out how this interacts/overlaps with #184 before merging.

@cgibbard may also have some thoughts as the throttle code here seems to be an upgraded version of something he wrote (that somehow never made it to develop..)

throttle :: (MonadFix m, MonadHold t m, PerformEvent t m, TriggerEvent t m, MonadIO (Performable m)) => NominalDiffTime -> Event t a -> m (Event t a)

@3noch
Copy link
Member Author

3noch commented Nov 6, 2018

cc @xplat

@xplat
Copy link
Contributor

xplat commented Nov 6, 2018

Does this behave as expected for a delay of 5s and a example input signal that fires once every second? If I am reading things correctly, the delayed signals are not filtered, meaning that after 5 seconds, the delayed signal fires every second too, which turns immediate mode back on at the same rate. So you get 1 output, 5s pause, 4 merged outputs, and then every (other?) second some output. Whether it is every second or every other probably is not deterministic due to continuous-time/fuzzy delays.

I'd expect proper 5s intervals of silence, as you'd get if only the non-immediate-mode-entering signals trigger, after a delay, the back-to-immediate-mode switch.

I had exactly the same question after reading the code for throttle. @cgibbard gave me the answer -- the delay is fired based on the output events, not the input events. So the first output, 5s pause, 4 merged outputs, and then nothing until 5 seconds after the 4 merged outputs.

It's all twisty, but it works.

@lspitzner
Copy link
Contributor

Right, i should have noticed that. sorry. Looks fine to me!

(and regarding functionality overlap: I think it is worth having this function in addition to the #184 ones. Even if you could express fancy-throttle in terms of gateGather, as I suspect you can.)

@sboosali
Copy link

sboosali commented Nov 7, 2018 via email

@ali-abrar
Copy link
Member

ali-abrar commented Nov 8, 2018 via email

@3noch 3noch force-pushed the jd-fancy-throttle branch from 4bdf228 to ad74fe5 Compare November 13, 2018 19:49
Should be suitable for throttling ViewSelector updates in rhyolite.
@3noch 3noch force-pushed the jd-fancy-throttle branch from ad74fe5 to 2e2e19d Compare November 21, 2018 21:06
@matthewbauer
Copy link
Member

matthewbauer commented Jan 15, 2019

It would be good to get this merged.

@luigy
Copy link
Member

luigy commented Jan 15, 2019

pinging @cgibbard since I believe you were somewhat involved in this? afaik this has been in use in prod for some time

@@ -35,6 +35,7 @@ import Data.Time.Clock
import Data.Typeable
import GHC.Generics (Generic)
import System.Random
import Data.Semigroup
Copy link
Member Author

Choose a reason for hiding this comment

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

The imports were alphabetized prior to this change

Prelude in ghc 8.0 does not come with Semigroup. Importing it directly
works in 8.0, 8.2, and 8.4.
@tomsmalley
Copy link
Member

throttleBatchWithLag pure causes a hang which leads to a stack overflow. Granted, the docs say that the "lag" function should construct an event, but we should at least give a stronger warning there.

@3noch
Copy link
Member Author

3noch commented Jan 25, 2019

@tomsmalley Yikes. I wonder if there's some "innocuous" operation we can do to ensure pure doesn't work. Something like delay 0 =<< but I don't know if that would cause unintended consequences.

@3noch
Copy link
Member Author

3noch commented Jan 25, 2019

Actually I'm sure it would have bad consequences...but perhaps something else.

@ali-abrar ali-abrar merged commit 49c1dec into develop Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.