Rename echo benchmark to udp-echo. Rename file-server benchmark to tcp-echo. Add more benchmarks for different loads.
parent
98979fc51c
commit
5836634922
|
@ -1,44 +0,0 @@
|
|||
! Copyright (C) 2011 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors byte-arrays io io.encodings.binary io.servers
|
||||
io.sockets kernel math memoize namespaces sequences fry literals ;
|
||||
IN: benchmark.file-server
|
||||
|
||||
! Tweak these parameters to test different loads
|
||||
CONSTANT: #times 4
|
||||
|
||||
! Max size here is 26 2^ 1 - because array-capacity limits on 32bit platforms
|
||||
CONSTANT: test-file-size $[ 26 2^ 1 - ]
|
||||
|
||||
MEMO: test-file-bytes ( -- byte-array )
|
||||
test-file-size iota >byte-array ;
|
||||
|
||||
TUPLE: file-server < threaded-server ;
|
||||
|
||||
: <file-server> ( -- obj )
|
||||
binary \ file-server new-threaded-server
|
||||
f 0 <inet4> >>insecure ;
|
||||
|
||||
M: file-server handle-client*
|
||||
drop
|
||||
#times [ test-file-bytes output-stream get stream-write ] times ;
|
||||
|
||||
ERROR: incorrect-#bytes ;
|
||||
|
||||
: server>address ( server -- port )
|
||||
servers>> first addr>> port>> local-server ;
|
||||
|
||||
: file-server-benchmark ( -- )
|
||||
<file-server> start-server [
|
||||
[ #times ] dip
|
||||
server>address binary <client> drop [
|
||||
'[
|
||||
test-file-size _ stream-read length test-file-size =
|
||||
[ incorrect-#bytes ] unless
|
||||
] times
|
||||
] [
|
||||
stream-contents length 0 = [ incorrect-#bytes ] unless
|
||||
] bi
|
||||
] [ stop-server ] bi ;
|
||||
|
||||
MAIN: file-server-benchmark
|
|
@ -0,0 +1,56 @@
|
|||
! Copyright (C) 2011 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors byte-arrays io io.encodings.binary io.servers
|
||||
io.sockets kernel math memoize namespaces sequences fry literals
|
||||
locals formatting ;
|
||||
IN: benchmark.tcp-echo0
|
||||
|
||||
! Max size here is 26 2^ 1 - because array-capacity limits on 32bit platforms
|
||||
CONSTANT: test-size0 $[ 26 2^ 1 - ]
|
||||
|
||||
MEMO: test-bytes ( n -- byte-array ) iota >byte-array ;
|
||||
|
||||
TUPLE: tcp-echo < threaded-server #times #bytes ;
|
||||
|
||||
: <tcp-echo> ( #times #bytes -- obj )
|
||||
binary \ tcp-echo new-threaded-server
|
||||
swap >>#bytes
|
||||
swap >>#times
|
||||
f 0 <inet4> >>insecure ;
|
||||
|
||||
ERROR: incorrect-#bytes ;
|
||||
|
||||
: check-bytes ( bytes n -- bytes )
|
||||
over length = [ incorrect-#bytes ] unless ;
|
||||
|
||||
: read-n ( n -- bytes )
|
||||
[ read ] [ check-bytes ] bi ;
|
||||
|
||||
: read-write ( n -- ) read-n write flush ;
|
||||
|
||||
: write-read ( bytes -- )
|
||||
[ write flush ] [ length read-n drop ] bi ;
|
||||
|
||||
M: tcp-echo handle-client*
|
||||
[ #times>> ] [ #bytes>> ] bi
|
||||
'[ _ [ _ test-bytes write-read ] times ] call ;
|
||||
|
||||
: server>address ( server -- port )
|
||||
servers>> first addr>> port>> local-server ;
|
||||
|
||||
: tcp-echo-banner ( #times #bytes -- )
|
||||
"Network testing: times: %d, length: %d\n" printf ;
|
||||
|
||||
:: tcp-echo-benchmark ( #times #bytes -- )
|
||||
#times #bytes [ tcp-echo-banner ] 2keep
|
||||
<tcp-echo> [
|
||||
\ threaded-server get server>address binary [
|
||||
#times [ #bytes read-write ] times
|
||||
contents length 0 = [ incorrect-#bytes ] unless
|
||||
] with-client
|
||||
] with-threaded-server ;
|
||||
|
||||
: tcp-echo-benchmark0 ( -- )
|
||||
4 test-size0 tcp-echo-benchmark ;
|
||||
|
||||
MAIN: tcp-echo-benchmark0
|
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1,9 @@
|
|||
! Copyright (C) 2011 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: benchmark.tcp-echo0 io ;
|
||||
IN: benchmark.tcp-echo1
|
||||
|
||||
: tcp-echo-benchmark1 ( -- )
|
||||
20,000 64 tcp-echo-benchmark ;
|
||||
|
||||
MAIN: tcp-echo-benchmark1
|
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1,9 @@
|
|||
! Copyright (C) 2011 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: benchmark.tcp-echo0 io ;
|
||||
IN: benchmark.tcp-echo2
|
||||
|
||||
: tcp-echo-benchmark2 ( -- )
|
||||
20,000,000 20 tcp-echo-benchmark ;
|
||||
|
||||
MAIN: tcp-echo-benchmark2
|
|
@ -1,20 +1,23 @@
|
|||
! Copyright (C) 2011 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
|
||||
USING: accessors destructors kernel io.binary io.sockets
|
||||
USING: accessors destructors fry io.binary io.sockets kernel
|
||||
sequences ;
|
||||
|
||||
IN: benchmark.echo
|
||||
IN: benchmark.udp-echo0
|
||||
|
||||
: send/recv ( packet server client -- )
|
||||
[ over over addr>> ] [ send ] bi* receive drop assert= ;
|
||||
|
||||
: udp-echo ( -- )
|
||||
[
|
||||
10000 iota [ 4 >be ] map
|
||||
: udp-echo ( #times #bytes -- )
|
||||
'[
|
||||
_ iota [ _ >be ] map
|
||||
"127.0.0.1" 0 <inet4> <datagram>
|
||||
"127.0.0.1" 0 <inet4> <datagram>
|
||||
[ send/recv ] 2curry each
|
||||
] with-destructors ;
|
||||
|
||||
MAIN: udp-echo
|
||||
|
||||
: udp-echo0 ( -- ) 50,000 1 udp-echo ;
|
||||
|
||||
MAIN: udp-echo0
|
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1,8 @@
|
|||
! Copyright (C) 2011 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: benchmark.udp-echo0 ;
|
||||
IN: benchmark.udp-echo1
|
||||
|
||||
: udp-echo1 ( -- ) 50,000 200 udp-echo ;
|
||||
|
||||
MAIN: udp-echo1
|
|
@ -0,0 +1 @@
|
|||
Doug Coleman
|
|
@ -0,0 +1,8 @@
|
|||
! Copyright (C) 2011 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: benchmark.udp-echo0 ;
|
||||
IN: benchmark.udp-echo2
|
||||
|
||||
: udp-echo2 ( -- ) 50,000 1450 udp-echo ;
|
||||
|
||||
MAIN: udp-echo2
|
Loading…
Reference in New Issue