-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathRAMConfigGenerator.cpp
More file actions
150 lines (138 loc) · 6.2 KB
/
Copy pathRAMConfigGenerator.cpp
File metadata and controls
150 lines (138 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause-Clear
#include "RAMConfigGenerator.h"
#include "Logger.h"
// Low RAM Profile (< 4GB)
// Conservative settings to minimize memory usage
RAMConfigGenerator::ConfigProfile RAMConfigGenerator::getLowRAMProfile() {
ConfigProfile profile;
profile.maxConcurrentRequests = 30;
profile.maxResourcesPerRequest = 10;
profile.threadPoolDesiredCapacity = 3;
profile.threadPoolMaxScalingCapacity = 6;
profile.pulseDuration = 30000;
profile.garbageCollectionDuration = 1500;
profile.garbageCollectionBatchSize = 10;
profile.rateLimiterDelta = 3;
profile.penaltyFactor = 2.5;
profile.rewardFactor = 0.3;
return profile;
}
// Medium RAM Profile (4GB - 8GB)
// Balanced settings - similar to current defaults
RAMConfigGenerator::ConfigProfile RAMConfigGenerator::getMediumRAMProfile() {
ConfigProfile profile;
profile.maxConcurrentRequests = 60;
profile.maxResourcesPerRequest = 20;
profile.threadPoolDesiredCapacity = 5;
profile.threadPoolMaxScalingCapacity = 10;
profile.pulseDuration = 23000;
profile.garbageCollectionDuration = 1000;
profile.garbageCollectionBatchSize = 20;
profile.rateLimiterDelta = 5;
profile.penaltyFactor = 2.0;
profile.rewardFactor = 0.4;
return profile;
}
// High RAM Profile (8GB - 64GB)
// Aggressive settings for better performance
RAMConfigGenerator::ConfigProfile RAMConfigGenerator::getHighRAMProfile() {
ConfigProfile profile;
profile.maxConcurrentRequests = 75;
profile.maxResourcesPerRequest = 30;
profile.threadPoolDesiredCapacity = 8;
profile.threadPoolMaxScalingCapacity = 16;
profile.pulseDuration = 18000;
profile.garbageCollectionDuration = 800;
profile.garbageCollectionBatchSize = 30;
profile.rateLimiterDelta = 7;
profile.penaltyFactor = 1.8;
profile.rewardFactor = 0.5;
return profile;
}
// Very High RAM Profile (> 64GB)
// Maximum performance settings
RAMConfigGenerator::ConfigProfile RAMConfigGenerator::getVeryHighRAMProfile() {
ConfigProfile profile;
profile.maxConcurrentRequests = 100;
profile.maxResourcesPerRequest = 50;
profile.threadPoolDesiredCapacity = 12;
profile.threadPoolMaxScalingCapacity = 24;
profile.pulseDuration = 15000;
profile.garbageCollectionDuration = 600;
profile.garbageCollectionBatchSize = 40;
profile.rateLimiterDelta = 10;
profile.penaltyFactor = 1.5;
profile.rewardFactor = 0.6;
return profile;
}
RAMConfigGenerator::ConfigProfile RAMConfigGenerator::getProfileForTier(const std::string& ramTier) {
if (ramTier == "low") {
LOGI("RAM_CONFIG_GEN", "Using LOW RAM configuration profile");
return getLowRAMProfile();
} else if (ramTier == "medium") {
LOGI("RAM_CONFIG_GEN", "Using MEDIUM RAM configuration profile");
return getMediumRAMProfile();
} else if (ramTier == "high") {
LOGI("RAM_CONFIG_GEN", "Using HIGH RAM configuration profile");
return getHighRAMProfile();
} else if (ramTier == "very_high") {
LOGI("RAM_CONFIG_GEN", "Using VERY_HIGH RAM configuration profile");
return getVeryHighRAMProfile();
} else {
LOGW("RAM_CONFIG_GEN", "Unknown RAM tier: " + ramTier + ", using MEDIUM profile");
return getMediumRAMProfile();
}
}
std::string RAMConfigGenerator::getConfigValue(const std::string& propertyName,
const std::string& ramTier) {
ConfigProfile profile = getProfileForTier(ramTier);
if (propertyName == "resource_tuner.maximum.concurrent.requests") {
return std::to_string(profile.maxConcurrentRequests);
} else if (propertyName == "resource_tuner.maximum.resources.per.request") {
return std::to_string(profile.maxResourcesPerRequest);
} else if (propertyName == "resource_tuner.thread_pool.desired_capacity") {
return std::to_string(profile.threadPoolDesiredCapacity);
} else if (propertyName == "resource_tuner.thread_pool.max_scaling_capacity") {
return std::to_string(profile.threadPoolMaxScalingCapacity);
} else if (propertyName == "resource_tuner.pulse.duration") {
return std::to_string(profile.pulseDuration);
} else if (propertyName == "resource_tuner.garbage_collection.duration") {
return std::to_string(profile.garbageCollectionDuration);
} else if (propertyName == "resource_tuner.garbage_collection.batch_size") {
return std::to_string(profile.garbageCollectionBatchSize);
} else if (propertyName == "resource_tuner.rate_limiter.delta") {
return std::to_string(profile.rateLimiterDelta);
} else if (propertyName == "resource_tuner.penalty.factor") {
return std::to_string(profile.penaltyFactor);
} else if (propertyName == "resource_tuner.reward.factor") {
return std::to_string(profile.rewardFactor);
}
return "";
}
std::unordered_map<std::string, std::string>
RAMConfigGenerator::getAllConfigs(const std::string& ramTier) {
std::unordered_map<std::string, std::string> configs;
ConfigProfile profile = getProfileForTier(ramTier);
configs["resource_tuner.maximum.concurrent.requests"] =
std::to_string(profile.maxConcurrentRequests);
configs["resource_tuner.maximum.resources.per.request"] =
std::to_string(profile.maxResourcesPerRequest);
configs["resource_tuner.thread_pool.desired_capacity"] =
std::to_string(profile.threadPoolDesiredCapacity);
configs["resource_tuner.thread_pool.max_scaling_capacity"] =
std::to_string(profile.threadPoolMaxScalingCapacity);
configs["resource_tuner.pulse.duration"] =
std::to_string(profile.pulseDuration);
configs["resource_tuner.garbage_collection.duration"] =
std::to_string(profile.garbageCollectionDuration);
configs["resource_tuner.garbage_collection.batch_size"] =
std::to_string(profile.garbageCollectionBatchSize);
configs["resource_tuner.rate_limiter.delta"] =
std::to_string(profile.rateLimiterDelta);
configs["resource_tuner.penalty.factor"] =
std::to_string(profile.penaltyFactor);
configs["resource_tuner.reward.factor"] =
std::to_string(profile.rewardFactor);
return configs;
}