-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Added variable latency delay, normal and uniform based #2871
Conversation
func VariableNormal(t, std time.Duration) D { | ||
v := &variableNormal{ | ||
std: std, | ||
rng: rand.New(rand.NewSource(int64(time.Now().Nanosecond()))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using one random source per one delay instance runs risk of it being used just one time.
Pseudo Random Generators used just one time will not generate uniformly distributed random numbers.
I would recommend using one package wide random generator.
@Kubuxu, thanks for the feedback. |
Right, I missed that. Apart from that, LGTM, thank you. |
@Kubuxu - yep, fixed that. Thanks! |
LGTM |
"sync" | ||
"time" | ||
) | ||
|
||
var sharedRNG = rand.New(rand.NewSource(int64(time.Now().Nanosecond()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of .Nanosecond()
we could use .UnixNano()
, saves a cast
one comment, then LGTM |
- Allow providing new delays with your own rng / use shared rng License: MIT Signed-off-by: Or Rikon <rikonor@gmail.com>
@whyrusleeping, using |
cool, LGTM. Thanks! |
This doesn't seem like it's used anywhere? |
@lgierth I don't believe that it is. I was just looking for something to do and ended up implementing that. Hope that it can help at some point in the future. |
We currently do local network dialups in bursts. This is somewhere we can use it. |
Maybe this type of thing could be useful as a libp2p transport?
|
We might move it to utility package to use it in libp2p to not send dials in bursts, it isn't huge issues right now. |
@jbenet aren't you having a day off? Go out and play :) |
Hey,
I saw the todo for random delays and thought I'd give it a go.
License: MIT
Signed-off-by: Or rikonor@gmail.com