Change socket benchmark
parent
d4f37e175f
commit
7b8a3a7bf5
|
@ -0,0 +1,14 @@
|
||||||
|
IN: benchmark.fib6
|
||||||
|
USING: math kernel alien ;
|
||||||
|
|
||||||
|
: fib
|
||||||
|
"int" { "int" } "cdecl" [
|
||||||
|
dup 1 <= [ drop 1 ] [
|
||||||
|
1- dup fib swap 1- fib +
|
||||||
|
] if
|
||||||
|
] alien-callback
|
||||||
|
"int" { "int" } "cdecl" alien-indirect ;
|
||||||
|
|
||||||
|
: fib-main 25 fib drop ;
|
||||||
|
|
||||||
|
MAIN: fib-main
|
|
@ -1,32 +1,54 @@
|
||||||
USING: io.sockets io.server io kernel math threads
|
USING: io.sockets io kernel math threads
|
||||||
debugger tools.time prettyprint concurrency.combinators ;
|
debugger tools.time prettyprint concurrency.count-downs
|
||||||
|
namespaces arrays continuations ;
|
||||||
IN: benchmark.sockets
|
IN: benchmark.sockets
|
||||||
|
|
||||||
|
SYMBOL: counter
|
||||||
|
|
||||||
|
: number-of-requests 1 ;
|
||||||
|
|
||||||
|
: server-addr "127.0.0.1" 7777 <inet4> ;
|
||||||
|
|
||||||
|
: server-loop ( server -- )
|
||||||
|
dup accept [
|
||||||
|
[
|
||||||
|
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 ( -- )
|
: simple-server ( -- )
|
||||||
7777 local-server "benchmark.sockets" [
|
[
|
||||||
read1 CHAR: x = [
|
server-addr <server> dup "server" set [
|
||||||
stop-server
|
server-loop
|
||||||
] [
|
] with-disposal
|
||||||
20 [ read1 write1 flush ] times
|
] ignore-errors ;
|
||||||
] if
|
|
||||||
] with-server ;
|
|
||||||
|
|
||||||
: simple-client ( -- )
|
: simple-client ( -- )
|
||||||
"localhost" 7777 <inet> <client> [
|
server-addr <client> [
|
||||||
CHAR: b write1 flush
|
CHAR: b write1 flush
|
||||||
20 [ CHAR: a dup write1 flush read1 assert= ] times
|
number-of-requests
|
||||||
|
[ CHAR: a dup write1 flush read1 assert= ] times
|
||||||
|
counter get count-down
|
||||||
] with-stream ;
|
] with-stream ;
|
||||||
|
|
||||||
: stop-server ( -- )
|
: stop-server ( -- )
|
||||||
"localhost" 7777 <inet> <client> [
|
server-addr <client> [
|
||||||
CHAR: x write1
|
CHAR: x write1
|
||||||
] with-stream ;
|
] with-stream ;
|
||||||
|
|
||||||
: clients ( n -- )
|
: clients ( n -- )
|
||||||
dup pprint " clients: " write [
|
dup pprint " clients: " write [
|
||||||
[ simple-server ] in-thread
|
dup 2 * <count-down> counter set
|
||||||
|
[ simple-server ] "Simple server" spawn drop
|
||||||
yield yield
|
yield yield
|
||||||
[ drop simple-client ] parallel-each
|
[ [ simple-client ] "Simple client" spawn drop ] times
|
||||||
|
counter get await
|
||||||
stop-server
|
stop-server
|
||||||
yield yield
|
yield yield
|
||||||
] time ;
|
] time ;
|
||||||
|
|
Loading…
Reference in New Issue