Distributed applications
The so-called distributed computing is a computer science that studies how to divide a problem that requires very large computational power into small parts, and then allocates these parts to many computers for processing, finally synthesizing the results to get the final result.
Benefits of distributed
Geographical dispersion
such as the banking system, the head office and the branches in different cities or cities in various regions, in the business they need to deal with their own data, but also need to exchange and deal with each other, which requires a distributed system.
Meet Scalability
If an organization needs to add new and relatively autonomous organizational units to augment the Organization, the distributed database system can be expanded with minimal impact on the current organization.
Balanced load
The decomposition of the data by the use of local applications to achieve maximum, which makes the mutual interference between the processors to a minimum. The load is shared between processors to avoid critical bottlenecks.
Distributed database
And when the need for global application increases, the database can be formed from the bottom up of the distributed database system.
Reliability
The distributed database system with equal scale will not be lower than the centralized database system in the probability of failure, but because of its failure is limited to the local data application, so it is more reliable for the whole system.
Remoting
A distributed processing method, from the Microsoft product point of view, it can be said that remoting is an upgrade of DCOM, it has improved a lot of features, and excellent integration. NET platform.
Microsoft. NET Remoting provides a framework that allows an object to interact with another object through an application domain. That's why we use Remoting.
There are three ways to communicate: HTTP, TCP, IPC
HTTP across firewalls;
TCP is usually in the local area network, the speed is fast;
IPC is used for the same machine between processes.
Development Remoting (i)
1. Create a remote object:
Public class Helloserver:marshalbyrefobject { public HelloServer () { /// output information, server activated Console.WriteLine (" server Activation ... ..") " ); } Public string HelloMethod (string name) { return" here is:" + name; } }
2. Create the host application:
/**/ /// Create a TCP channel New TcpChannel (8085); /**/ /// Register Channel false ); RemotingConfiguration.RegisterWellKnownServiceType (typeof"helloserver ", Wellknownobjectmode.singleton);
3. Create the client program:
///using TCP channels to get remote objectsTcpChannel Chan1 =NewTcpChannel (); ChannelServices.RegisterChannel (Chan1,false); HelloServer Obj1= (HelloServer) Activator.GetObject (typeof(Consoleserver.helloserver),"Tcp://localhost:8085/helloserver"); if(Obj1 = =NULL) {System.Console.WriteLine ("failed to connect to the TCP server"); } MessageBox.Show (Obj1. HelloMethod ("Hello"));Development Remoting (II)
1. Profile-Server
<configuration> <system.runtime.remoting> <application> <service> <wellknown mo De="SingleCall"Type="Consoleserver.helloserver, Consoleserver"Objecturi="HelloServer"/> </service> <channels> <channelref="TCP"port="9000"> </channel> </channels> </application> </system.runtime.remoting></configur Ation>
// Service-side code:
RemotingConfiguration.Configure ("ConsoleServer.exe.config", false);
2. Profile-Client
<system.runtime.remoting> <application> <client> <wellknown type=" Consoleserver.helloserver,consoleserver " url="tcp://192.168.0.3:9000/helloserver "/> </client> </application> </system.runtime.remoting>
// Client code: System.Runtime.Remoting.RemotingConfiguration.Configure ("RemotingClient.exe.config" ,false);
Development Remoting (III)
Pumped interface
Public Interface Iserverinterface { string HelloMethod (string name); }
Service side:
Public classHelloserver:marshalbyrefobject, Iserverinterface { PublicHelloServer () {///output information, server activationConsole.WriteLine ("Server Activation ..."); } Publicstring HelloMethod (string name) {Console.WriteLine ("Server side: {0}", name); return "here is:"+name; } }
// Service-Side Execution code: RemotingConfiguration.Configure ("ConsoleServer.exe.config"false);
Client:
// Client configuration file <configuration> <appSettings> <add key="tcp" Value="tcp://localhost:9000/helloserver"/> </appsettings></ Configuration>
Iserverinterface SEv = (iserverinterface) activator.getobject (typeof(Iserverinterface), configurationmanager.appsettings["tcp"]. ToString ()); MessageBox.Show (SEv. HelloMethod ("hello"));
Some concepts
server-side activation: also known as Wellknow mode, many are translated into well-known objects. Why is it called a well-known object activation mode? is because the server application publishes this type on a well-known Uniform Resource Identifier (URI) before activating the object instance. The server process then configures a WellKnown object for this type and publishes the object based on the specified port or address.
server-side activation is also divided into singleton mode and SingleCall mode two kinds: Singleton mode: This is a stateful mode. If set to singleton activation mode, remoting will establish the same object instance for all clients. When an object is active, the singleton instance processes all subsequent client access requests, whether they are the same client or another client. The singleton instance will maintain its state in the method call. We can think of it as a application state. SingleCall mode: SingleCall is a stateless mode. Once set to SingleCall mode, when the client invokes the method of the remote object, remoting establishes a remote object instance for each client, and the destruction of the object instance is automatically managed by the GC. As an example above, the two customers accessing the remote object received 1. We think of it as a session state.
Distributed Application processing mode-Remoting