7/25/2019 03 - 50 - 3 -
1/50
3
7/25/2019 03 - 50 - 3 -
2/50
1 - Java Sockets) Echo service
Java 4.5 4.6 (www.cdk5.net/ipc) echo TCP streams. server client. : java TCPServer
java TCPClient Hello SDY50 Tomos Blocalhost
server IP port number /
2
7/25/2019 03 - 50 - 3 -
3/50
Fig. 4.5 TCPClient
import java.net.*;
import java.io.*;
public class TCPClient {
public static void main (String args[]) {
// arguments supply message and hostname of destination
Socket s = null;
try{
int serverPort = 7896;
s = new Socket(args[1], serverPort);
DataInputStream in = new DataInputStream( s.getInputStream());
DataOutputStream out =
new DataOutputStream( s.getOutputStream());
out.writeUTF(args[0]); // UTF is a string encoding see Sn 4.3
String data = in.readUTF();
System.out.println("Received: "+ data) ;}catch (UnknownHostException e){
System.out.println("Sock:"+e.getMessage());
}catch (EOFException e){System.out.println("EOF:"+e.getMessage());
}catch (IOException e){System.out.println("IO:"+e.getMessage());}
}finally {if(s!=null) try {s.close();}catch (IOException
e){System.out.println("close:"+e.getMessage());}}
}
}
TCP client makes connection to server, sends request and receives reply
7/25/2019 03 - 50 - 3 -
4/50
import java.net.*;
import java.io.*;
public class TCPServer {
public static void main (String args[]) {
try{
int serverPort = 7896;
ServerSocket listenSocket = new ServerSocket(serverPort);
while(true) {
Socket clientSocket = listenSocket.accept();
Connection c = new Connection(clientSocket);
}} catch(IOException e) {System.out.println("Listen :"+e.getMessage());}
}
}
// this figure continues on the next slide
Fig. 4.6 TCPServer TCP server makes a connection for each client and then echoes the
clients request
7/25/2019 03 - 50 - 3 -
5/50
class Connection extends Thread {
DataInputStream in;DataOutputStream out;
Socket clientSocket;
public Connection (Socket aClientSocket) {
try {
clientSocket = aClientSocket;
in = new DataInputStream( clientSocket.getInputStream());
out =new DataOutputStream( clientSocket.getOutputStream());
this.start();
} catch(IOException e) {System.out.println("Connection:"+e.getMessage());}
}
public void run(){
try { // an echo server
String data = in.readUTF();out.writeUTF(data);
} catch(EOFException e) {System.out.println("EOF:"+e.getMessage());
} catch(IOException e) {System.out.println("IO:"+e.getMessage());}
} finally{ try {clientSocket.close();}catch (IOException e){/*close failed*/}}
}
}
Fig. 4.6 continued
7/25/2019 03 - 50 - 3 -
6/50
TCPServer
public class TCPServer {public static void main (String args[]) {
try{
int serverPort = 7896; // the server port
ServerSocket listenSocket = new ServerSocket(serverPort);
while(true) {
Socket clientSocket = listenSocket.accept();
Connection c = new Connection(clientSocket);}
} catch(IOException e) {System.out.println("Listensocket:"+e.getMessage());}
}
} 6
7/25/2019 03 - 50 - 3 -
7/50
TCPServer
public class TCPServer {public static void main (String args[]) {
try{
int serverPort = 7896; // the server port
ServerSocket listenSocket = new ServerSocket(serverPort);
while(true) {
Socket clientSocket = listenSocket.accept();
System.out.println("Connection request form client: " +clientSocket.getInetAddress() + " : " + clientSocket.getPort());
Connection c = new Connection(clientSocket);}
} catch(IOException e) {System.out.println("Listensocket:"+e.getMessage());}
}
} 7
7/25/2019 03 - 50 - 3 -
8/50
1 - Java Sockets) Knock KncokWhos there?
Knock KncokWhos there - Java sockets
To ( )
(). :
: Knock, knock!
: Who's there?
: (.. Atch)
: ; (.. Atch who?)
: (.. Bless you!)
8
7/25/2019 03 - 50 - 3 -
9/50
1..I - KKClient
() . , , Bye. .
, Client. Client
( {localhost, 5050})
9
7/25/2019 03 - 50 - 3 -
10/50
1..I - KKClient
10
7/25/2019 03 - 50 - 3 -
11/50
1..I - KKClient
11
7/25/2019 03 - 50 - 3 -
12/50
1..I - KKClient
12
7/25/2019 03 - 50 - 3 -
13/50
1..I - KKClient
13
7/25/2019 03 - 50 - 3 -
14/50
1..I - KKServer
14
7/25/2019 03 - 50 - 3 -
15/50
1..I - KKServer
15
listening
socket
socket /
Protocol
request/reply prtotocol
7/25/2019 03 - 50 - 3 -
16/50
1..I - KKProtocol
16
7/25/2019 03 - 50 - 3 -
17/50
1..I - KKProtocol
17
7/25/2019 03 - 50 - 3 -
18/50
1..I - KKProtocol
18
7/25/2019 03 - 50 - 3 -
19/50
1..IConcurrent Server
19
7/25/2019 03 - 50 - 3 -
20/50
1..IConcurrent Server
20
thread
7/25/2019 03 - 50 - 3 -
21/50
1..IConcurrent Server
21
2 Di ib d Obj d
7/25/2019 03 - 50 - 3 -
22/50
2 - Distributed Objects andRemote Invocation
Election :
vote: ,
(string) (integer).
result:
22
7/25/2019 03 - 50 - 3 -
23/50
2.
) input output;
5.3.1 Interfaces indistributed systems
23
7/25/2019 03 - 50 - 3 -
24/50
2.
Vote: : Input
: Input
result:
: Output
: Output
24
7/25/2019 03 - 50 - 3 -
25/50
2.
) Election Java RMI
Figure 5.16 .
25
7/25/2019 03 - 50 - 3 -
26/50
2.
:
class Result implements Serializable {
String candidateName;
int votes;
}
:
import java.rmi.*;
public interface Election extends Remote {
void vote(String candidateName, int voterID)throws RemoteException;
Result result() throws RemoteException;
};
26
7/25/2019 03 - 50 - 3 -
27/50
2.
) Election
. Election (Maybe invocation,At-Least-Once Invocation,At-Most-Once Invocation);
5.3.1 Design Issues forRPC, call semantics
27
7/25/2019 03 - 50 - 3 -
28/50
2.
H Maybe invocation At-Least-Once Invocation,
, ,
At-Most-Once Invocation,
Java RMIAt-Most-Once Invocation
28
7/25/2019 03 - 50 - 3 -
29/50
7/25/2019 03 - 50 - 3 -
30/50
2.
(voterID, candidateName)
() vote,
Hash Table
Java Hashtable
, ,
semaphores monitors
30
7/25/2019 03 - 50 - 3 -
31/50
2.
) Election .
)
31
7/25/2019 03 - 50 - 3 -
32/50
2.
server ( ) (),
.
32
7/25/2019 03 - 50 - 3 -
33/50
3 - (threads)
) threads, , ;
7.4.3 Threads , Threads versus multiple processes.
33
7/25/2019 03 - 50 - 3 -
34/50
3
thread switching thread
thread
, (.. thread-per-request )
threads
34
7/25/2019 03 - 50 - 3 -
35/50
3 - (threads)
) file server caching (hit ratio) 80%. server 5ms CPU time, caching, 15 ms / .
server ( /sec), :
i) server (single-threaded)
ii) o server -
iii) server
. 292-293 7.4.3 Threads .
35
7/25/2019 03 - 50 - 3 -
36/50
Average Request Processing Time (ARPT)
Average Throughput(AT)i) server (single-threaded)
ARPT = 0,8 * 5 + 0,2 * 20 = 8 ms
AT= 1000/8 = 125reqs/sec
ii) o server -
(cache hit):(cache miss) 4:1
/ :
25 ms 4 + 1
ARPT = 25/5 = 5 ms
AT = 1000/5 = 200 reqs/sec
Req1 Req1(I/O) Req1(I/O) Req1(I/O)
Req2 Req3 Req4 Req5
3
36
7/25/2019 03 - 50 - 3 -
37/50
3
iii) o server .
tiM thread request / tiH thread request cache
(1 cell = 5ms)
20ms 5 reqs. :
ARPT = 20/5 = 4 ms
AT = 1000/4 = 250 reqs/sec
37
CPU1 t1M I/O I/O I/O
CPU2 t2H t2H t2H t2H
7/25/2019 03 - 50 - 3 -
38/50
4 -
web-based . . :
(entry ticket) ( )
( )
38
7/25/2019 03 - 50 - 3 -
39/50
4 -
( , ,
, , ..), .
, (web service provider)
39
7/25/2019 03 - 50 - 3 -
40/50
4:
40
|
-
-/ -
-/- -
- -
- ( ), -
7/25/2019 03 - 50 - 3 -
41/50
4:
41
|
-
- -
-
- -
? 5: Pastry
7/25/2019 03 - 50 - 3 -
42/50
65a1fc
?
?
?
?
e232fc
5: Pastry (P2P)
, (overlay routing) Pastry, b=4 ( GUIDs) L=8 .
GUID: 65a1fc D: e232fc, : GUIDs 3
; ( ?)
;
( Figure 10.6 Distributed Systems)
7/25/2019 03 - 50 - 3 -
43/50
4: Pastry
65a1fc
?
?
??
e232fc
0 1 2 3 4 5 6 7 8 9 a b c d e f
7/25/2019 03 - 50 - 3 -
44/50
65a1fc
e13da3
d4213f
d462bad462bc
e232fc
n n n n n n n n n n n n n n n
60n
61n
62n
63n
64n
65 66n
67n
68n
69n
6an
6bn
6cn
6dn
6en
6fn
650
n
651
n
652
n
653
n
654
n
655
n
656
n
657
n
658
n
659
n
65a 65b
n
65c
n
65d
n
65e
n
65f
n65a0
n65a1 65a2
n65a3
n65a4
n65a5
n65a6
n65a7
n65a8
n65a9
n65aa
n65ab
n65ac
n65ad
n65ae
n65af
n
0 1 2 3 4 5 6 7 8 9 a b c d e f
7/25/2019 03 - 50 - 3 -
45/50
45
65a1fc
e13da3
e20ff4
d462bad462bc
e232fc
n n n n n n n n n n n n n n n
e0n
e1 e2n
e3n
e4n
e5n
e6n
e7n
e8n
e9n
ean
ebn
ecn
edn
een
efn
e10n
e11n
e12n
e13 e14n
e15n
e16n
e17n
e18n
e19n
e1an
e1bn
e1cn
e1dn
e1en
e1fn
e130n
e131n
e132n
e133n
e134n
e135n
e136n
e137n
e138n
e139n
e13an
e13bn
e13cn
e13d e13en
e13fn
0 1 2 3 4 5 6 7 8 9 a b c d e f
7/25/2019 03 - 50 - 3 -
46/50
46
65a1fc
e13da3
e20ff4
e23b3ad462bc
e232fc
n n n n n n n n n n n n n n n
e0n
e1n
e2 e3n
e4n
e5n
e6n
e7n
e8n
e9n
ean
ebn
ecn
edn
een
efn
e20 e21n
e22n
e23n
e24n
e25n
e26n
e27n
e28n
e29n
e2an
e2bn
e2cn
e2dn
e2en
e2fn
e200n
e201n
e202n
e203n
e204n
e205n
e206n
e207n
e208n
e209n
e20an
e20bn
e20cn
e20dn
e20en
e20f
O GUID e232fc
7/25/2019 03 - 50 - 3 -
47/50
O GUID e232fc e23b3a - (leaf nodes)
47
65a1fc
e13da3
e20ff4
e23b3ae232fc
e232fc
7/25/2019 03 - 50 - 3 -
48/50
, 4
log2bN (= log16 2128=
32) ( 128-bit GUIDs)
(circular routing), , L/2 = 4
(e232fc-65a1fc)/4 .
48
5: Pastry
7/25/2019 03 - 50 - 3 -
49/50
49
, ([1], [2], )
/ , ( )
( )
MS Word / (. Caption -Cross-Reference)
7/25/2019 03 - 50 - 3 -
50/50
:
:
[1]. GUIDE [2].
:[1] .Abowd, C. Atkeson, J. Hong, Cyberguide: A Mobile Context-Aware Tour
Guide, Wireless Networks, 3(5):421433, 1996.
[2] K. Cheverst, N. Davies, K. Mitchell, A. Friday, Experiences of Developing
and Deploying a Context-Aware Tourist Guide: The GUIDE Project,Proceedings of the 6th ACM/IEEE International Conference on MobileComputing and Networking (Mobicom2000): 2031, 2000.
Top Related