TypeScript Templates Distributed_System - samchon/framework GitHub Wiki

Distributed System

A template module for Distributed Processing System in master side.

References

Conceptual Diagram

Conceptual Diagram

Class Diagram

Protocol - Distributed System

API Documents

Source Codes

Basic Classes

DistributedSystemArray

Master of Distributed Processing System.

The DistributedSystemArray is an abstract class containing and managing remote distributed slave system drivers, DistributedSystem objects. Within framework of network, DistributedSystemArray represents your system, a Master of Distributed Processing System that requesting distributed process to slave systems and the children DistributedSystem objects represent the remote slave systems, who is being requested the Distributed Processes.

You can specify this DistributedSystemArray class to be a server accepting distributed clients or a client connecting to distributed servers. Even both of them is possible. Extends one of them below and overrides abstract factory method(s) creating the child DistributedSystem object.

The DistributedSystemArray contains DistributedProcess objects directly. You can request Distributed Processes through the DistributedProcess object. You can access the DistributedProcess object(s) with those methods:

When you need the Distributed Process, call the DistributedProcess.sendData method. Then the DistributedProcess will find the most idle DistributedSystem object who represents a distributed slave system. The Invoke message will be sent to the most idle DistributedSystem object. When the Distributed Process has completed, then performance index and resource index of related objects will be revaluated.

Parallel Process

This DistributedSystemArray class is derived from the ParallelSystemArray class, so you can request the Parallel Processes, too.

When you need the a Parallel Process, then call one of them: sendSegmentData or sendPieceData. When the parallel process has completed, DistributedSystemArray estimates each DistributedSystem's performance index basis on their execution time. Those performance indices will be reflected to the next Parallel Process, how much pieces to allocate to each DistributedSystem.

DistributedSystem

A driver for a distributed slave system.

The DistributedSystem is an abstract class represents a slave system in Distributed Processing System, connected with this master system. This DistributedSystem takes full charge of network communication with the remote, distributed slave system has connected.

This DistributedSystem has a performance index that indicates how much the slave system is fast. The performance index is referenced and revaluated whenever those methods are called:

Note that, this DistributedSystem class derived from the ExternalSystem class. Thus, this DistributedSystem can also have children ExternalSystemRole objects exclusively. However, the children roles objects are different with the DistributedProcess. The domestic roles are belonged to only a specific DistributedSystem object. Otherwise, the DistributedProcess objects are belonged to a DistributedSystemArray object. Furthermore, the relationship between this DistributedSystem and DistributedProcess classes are M: N Associative.

Articles DistributedProcess ExternalSystemRole
Belonged to DistributedSystemArray DistributedSystem
Relationship M: N Associative 1: N Composite
Ownership References Exclusive possession
Performance index

The [performance index](#performance index) indicates how much fast the remote slave system (ParallelSystem) is.

If the DistributedSystem 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 DistributedSystem instances (that are belonged to a same DistributedSystemArray object).

You can specify the [performance index](#performance index) by yourself but notice that, if the [performance index](#performance index) is higher than other DistributedSystem objects, then the DistributedSystem 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 DistributedSystemArray.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.

DistributedProcess

A process of Distributed Processing System.

The DistributedProcess is an abstract class who represents a process, SOMETHING TO DISTRIBUTE in a Distributed Processing System. Overrides the DistributedProcess and defines the SOMETHING TO DISTRIBUTE.

Relationship between DistributedSystem and DistributedProcess objects are M: N Associative. Unlike ExternalSystemRole, the DistributedProcess objects are not belonged to a specific DistributedSystem object. The DistributedProcess objects are belonged to the DistributedSystemArrayMediator directly.

When you need the distributed process, then call sendData(). The sendData will find the most idle slave system considering not only number of processes on progress, but also performance index of each DistributedSystem object and resource index of this DistributedProcess object. The Invoke message requesting the distributed process will be sent to the most idle slave system.

Those performance index and resource index are revaluated whenever the distributed process has completed basis on the execution time.

Resource index

indicates how much the process is heavy.

If the process does not have any Invoke message had handled, then the resource index will be 1.0, which means default and average value between all DistributedProcess instances (that are belonged to a same DistributedSystemArray object).

You can specify the resource index by yourself, but notice that, if the resource index is higher than other DistributedProcess objects, then this role will be ordered to handle less processes than other DistributedProcess objects. Otherwise, the resource index is lower than others, of course, much processes will be requested.

setResource

Set resource index, but not fixed. The newly configured resource index can be changed by the revaluation.

estimateResource

Set resource index and it's fixed. The newly configured resource index can't be changed by the relvaluation.

ExternalSystemRole

This Distributed System module has implemented by extending the External System module. Thus, a DistributedSystem 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 DistributedSystem which is containing the ExternalSystemRole. Of course, the ExternalSystemRole is belonged to an DistributedSystem. However, if you access an ExternalSystemRole from an DistributedSystemArray directly, not passing by a belonged DistributedSystem, and send an Invoke message even you're not knowing which DistributedSystem 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 DistributedSystem object. Those pattern is called Proxy Pattern.

/// <reference types="samchon-framework.d.ts" />

import samchon = require("samchon-framework");
import protocol = samchon.protocol;
import distributed = samchon.templates.distributed;

//--------
// MANAGER OF EXTERNAL FILE SERVERS' DRIVERS
//--------
var file_servers: distributed.DistributedSystemArray;

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 Distributed Processing System

You can compose not only 1: N Distributed Processing System, but also tree-structured, recursive 1: N Distributed Processing System.

Conceptual Diagram

DistributedSystemArrayMediator

Mediator of Distributed Processing System.

The DistributedSystemArrayMediator class be a master for its slave systems, and be a slave to its master system at the same time. This DistributedSystemArrayMediator be a master system, containing and managing DistributedSystem objects, which represent distributed slave systems, by extending DistributedSystemArray class. Also, be a slave system through mediator object, which is derived from the SlaveSystem class.

As a master, you can specify this DistributedSystemArrayMediator 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 DistributedSystem object.

As a slave, you can specify this DistributedSystemArrayMediator 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 return one of them:

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:

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

Interaction

Conceptual Diagram

Interaction is an example implemented Tree-structured Distributed & Distributed Processing System. The Interaction provides ultimate guidance; how to use External System and its derived modules.

Go to the Interaction