-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CPU and RAM limits for Docker containers (#54)
* Add CPU and RAM limits for Docker containers * Add cpu and memory limit to the API
- Loading branch information
1 parent
c913abc
commit eea0537
Showing
6 changed files
with
125 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package utils | ||
|
||
import log "github.com/sirupsen/logrus" | ||
|
||
func FindLimit(x, y int) int { | ||
if x == 0 { | ||
return y | ||
} | ||
if y == 0 { | ||
return x | ||
} | ||
if x < y { | ||
return x | ||
} | ||
return y | ||
} | ||
|
||
// Gets two memory limits and returns the smaller one as number of bytes | ||
func FindMemoryLimit(x, y string) int { | ||
// Check the global RAM Limit | ||
var global_ram_limit int64 | ||
if x != "" { | ||
bytes, err := ParseMemoryLimit(x) | ||
if err != nil { | ||
log.WithError(err).Errorf("Failed to parse global RAM limit %s", x) | ||
} else { | ||
global_ram_limit = bytes | ||
} | ||
} | ||
var step_ram_limit int64 | ||
if y != "" { | ||
bytes, err := ParseMemoryLimit(y) | ||
if err != nil { | ||
log.WithError(err).Errorf("Failed to parse step RAM limit %s", y) | ||
} else { | ||
step_ram_limit = bytes | ||
} | ||
} | ||
return FindLimit(int(step_ram_limit), int(global_ram_limit)) | ||
} |