-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
356 lines (222 loc) · 10.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<title>
NIOMON - NIO Network Monitor Tool
</title>
<head>
<style type="text/css">
table {
vertical-align: top ;
caption-side : right ;
}
div:first-letter { font-size:large }
a.x:visited {color: #0000ff}
a.x:hover { background: #66ff66 ; font-size: 105% }
BODY {
font-family: Verdana, Arial;
font-size:smaller;
}
pre.code {
font-family: cg-times, courier new, courier;
font-size:100% ;
color:yellow ;
border: 1px solid yellow;
background-color:black;
}
pre.y {
font-size:100% ;
font-family:cg-times ;
border-style: solid ;
border-width: 1px 1px 1px 1px ;
border-color: red ;
}
pre.z {
font-family: cg-times, courier new, courier;
font-size:75% ;
border: 1px solid black;
background-color: #d0d0d0;
}
pre.zold {
font-size:75% ;
font-family:cg-times ;
background-color:black ;
color:black ;
border-style: solid ;
border-width: 1px 1px 1px 1px ;
border-color: red ;
}
</style>
<CENTER><H2>NIOMON - NIO Network Monitor Tool</H2></CENTER>
</head>
<body>
<P>
</div>
<h2>Introduction</h2>
<P>
NIOMON is a simple NIO network monitoring tool. (670 words; April, 2002)
<uL>
<LI>Introduction
<LI>NIO Use Case
<LI>Network monitoring
<LI>References and ReferenceQueues
<LI>Application Design
<LI>NIOServer Walk Through
<LI>How to Download, Install, and Test
<LI>Java Documentation
</uL>
By <FONT size=""><a href="#Author">Clayton Press</a></FONT>
<h2>Introduction</h2>
<P>
Java 1.4 introduced a new API for high performance, nonblocking I/O and networking.
The API consists of three development packages: java.nio, java.nio.channels, java.nio.charset,
and two Service-provider packages: java.nio.channels.spi, java.nio.charset.spi.
<P>
Multiplexed nonblocking IO is also useful for client applications that maintain multiple network connections in a
non-blocking manner - for example a web browser.
<P>
Developing client and server network applications is complex.
There are a range of issues to consider: multi-threading, sockets, configuration, tuning.
As the demand for high peformance low latency network application increases, so does the need for
developer tools with which to test & monitor such applications, during development and in production.
<P>
The NIOMON network application monitor is a simple tool which which to monitor NIO-based java applications.
Thus far, it monitors on the run:
<ul>
<li> number of connections
<li> connection speed, throughput, latency
<li> thread stack frames, snap-shot and time-series
<li> cache memory eviction rate
</ul>
<h2>NIO Use Case</B></h2>
<P>
Previously, standard IO server applications required a dedicated thread for each connection.
A multi-threaded socket server, serving hundreds of connections, must maintain hundreds of threads.
NIO introduces channels and selectors which allow multiplexed, non-blocking I/O operations.
The Channel Selector semantics enable a dramatic reduction in multi-threaded resources and complexity.
<P>
Let’s take a look at a simple NIO test application.
<P>
<P>
<h2>NIOMON Network monitor tool</h2>
<P>
The NIOMON Network monitor connects multiple NIOClient to one NIOServer .
The NIOClient sends a message to the NIOServer over a socket. The NIOServer responds back.
This continues according to a TTL "count" parameter.
The "count" parameter is configured on the NIOClient.
<P>
The application is composed of one server and multiple client components.
The client sends a message to the server.
The client displays the response back from the server.
The server component manages remote communication with multiple connected clients.
The server sends the message back to the respective client.
<P>
NIOMON consists of 2 standalone java applications, NIOClient and NIOServer, which communicate over TCP network sockets.
NIOServer is capable of handling multiple NIOClients
<P>
The server application
<ul>
<li> 1a. Listens for TCP connections on a well known IP address and port
<li> 1b. Accepts connections initiated on that port from multiple clients
<li> 1c. Receives messages from multiple clients and echoes them back
<li> 1d. Tracks when each client drops a connection
<li> 1e. Maintains a thread dump time series WeakReference Memory Cache
</ul>
The client application
<ul>
<li> 2a. Establishs a connection with the server at it's well known IP address and port
<li> 2b. Sends messages in an asynchronous manner to the server. The message is a Date String.
<li> 2c. The server adds a response tag to the message so that the client knows how many "round trips" to the server have occurred.
<li> 2d. Reports the round trip time for each message, the running average round trip time for all messages
<li> 2e. Reports the running throughput rate for all messages.
</ul>
Both client and server application automated testing
<ul>
<li> 3a. ant tasks for testing multiple clients and server - short burst or long duration connections
<li> 3b. ant tasks for testing Reference memory cache eviction rate
</ul>
<h2>References and ReferenceQueues</h2>
Reference and ReferenceQueue types merit special comment.
<P>
In a high frequency environment, close attention to memory management is required, hence Reference types.
The java.lang.ref Package description says it best:
<P>
A <b>Reference</b> object encapsulates a reference to some other object so that the reference itself may be examined and manipulated like any other object. Three types of reference objects are provided, each weaker than the last: soft, weak, and phantom. Each type corresponds to a different level of reachability, as defined below. <b>Soft references</b> are for implementing memory-sensitive caches, <b>weak references</b> are for implementing canonicalizing mappings that do not prevent their keys (or values) from being reclaimed, and <b>phantom references</b> are for scheduling pre-mortem cleanup actions in a more flexible way than is possible with the Java finalization mechanism.
<P>
Each reference-object type is implemented by a subclass of the abstract base Reference class. An instance of one of these subclasses encapsulates a single reference to a particular object, called the referent. Every reference object provides methods for getting and clearing the reference. Aside from the clearing operation reference objects are otherwise immutable, so no set operation is provided. A program may further subclass these subclasses, adding whatever fields and methods are required for its purposes, or it may use these subclasses without change.
<P>
<b>Notification</b>
A program may request to be notified of changes in an object's reachability by registering an appropriate reference object with a reference queue at the time the reference object is created. Some time after the garbage collector determines that the reachability of the referent has changed to the value corresponding to the type of the reference, it will add the reference to the associated queue. At this point, the reference is considered to be enqueued. The program may remove references from a queue either by polling or by blocking until a reference becomes available. Reference queues are implemented by the ReferenceQueue class.
<P>
<h2>Application Design</h2>
<P>
<h2>NIOServer Walk Through</h2>
<P>
A condensed version of the Server class logic, is listed below. Exception handling and other support logic has been excluded for clarity.
Refer to the source code for more details.
BASIC INFO
<pre class="y">
public class NIOServer {
// try - catch blocks omitted for brevity
1 ServerSocketChannel ssc = ServerSocketChannel.open();
2 ssc.socket().bind(new InetSocketAddress( port ));
3 ssc.configureBlocking(false);
4 SelectionKey serverkey = ssc.register(selector, SelectionKey.OP_ACCEPT);
5 selector.select(); //block until a channel is ready for I/O
6 SocketChannel client = ssc.accept();
7 client.configureBlocking(false);
8 SelectionKey clientkey = client.register(selector, SelectionKey.OP_READ);
9 bytesread = client.read(buffer);
10 buffer.flip();
11 String request = decoder.decode(buffer).toString();
12 buffer.clear();
}
</pre>
<h3>Program Notes</h3>
<UL type="circle">
<LI>Line 1 creates a ServerSocketChannel
<br>
<LI>Line 2 bind to a Socket
<br>
<LI>Line 3 configure non-blocking
<br>
<LI>Line 5 block until one multiplexed channel is ready for IO
<br>
<LI>Line 6 accept client SocketChannel
<br>
<LI>Line 9 read client SocketChannel into special purpose Container Byte Buffer
<br>
<LI>Line 10 switch R/W IO Byte Buffer Container direction
</UL>
<P>
<h2>How to Download, Install and Run</h2>
<P>
Complete source code is available for research and development purposes.
The following link provides step-by-step technical information to guide you through the Download and Installation process.
<p>
<A HREF="http://ece.uic.edu/~cpress/niomon/niomonTechSupport.htm" target="ImageWindow">N I O M O N T e c h n i c a l S u p p o r t</A>
<P>
<h2>Java Documentation</h2>
<P>
<A HREF="http://ece.uic.edu/~cpress/niomon/jdoc/" target="ImageWindow">J a v a D o c</A>
</UL>
<P>
<h2>Conclusion</h2>
<P>
Java NIO provides for high performance, non-blocking, multiplexed I/O network server development.
<P>
<h2>About the Author</h2><a name="Author">
<P>
Clayton Press has worked in Chicago as a systems developer since 1982.
He has built trade systems for the CME, CBOT, UBS, Bank of America, Bank of Montreal, Lehman Brothers and T.Rowe Price.
He can be reached at <A href="mailto:[email protected]">[email protected]</A>
<P>
<h2>References</h2>
<UL>
<LI> <A href="http://java.sun.com/j2se/1.4.2/docs/guide/nio/">NIO Home</A>, Sun
<LI> <A href="http://java.sun.com/javase/6/docs/api/">Java 6 API</A>, Sun
<LI> <A href="http://www.oreilly.com/catalog/javaio2">Java I/O, by Rusty Harold</A>, O'Reilly
<LI> <A href="http://www.oreilly.com/catalog/javanp3">Java Network Programming, by Rusty Harold</A>, O'Reilly
<LI> <A href="http://www.oreilly.com/catalog/javanio/">Java NIO, Ron Hitchens</A>, O'Reilly
</UL>
</body>
</html>