blob: 3529061697ae4f2052177ed21ecaf79908dacbfb (
plain)
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
|
= async
This is a simple asynchronous demo, that demonstrates use of the RAW
option with a server, along with async message handling, to obtain a
very high level of asynchronous operation, suitable for use in a highly
concurrent server application.
== Compiling
You can override the level of concurrency with the `PARALLEL`
define. This determines how many requests the server will accept
at a time, and keep outstanding. Note that for our toy
implementation, we create this many "logical" flows of execution
(these are _NOT_ threads), where a request is followed by a reply.
The value of `PARALLEL` must be at least one, and may be as large
as your memory will permit. (The default value is 32.)
On UNIX-style systems:
[source, bash]
----
% export CPPFLAGS="-D PARALLEL=32 -I /usr/local/include"
% export LDFLAGS="-L /usr/local/lib -lnng"
% export CC="cc"
% ${CC} ${CPPFLAGS} async.c -o async ${LDFLAGS}
----
== Running
To run the server, use the arguments `__url__ -s`.
To run the client, use the arguments `__url__ __msec__`.
The _msec_ is a "delay" time that server will wait before responding.
We have these delays so simulate long running work.
In the following example, all of the clients should complete within
2 seconds. (Assuming `PARALLEL` is defined to be large enough.)
[source,bash]
----
% export URL="tcp://127.0.0.1:55995"
# start the server
% ./async $URL -s &
# start a bunch of clients
# Note that these all run concurrently!
% ./async $URL 2 &
% ./async $URL 2 &
% ./async $URL 2 &
% ./async $URL 2 &
% ./async $URL 2 &
----
|