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

Added perPeerRateLimit env config #1580

Merged
merged 10 commits into from
Jun 14, 2022
Merged

Added perPeerRateLimit env config #1580

merged 10 commits into from
Jun 14, 2022

Conversation

millken
Copy link
Contributor

@millken millken commented May 31, 2022

Fix #1579

@marten-seemann marten-seemann requested a review from vyzo May 31, 2022 13:32
return newDialLimiterWithParams(df, fd, DefaultPerPeerRateLimit)
perPeerRateLimit := DefaultPerPeerRateLimit
if env := os.Getenv("LIBP2P_SWARM_PEER_RATE_LIMIT"); env != "" {
if n, err := strconv.ParseInt(env, 10, 32); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should at least log the error here.
Also, why the 32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to unify with the code above.

@vyzo vyzo self-requested a review May 31, 2022 13:38
@vyzo
Copy link
Contributor

vyzo commented May 31, 2022

sorry accidental early approval; other than the log though, i think this is mostly fine.

Even better to parse the envvar once in init and set the default.

@marten-seemann
Copy link
Contributor

Not a big fan of making this configurable via environment variable.
The best fix would be to make the swarm injectable, and then use a constructor option. The next-better fix would be to have a package-level global variable.

@millken
Copy link
Contributor Author

millken commented Jun 1, 2022

Yes, I agree with you, adding environment variables can keep the existing code unchanged for the purpose of modifying it.

Not a big fan of making this configurable via environment variable. The best fix would be to make the swarm injectable, and then use a constructor option. The next-better fix would be to have a package-level global variable.

@MarcoPolo
Copy link
Collaborator

Not a big fan of making this configurable via environment variable.
The best fix would be to make the swarm injectable, and then use a constructor option. The next-better fix would be to have a package-level global variable.

Agreed. @millken mind making the package level global change please? It’s better since then this is exposed prominently in the pkg reference, and your code can read your env var and set the variable.

@BigLep BigLep added the need/author-input Needs input from the original author label Jun 3, 2022
@millken
Copy link
Contributor Author

millken commented Jun 6, 2022

Not a big fan of making this configurable via environment variable.
The best fix would be to make the swarm injectable, and then use a constructor option. The next-better fix would be to have a package-level global variable.

Agreed. @millken mind making the package level global change please? It’s better since then this is exposed prominently in the pkg reference, and your code can read your env var and set the variable.

Updated

config/config.go Outdated
@@ -104,6 +104,9 @@ type Config struct {

EnableHolePunching bool
HolePunchingOptions []holepunch.Option

FDLimit int
PerPeerLimit int
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no way for a libp2p user to directly set values in this config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, forgot to add, update again.

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

I don't think we should have global config options for this. This seems overly specific.
Why don't you just add a variable, as @MarcoPolo suggested in #1580 (comment).

@millken
Copy link
Contributor Author

millken commented Jun 14, 2022

I don't think we should have global config options for this. This seems overly specific. Why don't you just add a variable, as @MarcoPolo suggested in #1580 (comment).

Ok, only change const DefaultPerPeerRateLimit = 8 to var DefaultPerPeerRateLimit = 8

@MarcoPolo MarcoPolo merged commit 5a06093 into libp2p:master Jun 14, 2022
@MarcoPolo
Copy link
Collaborator

Thanks!

@millken millken deleted the patch-1 branch June 19, 2022 02:50
MarcoPolo pushed a commit that referenced this pull request Jun 24, 2022
Expose DefaultPerPeerRateLimit as var
@MarcoPolo MarcoPolo mentioned this pull request Jul 7, 2022
41 tasks
@ajnavarro ajnavarro mentioned this pull request Aug 24, 2022
72 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need/author-input Needs input from the original author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there a way to dynamically configure DefaultPerPeerRateLimit?
5 participants