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

create UDP connection only when needed #825

Merged
merged 9 commits into from
Dec 20, 2020
Merged

create UDP connection only when needed #825

merged 9 commits into from
Dec 20, 2020

Conversation

mitnk
Copy link
Contributor

@mitnk mitnk commented Dec 19, 2020

A further step to try to fix #802

@coveralls
Copy link

coveralls commented Dec 19, 2020

Coverage Status

Coverage remained the same at 0.0% when pulling 4016a0d on mitnk:udp-idle into e9316f7 on xtaci:master.

@mitnk
Copy link
Contributor Author

mitnk commented Dec 19, 2020

Changed the logging items to let them more clear:

2020/12/19 14:51:01 main.go:447: accepted an TCP conn: 127.0.0.1:63581
2020/12/19 14:51:01 main.go:393: smux version: 1 on connection: 0.0.0.0:58146 -> x.x.x.x:12345
2020/12/19 14:51:04 main.go:447: accepted an TCP conn: 127.0.0.1:63583
2020/12/19 14:51:04 main.go:393: smux version: 1 on connection: 0.0.0.0:51598 -> x.x.x.x:12345
2020/12/19 14:51:06 main.go:447: accepted an TCP conn: 127.0.0.1:63585
2020/12/19 14:51:06 main.go:393: smux version: 1 on connection: 0.0.0.0:50933 -> x.x.x.x:12345
2020/12/19 14:51:21 main.go:488: scavenger: session closed due to ttl: 0.0.0.0:58146
2020/12/19 14:51:24 main.go:488: scavenger: session closed due to ttl: 0.0.0.0:51598
2020/12/19 14:51:26 main.go:488: scavenger: session closed due to ttl: 0.0.0.0:50933

@mitnk mitnk changed the title create UDP connection only when needed WIP: create UDP connection only when needed Dec 19, 2020
@mitnk
Copy link
Contributor Author

mitnk commented Dec 19, 2020

@xtaci Now that only when AutoExpire > that scavengettl will have meanings or routine scavengettl will have work to do:

if config.AutoExpire > 0 { // only when autoexpire set

So a question is that should we update option --scavengettl's description like `this option take effects only if AutoExpire is enabled? Or make logic change that scavengettl take effects no matter whether AutoExpire enabled or not?

@xtaci
Copy link
Owner

xtaci commented Dec 19, 2020

scavengettl make sense ONLY when autoexpire(actively switching to new connection) has set.

@mitnk mitnk changed the title WIP: create UDP connection only when needed create UDP connection only when needed Dec 19, 2020
@mitnk
Copy link
Contributor Author

mitnk commented Dec 19, 2020

@xtaci Ok, make sense to me. This PR is ready for review, please let me know if any adjust needed

@xtaci
Copy link
Owner

xtaci commented Dec 19, 2020

why setting nil for line 440

@mitnk
Copy link
Contributor Author

mitnk commented Dec 19, 2020

@xtaci Set sessions to nil when make the pool is because 1) there may no soon traffic coming to kcptun-client when it starts up and 2) make session's creation only happens in a single place (create only when a TCP conn accepted) which makes a better readability.

sessionList = append(sessionList, timedSession{
sess,
time.Now().Add(time.Duration(config.ScavengeTTL+config.AutoExpire) * time.Second)})
Copy link
Contributor Author

@mitnk mitnk Dec 20, 2020

Choose a reason for hiding this comment

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

Here in scavenger(), we better not depend on config.AutoExpire, instead to fetch the expire info from the session item. So that a change to the timedSession.expiryDate built logic won't need to touch the code in scavenger too.

@@ -152,7 +152,7 @@ GLOBAL OPTIONS:
--mode value profiles: fast3, fast2, fast, normal, manual (default: "fast")
--conn value set num of UDP connections to server (default: 1)
--autoexpire value set auto expiration time(in seconds) for a single UDP connection, 0 to disable (default: 0)
--scavengettl value set how long an expired connection can live(in sec), -1 to disable (default: 600)
--scavengettl value set how long an expired connection can live (in seconds) (default: 600)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see any place of using -1, so I guess the description need to be updated?

@mitnk
Copy link
Contributor Author

mitnk commented Dec 20, 2020

@xtaci I just updated a bit more. It's ready for another look. Please let me know if you'd like to do any adjustments.

@xtaci
Copy link
Owner

xtaci commented Dec 20, 2020

@mitnk
Copy link
Contributor Author

mitnk commented Dec 20, 2020

@xtaci hmm, good point. Updated.

@xtaci
Copy link
Owner

xtaci commented Dec 20, 2020

looks good to me .

@xtaci xtaci merged commit 2225d25 into xtaci:master Dec 20, 2020
@mitnk mitnk deleted the udp-idle branch December 20, 2020 11:46
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.

kcptun client consume 2~5% CPU power when idle
3 participants