2 #include <samchon/API.hpp> 4 #include <samchon/templates/parallel/ParallelSystemArray.hpp> 5 # include <samchon/templates/distributed/DistributedSystem.hpp> 6 # include <samchon/templates/distributed/DistributedProcess.hpp> 7 #include <samchon/templates/distributed/base/DistributedSystemArrayBase.hpp> 118 template <
class System = DistributedSystem>
121 public base::DistributedSystemArrayBase
139 virtual void construct(std::shared_ptr<library::XML> xml)
override 145 process_map_.clear();
148 if (xml->has(
"processes") ==
true && xml->get(
"processes")->front()->has(
"process") ==
true)
150 std::shared_ptr<library::XMLList> &role_xml_list = xml->get(
"processes")->front()->get(
"process");
151 for (
size_t i = 0; i < role_xml_list->size(); i++)
153 std::shared_ptr<library::XML> &role_xml = role_xml_list->at(i);
156 std::shared_ptr<DistributedProcess> role(
createProcess(role_xml));
157 role->construct(role_xml);
182 virtual auto _Complete_history(std::shared_ptr<slave::InvokeHistory> $history) ->
bool override 184 std::shared_ptr<DSInvokeHistory> history = std::dynamic_pointer_cast<
DSInvokeHistory>($history);
187 if (history ==
nullptr)
188 return super::_Complete_history($history);
196 if (history->getProcess() ==
nullptr)
200 estimate_system_performance(history);
201 estimate_process_resource(history);
204 _Normalize_performance();
208 virtual void _Normalize_performance()
override 211 super::_Normalize_performance();
215 size_t denominator = 0;
217 for (
auto it = process_map_.begin(); it != process_map_.end(); it++)
219 auto process = it->second;
220 if (process->_Is_enforced() ==
true)
223 average += process->getResource();
226 average /= (double)denominator;
229 for (
auto it = process_map_.begin(); it != process_map_.end(); it++)
231 auto process = it->second;
232 if (process->_Is_enforced() ==
true)
235 process->setResource(process->getResource() / average);
240 void estimate_process_resource(std::shared_ptr<DSInvokeHistory> history)
243 if (process->_Is_enforced() ==
true)
246 double average_elapsed_time_of_others = 0;
247 size_t denominator = 0;
250 for (
auto it = process_map_.begin(); it != process_map_.end(); it++)
253 if (my_process == process || my_process->_Get_history_list().empty() ==
true)
256 average_elapsed_time_of_others += my_process->_Compute_average_elapsed_time() * my_process->
getResource();
261 if (denominator != 0)
264 average_elapsed_time_of_others /= (double)denominator;
269 double elapsed_time = history->computeElapsedTime() / history->getWeight();
270 double new_performance = elapsed_time / average_elapsed_time_of_others;
273 double ordinary_ratio;
274 if (process->_Get_history_list().size() < 2)
275 ordinary_ratio = .15;
277 ordinary_ratio = min(.85, 1.0 / (process->_Get_history_list().size() - 1.0));
283 + (new_performance * (1 - ordinary_ratio))
288 void estimate_system_performance(std::shared_ptr<DSInvokeHistory> history)
291 if (system->_Is_enforced() ==
true)
294 double average_elapsed_time_of_others = 0;
295 size_t denominator = 0;
298 for (
size_t i = 0; i < this->size(); i++)
300 shared_ptr<DistributedSystem> system = this->at(i);
302 double avg = system->_Compute_average_elapsed_time();
306 average_elapsed_time_of_others += avg;
311 if (denominator != 0)
314 average_elapsed_time_of_others /= denominator;
319 double elapsed_time = history->computeElapsedTime() / history->getWeight();
320 double new_performance = average_elapsed_time_of_others / elapsed_time;
323 double ordinary_ratio;
324 if (system->_Get_history_list().size() < 2)
327 ordinary_ratio = min(0.7, 1.0 / (system->_Get_history_list().size() - 1.0));
333 + (new_performance * (1 - ordinary_ratio))
342 virtual auto toXML() const ->
std::shared_ptr<library::XML>
override 345 if (process_map_.empty() ==
true)
348 std::shared_ptr<library::XML> processes_xml(
new library::XML());
350 processes_xml->setTag(
"processes");
351 for (
auto it = process_map_.begin(); it != process_map_.end(); it++)
352 processes_xml->push_back(it->second->toXML());
354 xml->push_back(processes_xml);
virtual auto createProcess(std::shared_ptr< library::XML >) -> DistributedProcess *=0
auto getResource() const -> double
void setResource(double val)
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
virtual void construct(std::shared_ptr< library::XML > xml) override
Construct data of the Entity from an XML object.
void setPerformance(double val)
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityGroup.
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.
auto getPerformance() const -> double