diff --git a/CHANGELOG.md b/CHANGELOG.md index d6fab6709..0725a482e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Reduce memory consumption when returning large response that has been routed through a proxy server. [PR #1572](https://github.com/3scale/APIcast/pull/1572) [THREESCALE-12258](https://issues.redhat.com/browse/THREESCALE-12258) - Fix proxy policy doesn't send headers set by APIcast to the API Backend. [PR #1588](https://github.com/3scale/APIcast/pull/1588) [THREESCALE-10151](https://redhat.atlassian.net/browse/THREESCALE-10151) - Ensure the synchronization key is released correctly. [PR #1591](https://github.com/3scale/APIcast/pull/1590) +- Use new cpu.requests formula from Kubernetes. [PR #1595](https://github.com/3scale/APIcast/pull/1595) [THREESCALE-15465](https://redhat.atlassian.net/browse/THREESCALE-15465) ### Added - Update APIcast schema manifest [PR #1550](https://github.com/3scale/APIcast/pull/1550) diff --git a/gateway/src/apicast/cli/environment.lua b/gateway/src/apicast/cli/environment.lua index 95de38cb4..99644736a 100644 --- a/gateway/src/apicast/cli/environment.lua +++ b/gateway/src/apicast/cli/environment.lua @@ -60,7 +60,24 @@ local function cpu_shares() local weight = file:read('*n') file:close() - shares = (((weight - 1) * 262142) / 9999) + 2 + -- Recent version of runc/crun change the formula to calculate CPU weight + -- https://github.com/kubernetes/website/blob/main/content/en/blog/_posts/2026-01-30-new-cgroup-v1-to-v2-conversion-formula/index.md#new-conversion-formula + -- Old formula: + -- cpu.weight = (1 + ((cpu.shares - 2) * 9999) / 262142) + -- + -- New formula: + -- cpu.weight = ⌈ 10 ^ (L^2 / 612 + 125 * L / 612 − 7 / 34) + -- where: L=log2⁡(cpu.shares) (Please verify this with the code) + -- + -- So now we need to calculate CPU shares as follow: + -- cpu.shares = 2^L + -- L = (sqrt(16129 + 2448 * log10(cpu.weight)) - 125) / 2 + local a = math.log(weight, 10) + local b = 2448 * a + local c = 16129 + b + local d = math.sqrt(c) + local l = (d - 125)/2 + shares = math.ceil(2^l) end else -- Cgroups v1