2008-03-05 18:49:02 -05:00
|
|
|
USING: io.sockets io kernel math threads io.encodings.ascii
|
2008-05-05 05:32:01 -04:00
|
|
|
io.streams.duplex debugger tools.time prettyprint
|
2008-05-15 00:23:12 -04:00
|
|
|
concurrency.count-downs namespaces arrays continuations
|
|
|
|
destructors ;
|
2008-03-05 16:02:02 -05:00
|
|
|
IN: benchmark.sockets
|
|
|
|
|
|
|
|
SYMBOL: counter
|
|
|
|
|
|
|
|
: number-of-requests 1 ;
|
|
|
|
|
2008-06-09 03:14:14 -04:00
|
|
|
: server-addr ( -- addr ) "127.0.0.1" 7777 <inet4> ;
|
2008-03-05 16:02:02 -05:00
|
|
|
|
|
|
|
: server-loop ( server -- )
|
2008-05-07 06:14:25 -04:00
|
|
|
dup accept drop [
|
2008-03-05 16:02:02 -05:00
|
|
|
[
|
|
|
|
read1 CHAR: x = [
|
|
|
|
"server" get dispose
|
|
|
|
] [
|
|
|
|
number-of-requests
|
|
|
|
[ read1 write1 flush ] times
|
|
|
|
counter get count-down
|
|
|
|
] if
|
|
|
|
] with-stream
|
|
|
|
] curry "Client handler" spawn drop server-loop ;
|
|
|
|
|
|
|
|
: simple-server ( -- )
|
|
|
|
[
|
2008-03-05 17:57:06 -05:00
|
|
|
server-addr ascii <server> dup "server" set [
|
2008-03-05 16:02:02 -05:00
|
|
|
server-loop
|
|
|
|
] with-disposal
|
|
|
|
] ignore-errors ;
|
|
|
|
|
|
|
|
: simple-client ( -- )
|
2008-05-05 03:19:25 -04:00
|
|
|
server-addr ascii [
|
2008-03-05 16:02:02 -05:00
|
|
|
CHAR: b write1 flush
|
|
|
|
number-of-requests
|
|
|
|
[ CHAR: a dup write1 flush read1 assert= ] times
|
|
|
|
counter get count-down
|
2008-05-05 03:19:25 -04:00
|
|
|
] with-client ;
|
2008-03-05 16:02:02 -05:00
|
|
|
|
|
|
|
: stop-server ( -- )
|
2008-05-05 03:19:25 -04:00
|
|
|
server-addr ascii [
|
2008-03-05 16:02:02 -05:00
|
|
|
CHAR: x write1
|
2008-05-05 03:19:25 -04:00
|
|
|
] with-client ;
|
2008-03-05 16:02:02 -05:00
|
|
|
|
|
|
|
: clients ( n -- )
|
|
|
|
dup pprint " clients: " write [
|
|
|
|
dup 2 * <count-down> counter set
|
|
|
|
[ simple-server ] "Simple server" spawn drop
|
|
|
|
yield yield
|
|
|
|
[ [ simple-client ] "Simple client" spawn drop ] times
|
|
|
|
counter get await
|
|
|
|
stop-server
|
|
|
|
yield yield
|
|
|
|
] time ;
|
|
|
|
|
|
|
|
: socket-benchmarks ;
|
|
|
|
|
|
|
|
MAIN: socket-benchmarks
|