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

feat: use weighted round robin in balancedPool #1069

Merged
merged 6 commits into from Jul 14, 2022
Merged

feat: use weighted round robin in balancedPool #1069

merged 6 commits into from Jul 14, 2022

Conversation

jodevsa
Copy link
Contributor

@jodevsa jodevsa commented Oct 20, 2021

lib/balanced-pool.js Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2021

Codecov Report

Merging #1069 (467f847) into main (5ca25c2) will increase coverage by 1.47%.
The diff coverage is 97.91%.

❗ Current head 467f847 differs from pull request most recent head 1b4bc6b. Consider uploading reports for the commit 1b4bc6b to get more accurate results

@@            Coverage Diff             @@
##             main    #1069      +/-   ##
==========================================
+ Coverage   94.90%   96.37%   +1.47%     
==========================================
  Files          50       37      -13     
  Lines        4608     2785    -1823     
==========================================
- Hits         4373     2684    -1689     
+ Misses        235      101     -134     
Impacted Files Coverage Δ
lib/balanced-pool.js 98.83% <97.91%> (-1.17%) ⬇️
index.js 84.28% <0.00%> (-15.72%) ⬇️
lib/core/util.js 89.47% <0.00%> (-9.22%) ⬇️
lib/api/readable.js 82.75% <0.00%> (-8.63%) ⬇️
lib/handler/redirect.js 87.34% <0.00%> (-7.60%) ⬇️
lib/proxy-agent.js 87.30% <0.00%> (-6.35%) ⬇️
lib/core/request.js 95.33% <0.00%> (-4.67%) ⬇️
lib/mock/mock-utils.js 96.92% <0.00%> (-3.08%) ⬇️
lib/fetch/dataURL.js
lib/fetch/request.js
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ca25c2...1b4bc6b. Read the comment docs.

lib/balanced-pool.js Outdated Show resolved Hide resolved
@jodevsa jodevsa requested a review from mcollina October 22, 2021 17:42
@jodevsa jodevsa changed the title WIP: use weighted round robin in balancedPool Use weighted round robin in balancedPool Oct 22, 2021
Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

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

I think this could use more comments in the code explaining the algorithm and also maybe some references to the paper.

lib/balanced-pool.js Outdated Show resolved Hide resolved
lib/balanced-pool.js Outdated Show resolved Hide resolved
@jodevsa
Copy link
Contributor Author

jodevsa commented Oct 30, 2021

I still have to fix the comments and make them better

lib/balanced-pool.js Outdated Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Could you test this against a few scenarios:

  1. an upstream is unavailable from the start, the algorithm should successfully route requests to working peers.
  2. the upstream become online. Request should start be fulfilled by the new upstream.
  3. the upstream go offline again. Requests should be routed to other upstreams.

lib/balanced-pool.js Outdated Show resolved Hide resolved
@ronag
Copy link
Member

ronag commented Oct 31, 2021

Rebase main and you will get kNeedDrain to use instead of busy.

@ronag
Copy link
Member

ronag commented Nov 19, 2021

@jodevsa you still intend to work on this?

@jodevsa
Copy link
Contributor Author

jodevsa commented Nov 19, 2021

@ronag yeah, but no time right now :( I might be able to work on it on Saturday. Please feel free to take over if this thing is blocking you :)

@ronag
Copy link
Member

ronag commented Nov 19, 2021

@ronag yeah, but no time right now :( I might be able to work on it on Saturday. Please feel free to take over if this thing is blocking you :)

Not blocking. Just curious.

test/balanced-pool.js Outdated Show resolved Hide resolved
test/balanced-pool.js Outdated Show resolved Hide resolved
test/balanced-pool.js Outdated Show resolved Hide resolved
@jodevsa
Copy link
Contributor Author

jodevsa commented Dec 5, 2021

@mcollina please don't review yet. I need to make the tests more understanable

@ronag ronag marked this pull request as draft December 5, 2021 09:16
lib/balanced-pool.js Outdated Show resolved Hide resolved
@kibertoad
Copy link
Contributor

Can I help with this one?

@mcollina
Copy link
Member

mcollina commented Jun 5, 2022

Go for it!

@kibertoad
Copy link
Contributor

@mcollina are the only remaining items the unaddressed comments and conflicts, or there is something else?

@mcollina
Copy link
Member

mcollina commented Jul 5, 2022

Unsure, this PR is still a draft from the author.

@jodevsa jodevsa closed this Jul 9, 2022
@jodevsa jodevsa reopened this Jul 9, 2022
@jodevsa jodevsa marked this pull request as ready for review July 9, 2022 12:16
@jodevsa
Copy link
Contributor Author

jodevsa commented Jul 9, 2022

Hi @mcollina, @ronag,

This PR is ready for reviewing again 🎉

@jodevsa jodevsa requested a review from ronag July 9, 2022 12:19
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina changed the title Use weighted round robin in balancedPool feat: use weighted round robin in balancedPool Jul 11, 2022
@jodevsa
Copy link
Contributor Author

jodevsa commented Jul 14, 2022

Hi guys, what are the next steps for getting this merged? are we missing more reviewers?

@mcollina mcollina merged commit 99205ec into nodejs:main Jul 14, 2022
@mcollina
Copy link
Member

Having @ronag would have been nice but he looks busy. Let's ship this.

pool[kWeight] = Math.max(1, pool[kWeight] - this[kErrorPenalty])
this._updateBalancedPoolStats()
}
})
Copy link
Member

Choose a reason for hiding this comment

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

This event handlers need to be removed in removeUpstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good find! I'll open another PR to address your comments

@@ -100,10 +145,42 @@ class BalancedPool extends PoolBase {
return
}

this[kClients].splice(this[kClients].indexOf(dispatcher), 1)
this[kClients].push(dispatcher)
const allClientsBusy = this[kClients].map(pool => pool[kNeedDrain]).reduce((a, b) => a && b, true)
Copy link
Member

Choose a reason for hiding this comment

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

.every

metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
* fixes

* more fixes

* add test

* remove console.log

* rename startingWeightPerServer to maxWeightPerServer

* add another test
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
* fixes

* more fixes

* add test

* remove console.log

* rename startingWeightPerServer to maxWeightPerServer

* add another test
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.

None yet

5 participants