Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion gateway/src/apicast/cli/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading