Skip to content
Merged
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
21 changes: 4 additions & 17 deletions proxy_agent/src/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,13 @@ pub async fn provision_timeout(
/// For Linux GPA service, it sets CPUQuota for azure-proxy-agent.service to limit the CPU usage
/// For Windows GPA service, it sets CPU and RAM limits for current process to limit the CPU and RAM usage
fn set_resource_limits() {
const CPU_QUOTA: u16 = 15;

#[cfg(not(windows))]
{
// Set CPUQuota for azure-proxy-agent.service to 15% to limit the CPU usage for Linux azure-proxy-agent service
// Linux GPA VM Extension is not required for Linux GPA service, it should not have the resource limits set in HandlerManifest.json file
const SERVICE_NAME: &str = "azure-proxy-agent.service";
const CPU_QUOTA: u16 = 15;
match proxy_agent_shared::linux::set_cpu_quota(SERVICE_NAME, CPU_QUOTA) {
Ok(_) => {
logger::write_warning(format!(
Expand All @@ -298,29 +299,15 @@ fn set_resource_limits() {

#[cfg(windows)]
{
// Set CPUQuota for GPA service process to limit the CPU usage for Windows GPA service
// As we need adjust the total CPU quota based on the number of CPU cores,
// Windows GPA VM Extension should not have the resource limits set in HandlerManifest.json file
let cpu_count = proxy_agent_shared::current_info::get_cpu_count();
let percent = if cpu_count <= 4 {
50
} else if cpu_count <= 8 {
30
} else if cpu_count <= 16 {
20
} else {
15
};

const RAM_LIMIT_IN_MB: usize = 20;
match proxy_agent_shared::windows::set_resource_limits(
std::process::id(),
percent,
CPU_QUOTA,
RAM_LIMIT_IN_MB,
) {
Ok(_) => {
logger::write_warning(format!(
"Successfully set current process CPU quota to {percent}% and RAM limit to {RAM_LIMIT_IN_MB}MB"
"Successfully set current process CPU quota to {CPU_QUOTA}% and RAM limit to {RAM_LIMIT_IN_MB}MB"
));
}
Err(e) => {
Expand Down
Loading