Change socket benchmark

db4
Slava Pestov 2008-03-01 14:23:41 -06:00
parent d4f37e175f
commit 7b8a3a7bf5
2 changed files with 50 additions and 14 deletions

View File

@ -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

View File

@ -1,32 +1,54 @@
USING: io.sockets io.server io kernel math threads
debugger tools.time prettyprint concurrency.combinators ;
USING: io.sockets io kernel math threads
debugger tools.time prettyprint concurrency.count-downs
namespaces arrays continuations ;
IN: benchmark.sockets
: simple-server ( -- )
7777 local-server "benchmark.sockets" [
SYMBOL: counter
: number-of-requests 1 ;
: server-addr "127.0.0.1" 7777 <inet4> ;
: server-loop ( server -- )
dup accept [
[
read1 CHAR: x = [
stop-server
"server" get dispose
] [
20 [ read1 write1 flush ] times
number-of-requests
[ read1 write1 flush ] times
counter get count-down
] if
] with-server ;
] with-stream
] curry "Client handler" spawn drop server-loop ;
: simple-server ( -- )
[
server-addr <server> dup "server" set [
server-loop
] with-disposal
] ignore-errors ;
: simple-client ( -- )
"localhost" 7777 <inet> <client> [
server-addr <client> [
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 ;
: stop-server ( -- )
"localhost" 7777 <inet> <client> [
server-addr <client> [
CHAR: x write1
] with-stream ;
: clients ( n -- )
dup pprint " clients: " write [
[ simple-server ] in-thread
dup 2 * <count-down> counter set
[ simple-server ] "Simple server" spawn drop
yield yield
[ drop simple-client ] parallel-each
[ [ simple-client ] "Simple client" spawn drop ] times
counter get await
stop-server
yield yield
] time ;