CPP Templates Parallel_System - samchon/framework GitHub Wiki
Parallel System
A template module for Parallel Processing System in master side.
References
Conceptual Diagram
Class Diagram
API Documents
Source Codes
Basic Classes
ParallelSystemArray
Master of Parallel Processing System.
The ParallelSystemArray is an abstract class containing and managing remote parallel slave system drivers, ParallelSystem objects. Within framework of network, ParallelSystemArray represents your system, a Master of Parallel Processing System that requesting Parallel Processes to slave systems.
You can specify this ParallelSystemArray class to be a server accepting parallel clients or a client connecting to parallel servers. Even both of them is possible. Extends one of them below and overrides abstract factory method(s) creating the child ParallelSystem object.
- ParallelClientArray: A server accepting parallel clients.
- ParallelServerArray: A client connecting to parallel servers.
- ParallelServerClientArray: Both of them. Accepts parallel clients and connects to parallel servers at the same time.
When you need the Parallel Process, then call one of them: sendSegmentData() or sendPieceData(). When the Parallel Process has completed, ParallelSystemArray estimates each ParallelSystem's performance index basis on their execution time. Those performance indices will be refelcted to the next Parallel Process, how much pieces will be allocated to each ParallelSystem.
/// <reference types="samchon-framework" />
import samchon = require("samchon-framework");
import protocol = samchon.protocol;
import parallel = samchon.templates.parallel;
let parallel_systems: parallel.ParallelSystemArray;
let invoke: protocol.Invoke = new protocol.Invoke("optimize");
parallel_systems.sendSegmentData(invoke, 1000);
ParallelSystem
A driver for a parallel slave system.
The ParallelSystem is an abstract class represents a slave system in Parallel Processing System, connected with this master system. The ParallelSystem takes full charge of network communication with the remote, parallel slave system has connected.
When a Parallel Process is requested (by ParallelSystemArray.sendSegmentData or ParallelSystemArray.sendPieceData), the number of pieces to be allocated to a ParallelSystem is turn on its [performance index](#performance index). Higher performance index, then more pieces are requested. The [performance index](#performance index) is revaluated whenever a parallel process has completed, basic on the execution time and number of pieces. You can sugguest or enforce the performance index with setPerformance or enforcePerformance.
Performance index
The [performance index](#performance index) indicates how much fast the remote slave system (ParallelSystem) is.
If the ParallelSystem does not have any Invoke message had handled, then the [performance index](#performance index) will be 1.0
, which means default and average value between all ParallelSystem instances (that are belonged to a same ParallelSystemArray object).
You can specify the [performance index](#performance index) by yourself but notice that, if the [performance index](#performance index) is higher than other ParallelSystem objects, then the ParallelSystem object will be ordered to handle more processes than others. Otherwise, the performance index is lower than others, of course, less processes will be delivered.
When ParallelSystemArray.sendSegmentData($something, 100)
has called,
Name | Performance index | Number of pieces to be allocated | Formula |
---|---|---|---|
Snail | 1 | 10 | 100 / 10 * 1 |
Cheetah | 4 | 40 | 100 / 10 * 4 |
Rabbit | 3 | 30 | 100 / 10 * 3 |
Turtle | 2 | 20 | 100 / 10 * 2 |
Unless enforcePerformance is called, this [performance index](#performance index) is revaluated whenever user calles one of them below.
setPerformance
Set [performance index](#performance index), but it's not fixed. The newly configured [performance index](#performance index) can be changed by the revaluation.
enforcePerformance
Set [performance index](#performance index) and it's fixed. The newly configured [performance index](#performance index) does not be revaluated.
ExternalSystemRole
This Parallel System module has implemented by extending the External System module. Thus, a ParallelSystem object can contain ExternalSystemRole objects and utilizing the Proxy Pattern is also possible.
A role belonged to an external system.
The ExternalSystemRole class represents a role, what to do. Extends this class and defines methods handling Invoke message, which are related the specified role, what to do.
ExternalSystemRole can be a Logical Proxy for an ParallelSystem which is containing the ExternalSystemRole. Of course, the ExternalSystemRole is belonged to an ParallelSystem. However, if you access an ExternalSystemRole from an ParallelSystemArray directly, not passing by a belonged ParallelSystem, and send an Invoke message even you're not knowing which ParallelSystem is related in, the ExternalSystemRole acted a role of proxy.
With the Logical Proxy, you can only concentrate on ExternalSystemRole itself, what to do with Invoke messages, irrespective of the ExternalSystemRole is belonged to which ParallelSystem object. Those pattern is called Proxy Pattern.
/// <reference types="samchon-framework.d.ts" />
import samchon = require("samchon-framework");
import protocol = samchon.protocol;
import parallel = samchon.templates.parallel;
//--------
// MANAGER OF EXTERNAL FILE SERVERS' DRIVERS
//--------
var file_servers: parallel.ParallelSystemArray;
var png_data: Uint8Array; // DATA TO SAVE
var invoke: protocol.Invoke = new protocol.Invoke("save", "my_picture", "png", png_data);
// MESSAGE TO SEND
//--------
// YOU CAN SEND AN INVOKE MESSAGE WITHOUT SPECIFYING TARGET SYSTEM
// THE ExternalSystemRole OBJECT WILL ACT A ROLE NAMED "PROXY"
//--------
file_servers.getRole("image").sendData(invoke);
Tree-structured Parallel Processing System
You can compose not only 1: N Parallel Processing System, but also tree-structured, recursive 1: N Parallel Processing System.
ParallelSystemArrayMediator
Mediator of Parallel Processing System.
The ParallelSystemArrayMediator class be a master for its slave systems, and be a slave to its master system at the same time. This ParallelSystemArrayMediator be a master system, containing and managing ParallelSystem objects, which represent parallel slave systems, by extending ParallelSystemArray class. Also, be a slave system through mediator object, which is derived from the SlavSystem class.
As a master, you can specify this ParallelSystemArrayMediator class to be a master server accepting slave clients or a master client to connecting slave servers. Even both of them is possible. Extends one of them below and overrides abstract factory method(s) creating the child ParallelSystem object.
- ParallelClientArrayMediator: A server accepting parallel clients.
- ParallelServerArrayMediator: A client connecting to parallel servers.
- ParallelServerClientArrayMediator: Both of them. Accepts parallel clients and connects to parallel servers at the same time.
As a slave, you can specify this ParallelSystemArrayMediator to be a client slave connecting to master server or a server slave accepting master client by overriding the createMediator method. Overrides the createMediator() method and returns one of them:
- A client slave connecting to master server:
- A server slave accepting master client:
MediatorSystem
A mediator, the master driver.
The MediatorSystem is an abstract class helping ParallelSystemArrayMediator can be a slave system. The MediatorSystem interacts and communicates with the master system as a role of slave.
This MediatorSystem object is created in ParallelSystemArrayMediator.createMediator. Override the method and return one of them, which are derived from this MediatorSystem class, considering which type and protocol the master system follows:
- A client slave connecting to master server:
- A server slave accepting master client:
When the master orders a parallel process to this slave, then the MediatorSystem delivers the parallel process to its parent ParallelSystemArrayMediator object. The ParallelSystemArrayMediator object distributes the parallel process to its slaves system, MediatorSystem objects. When the parallel process has completed, then MediatorSystem reports the result to its master.
Example Project
Related Modules
Referencing related modules, it will be much helpful for comprehending this Parallel System Module.
Name | Source | Documents |
---|---|---|
Distributed System | templates/distributed | API, Guidance |
Slave System | templates/slave | API, Guidance |
Interaction
Interaction is an example implemented Tree-structured Distributed & Parallel Processing System. The Interaction provides ultimate guidance; how to use External System and its derived modules.