db4
Slava Pestov 2008-03-05 15:02:02 -06:00
parent e933cf97fe
commit fa898aa8c6
2 changed files with 59 additions and 66 deletions

View File

@ -1,65 +1,58 @@
USING: io.sockets io kernel math threads USING: io.sockets io kernel math threads
debugger tools.time prettyprint concurrency.count-downs debugger tools.time prettyprint concurrency.count-downs
namespaces arrays continuations ; namespaces arrays continuations ;
IN: benchmark.sockets IN: benchmark.sockets
SYMBOL: counter SYMBOL: counter
: number-of-requests 1 ; : number-of-requests 1 ;
: server-addr "127.0.0.1" 7777 <inet4> ; : server-addr "127.0.0.1" 7777 <inet4> ;
: server-loop ( server -- ) : server-loop ( server -- )
dup accept [ dup accept [
[ [
read1 CHAR: x = [ read1 CHAR: x = [
"server" get dispose "server" get dispose
] [ ] [
number-of-requests number-of-requests
[ read1 write1 flush ] times [ read1 write1 flush ] times
counter get count-down counter get count-down
] if ] if
] with-stream ] with-stream
] curry "Client handler" spawn drop server-loop ; ] curry "Client handler" spawn drop server-loop ;
: simple-server ( -- ) : simple-server ( -- )
[ [
server-addr <server> dup "server" set [ server-addr <server> dup "server" set [
server-loop server-loop
] with-disposal ] with-disposal
] ignore-errors ; ] ignore-errors ;
: simple-client ( -- ) : simple-client ( -- )
server-addr <client> [ server-addr <client> [
CHAR: b write1 flush CHAR: b write1 flush
number-of-requests number-of-requests
[ CHAR: a dup write1 flush read1 assert= ] times [ CHAR: a dup write1 flush read1 assert= ] times
counter get count-down counter get count-down
] with-stream ; ] with-stream ;
: stop-server ( -- ) : stop-server ( -- )
server-addr <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 [
dup 2 * <count-down> counter set dup 2 * <count-down> counter set
[ simple-server ] "Simple server" spawn drop [ simple-server ] "Simple server" spawn drop
yield yield yield yield
[ [ simple-client ] "Simple client" spawn drop ] times [ [ simple-client ] "Simple client" spawn drop ] times
counter get await counter get await
stop-server stop-server
yield yield yield yield
] time ; ] time ;
: socket-benchmarks : socket-benchmarks ;
10 clients
20 clients MAIN: socket-benchmarks
40 clients ;
! 80 clients
! 160 clients
! 320 clients
! 640 clients ;
MAIN: socket-benchmarks

View File

@ -8,7 +8,7 @@ SYMBOL: upload-images-destination
: destination ( -- dest ) : destination ( -- dest )
upload-images-destination get upload-images-destination get
"slava@/var/www/factorcode.org/newsite/images/latest/" "slava@factorcode.org:/var/www/factorcode.org/newsite/images/latest/"
or ; or ;
: checksums "checksums.txt" temp-file ; : checksums "checksums.txt" temp-file ;