1. Distributed Systems - EJB Tutorial · 1. Distributed Systems Master II –Software Engineering...

32
Imed Bouchrika. Distributed Objects , Uni of Souk-Ahras 2014-2015 http://www.imed.ws 1. Distributed Systems Master II Software Engineering Dr. Imed Bouchrika Dept of Mathematics & Computer Science University of Souk-Ahras [email protected]

Transcript of 1. Distributed Systems - EJB Tutorial · 1. Distributed Systems Master II –Software Engineering...

Imed Bouchrika. Distributed Objects , Uni of Souk-Ahras 2014-2015 http://www.imed.ws

1. Distributed Systems

Master II – Software Engineering

Dr. Imed BouchrikaDept of Mathematics & Computer Science

University of Souk-Ahras

[email protected]

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Centralized Application

Microsoft Word

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Centralized Application

Microsoft Word

Documents edited from different machines by different users ?

Document Size or number of documents depend on the size of hard drive ?

Computer Crashes or Hard drive fails ? Documents are lost without possible recovery ?

Software Upgrades ? Depends on the machine hardware and operating system

Upgrades limited to increase RAM and Disk space ?

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Centralized Applications

The application is housed on a single machine as a standalone system.

It contains all the functionalities of the system as one piece of software

In such systems : User Input ( GUI ..), verification, business logic and data access are all combined together.

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Centralized Application

As a result :

No need for network connectivity.

But

Any changes required to any part, may affect all the system.

New version release requires rolling to all computers which is sometimes impossible.

Even a simple change to part of the code requires compiling the whole system

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Case Study

CERN is the world's largest particle physics centre. Here physicists come to explore what matter is made of and what forces hold it together.

A new Collider: Large Hadron Collider (2007):

“machine used to shoot very small particles into each other at high speeds.”

Expected data: 10,000,000GB

Need 20,000,000 CDs to store

Solution: Distributed systems

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

What is a Distributed System ? Tanenbaum defines a distributed system as:

“a collection of independent computers that

appear to the users of the system as a single

computer”

independent : This means that, architecturally, the

machines are capable of operating independently.

single computer : The second point is that the software

enables this set of connected machines to appear as a

single computer to the users of the system.

7

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Centralized Application

Google Drive Docs

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

What is a Distributed System ? The figure below shows a simple distributed systems for a number of

applications running through different operating system

The middleware takes responsibility for the heterogeneity of the

communications.

9

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Middleware ?

Middleware is defined as :

“Middleware is a class of software technologies designed to

help manage the complexity and heterogeneity inherent in

distributed systems. It is defined as a layer of software above the

operating system but below the application program that provides a

common programming abstraction across a distributed system.”

Bakken 2001: Encyclopedia entry.

10

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Middleware ?

Protocols used by each middleware layer on different hosts should

be the same, as well as the interfaces they offer to applications.

11

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

WHY Distributed Systems ? Economics: a collection of microprocessors offer a better

price/performance than mainframes.

Speed: a distributed system may have more total computing power

than a mainframe. Enhanced performance through load distribution.

Inherent distribution: Some applications are inherently distributed.

Ex. a supermarket chain.

Reliability: If one machine crashes, the system as a whole can still

survive. Higher availability and improved reliability.

Incremental growth: Computing power can be added in small

increments. Modular expandability.

12

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

WHY Distributed Systems ? Data sharing: allow many users to access to a common data base

Resource Sharing: expensive peripherals like color printers

Communication: enhance human-to-human communication, e.g.,

email, chat

Flexibility: spread the workload over the available machines

Mobility : Access the system, data or resources from any place or

device.

…..

13

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Examples of Distributed Systems ?

Network file system, network printer etc

ATM (cash machine)

Distributed databases

Network computing

Global positioning systems

Retail point-of-sale terminals

Air-traffic control

Enterprise computing

WWW

.....

14

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Characteristics of Distributed Systems ? Fault-Tolerant: It can recover from component failures without performing

incorrect actions.

Highly Available: It can restore operations, permitting it to resume

providing services even when some components have failed.

Recoverable: Failed components can restart themselves and rejoin the

system, after the cause of failure has been repaired.

Consistent: The system can coordinate actions by multiple components

often in the presence of concurrency and failure

Scalable: It can operate correctly even as some aspect of the system is

scaled to a larger size.

Predictable Performance: The ability to provide desired responsiveness in

a timely manner.

Secure: The system authenticates access to data and services

15

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Challenges for Distributed Systems ?

16

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

HeterogeneityHeterogeneity (that is, variety and difference) applies to all of the

following:

Hardware devices: computers, tablets, mobile phones, embedded

devices, etc.

Operating System: Ms Windows, Linux, Mac, Unix, etc.

Network: Local network, the Internet, wireless network, satellite

links, etc.

Programming languages: Java, C/C++, Python, PHP, etc.

Different roles of software developers, designers, system

managers

17

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

TransparencyTransparency is defined as the concealment from the user and the

application programmer of the separation of components in a

distributed system,

Thus that the system is perceived as a whole rather than as a

collection of independent components.

In other words, distributed systems designers must hide the

complexity of the systems as much as they can

18

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

TransparencyAccess Hide differences in data representation and how a resource is

accessed

Location Hide where a resource is located

Migration Hide that a resource may move to another location

Relocation Hide that a resource may be moved to another location while

in use

Replication Hide that a resource may be copied in several places

Concurrency Hide that a resource may be shared by several

competitive users

Failure Hide the failure and recovery of a resource

Persistence Hide whether a (software) resource is in memory or a disk

19

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

OpennessThe openness of a computer system is the characteristic that

determines whether the system can be extended and re-

implemented in various ways.

If the well-defined interfaces for a system are published, it is easier

for developers to add new features or replace sub-systems in the

future.

Example: Twitter and Facebook have API that allows developers to

develop theirs own software interactively.

20

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

ConcurrencyBoth services and applications provide resources that can be shared

by clients in a distributed system:

There is therefore a possibility that several clients will attempt to

access a shared resource at the same time.

For example, a data structure that records bids for an auction

may be accessed very frequently when it gets close to the deadline

time.

For an object to be safe in a concurrent environment, its operations

must be synchronized in such a way that its data remains consistent.

This can be achieved by standard techniques such as semaphores,

which are used in most operating systems.

21

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

SecurityMany of the information resources that are made available and

maintained in distributed systems have a high intrinsic value to their

users.

Their security is therefore of considerable importance. Security for

information resources has three components:

Confidentiality (protection against disclosure to unauthorized

individuals).

Integrity (protection against alteration or corruption),

Availability for the authorized (protection against interference

with the means to access the resources).

22

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

ScalabilityDistributed systems must be scalable as the number of user increases.

The scalability is defined by B. Clifford Neuman as:

“A system is said to be scalable if it can handle the addition of users and

resources without suffering a noticeable loss of performance or increase in

administrative complexity”

Scalability has 3 dimensions:Size : Number of users and resources to be processed. Problem

associated is overloading.

Geography : Distance between users and resources. Problem associated

is communication reliability

Administration : As the size of distributed systems increases, many of the

system needs to be controlled. Problem associated is administrative mess

23

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Failure HandlingComputer systems sometimes fail.

When faults occur in hardware or software, programs :

may produce incorrect results

or may stop before they have completed the intended computation.

More components => increased fault rate

Increased possibilities

More redundancy => more possibilities for fault tolerance

No centralized control => no fatal failure

Issues

Detecting failures

Masking failures

Recovery from failures

Tolerating failures

Redundancy

24

Imed Bouchrika. Distributed Objects , Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Sockets Programming

Master II – Software Engineering

Dr. Imed BouchrikaDept of Mathematics & Computer Science

University of Souk-Ahras

[email protected]

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Java Hello World !Java Hello World !

public class Hello{

public static void main(String [] args){

System.out.println(“Hello Students. Address is : www.ejbtutorial.com”);

}

}

Compile & Run !

It runs LOCALLY only

26

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Java Hello Socket !import java.io.*;

import java.net.*;

public class Hello{

public static void main(String [] args){

try{

ServerSocket mysocket = new ServerSocket(5555);

Socket connectionSocket = mysocket.accept();

BufferedWriter writer = new

BufferedWriter(new OutputStreamWriter(connectionSocket.getOutputStream()));

writer.write("Hello Students. Address is : www.ejbtutorial.com");

writer.flush();

connectionSocket.close();

}catch(Exception e){e.printStackTrace();}

}

}

Compile & Run ?

27

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Java Hello Socket !You need to connect to it from a client on different machine: PuTTy

28

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Java Hello Socket !

29

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Java Hello Socket !import java.io.*;

import java.net.*;

public class Hello2{

public static void main(String [] args){

try{

ServerSocket mysocket = new ServerSocket(5500);

Socket connectionSocket = mysocket.accept();

BufferedReader reader =new

BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));

BufferedWriter writer = new

BufferedWriter(new OutputStreamWriter(connectionSocket.getOutputStream()));

writer.write("*** Type your name ***\r\n");

writer.flush();

String name = reader.readLine().trim();

writer.write("Hello "+name+". Address is : www.ejbtutorial.com");

writer.flush();

connectionSocket.close();

}catch(Exception e){e.printStackTrace();}

}

}

30

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

Java Hello Socket !

31

Imed Bouchrika. Distributed Objects, Uni of Souk-Ahras 2014-2015 http://www.imed.ws

To be Marked Next Week

32

Multi-Threaded Server

Extending the program to add :

Multiplication

Division

Subtraction