Skip to content

Commit

Permalink
Set GOMAXPROCS=1 for less than 1 vCPU (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0mdau authored Dec 14, 2024
1 parent 3aa7dee commit c159b6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (t *Task) GetMaxProcs(ctx context.Context) (int, error) {
}

cpu := int(containerCPULimit) >> cpuUnits
// Set a minimum of 1 for containers with less than 1 vCPU
if cpu == 0 {
cpu = 1
}

taskCPULimit := int(task.Limits.CPU)
if taskCPULimit > 0 {
Expand Down
7 changes: 7 additions & 0 deletions internal/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ func TestTask_GetMaxProcs_GetsCPUUsingContainerLimit(t *testing.T) {
taskCPU int
testServer func(t *testing.T, containerCPU, taskCPU int) *httptest.Server
}{
{
name: "should get cpu of 1 when task CPU limit is 1 and container CPU limit is 512 vCPU",
wantCPU: 1,
containerCPU: 1 << 9,
taskCPU: 1,
testServer: testServerContainerLimit,
},
{
name: "should get cpu of 1 when task CPU limit is 1 and container CPU limit is 1024 vCPU",
wantCPU: 1,
Expand Down

0 comments on commit c159b6f

Please sign in to comment.