Professional Documents
Culture Documents
03 - ΣΔΥ50 - ΟΣΣ3 - Ασκήσεις
03 - ΣΔΥ50 - ΟΣΣ3 - Ασκήσεις
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 B localhost
server
IP port number /
clients request
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
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();
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("Listen
socket:"+e.getMessage());}
}
}
1 - Java Sockets
) Knock Kncok Whos there?
Knock Kncok
Whos there
- Java sockets
To ( )
().
:
: Knock, knock!
: Who's there?
: (.. Atch)
:
1..I - KKClient
()
.
,
, Bye.
.
,
Client. Client
(
{localhost, 5050})
1..I - KKClient
10
1..I - KKClient
11
1..I - KKClient
12
1..I - KKClient
13
1..I - KKServer
14
1..I - KKServer
listening
socket
socket /
Protocol
request/reply prtotocol
15
1..I - KKProtocol
16
1..I - KKProtocol
17
1..I - KKProtocol
18
19
thread
20
21
Election
:
vote: ,
(string)
(integer).
result:
22
2.
)
input output;
5.3.1
Interfaces in
distributed systems
23
2.
Vote:
: Input
: Input
result:
: Output
: Output
24
2.
) Election Java RMI
Figure 5.16
.
25
2.
:
26
2.
) Election
.
Election (Maybe invocation, At-LeastOnce Invocation, At-Most-Once Invocation);
5.3.1 Design Issues for
RPC, call semantics
27
2.
H Maybe invocation
At-Least-Once Invocation,
,
,
At-Most-Once Invocation,
Java RMI
At-Most-Once Invocation
28
2.
)
Election
29
2.
(voterID, candidateName)
()
vote,
Hash Table
Java Hashtable
,
,
semaphores monitors
30
2.
) Election
.
)
31
2.
server (
)
(),
.
32
3 - (threads)
) threads,
,
;
7.4.3 Threads ,
Threads versus multiple processes.
33
thread switching
thread
thread
,
(.. thread-perrequest )
threads
34
3 - (threads)
) file server caching
(hit ratio) 80%.
server 5 ms CPU time, caching
, 15 ms
/ .
server ( /sec),
:
i) server (single-threaded)
ii) o server -
iii) server
3
Average Request Processing Time (ARPT)
Average Throughput (AT)
i) server (single-threaded)
ARPT = 0,8 * 5 + 0,2 * 20 = 8 ms
AT= 1000/8 = 125 reqs/sec
ii) o server
(cache hit):(cache miss) 4:1
/ :
Req1
Req1(I/O)
Req1(I/O)
Req1(I/O)
Req2
Req3
Req4
25 ms 4 + 1
ARPT = 25/5 = 5 ms
AT = 1000/5 = 200 reqs/sec
Req5
36
3
iii) o server
.
tiM thread request /
tiH thread request cache
(1 cell = 5ms)
CPU1
t1M
I/O
I/O
I/O
CPU2
t2H
t2H
t2H
t2H
20ms
5 reqs. :
ARPT = 20/5 = 4 ms
AT = 1000/4 = 250 reqs/sec
37
4 -
web-based
.
.
:
(entry ticket)
( )
(
)
38
4 -
(
,
,
,
, ..),
.
,
(web service provider)
39
4:
- /
-
-/
-
-
-
-
( ),
-
40
4:
-
-
-
-
-
41
5: Pastry
?
?
?
(P2P)
e232fc
65a1fc
,
(overlay routing)
Pastry, b=4 ( GUIDs) L=8
.
GUID: 65a1fc
D: e232fc, :
GUIDs 3
; ( ?)
;
(
Figure 10.6 Distributed Systems)
4: Pastry
?
?
e232fc
65a1fc
0
n
1
n
2
n
3
n
4
n
5
n
7
n
8
n
9
n
a
n
b
n
c
n
d
n
e
n
f
n
60
n
61
n
62
n
63
n
64
n
65
66
n
67
n
68
n
69
n
6a
n
6b
n
6c
n
6d
n
6e
n
6f
n
650
n
651
n
652 653 654 655 656 657 658 659 65a 65b 65c 65d 65e
n
n
n
n
n
n
n
n
n
n
n
n
65f
n
65a0
n
65a1
65a2
n
65af
n
65a3
n
65a4
n
65a5
n
65a6
n
65a7
n
65a8
n
65a9
n
65aa
n
65ab
n
65ac
n
65ad
n
65ae
n
d462bc
d462ba
d4213f
e232fc
65a1fc
e13da3
0
n
1
n
2
n
3
n
4
n
5
n
6
n
7
n
8
n
9
n
a
n
b
n
c
n
d
n
f
n
e0
n
e1
e2
n
e3
n
e4
n
e5
n
e6
n
e7
n
e8
n
e9
n
ea
n
eb
n
ec
n
ed
n
ee
n
ef
n
e10
n
e11
n
e12
n
e13
e14
n
e15
n
e16
n
e17
n
e18
n
e19
n
e1a
n
e1b
n
e1c
n
e1d
n
e1e
n
e1f
n
e130
n
e131
n
e132
n
e133
n
e134
n
e135
n
e136 e137
n
n
e13f
n
e138 e139
n
n
d462bc
d462ba
e20ff4
e232fc
e13da3
65a1fc
45
0
n
1
n
2
n
3
n
4
n
5
n
6
n
7
n
8
n
9
n
a
n
b
n
c
n
d
n
f
n
e0
n
e1
n
e2
e3
n
e4
n
e5
n
e6
n
e7
n
e8
n
e9
n
ea
n
eb
n
ec
n
ed
n
ee
n
ef
n
e20
e21
n
e22
n
e23 e24 e25 e26 e27 e28 e29 e2a e2b e2c e2d e2e
n
n
n
n
n
n
n
n
n
n
n
n
e2f
n
e200
e201
n
e20
2
n
e203
n
e204
e20
5
n
e206
e207
e208
e209
n
e20a
e20b
e20c e20d
n
n
e20
e
n
e20f
d462bc
e23b3a
e20ff4
e232fc
e13da3
65a1fc
46
O GUID e232fc
e23b3a -
(leaf nodes)
e232fc
e23b3a
e20ff4
e232fc
e13da3
65a1fc
47
5: Pastry
,
4
log2b N (= log16 2128 =
32) ( 128-bit GUIDs)
(circular routing),
,
L/2 = 4
(e232fc-65a1fc)/4
.
48
,
([1], [2], )
/ ,
( )
(
)
MS Word
/ (. Caption Cross-Reference)
49
:
:
[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 Mobile
Computing and Networking (Mobicom2000): 2031, 2000.
50