From 7addfcd80e49b4fb4678dd1f18cf1d01fe1d4c43 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 15 Oct 2011 10:52:07 -0700 Subject: [PATCH] Rename echo benchmark to udp-echo. Rename file-server benchmark to tcp-echo. Add more benchmarks for different loads. --- .../benchmark/file-server/file-server.factor | 44 --------------- .../{file-server => tcp-echo0}/authors.txt | 0 extra/benchmark/tcp-echo0/tcp-echo0.factor | 56 +++++++++++++++++++ extra/benchmark/tcp-echo1/authors.txt | 1 + extra/benchmark/tcp-echo1/tcp-echo1.factor | 9 +++ extra/benchmark/tcp-echo2/authors.txt | 1 + extra/benchmark/tcp-echo2/tcp-echo2.factor | 9 +++ .../udp-echo0.factor} | 15 +++-- extra/benchmark/udp-echo1/authors.txt | 1 + extra/benchmark/udp-echo1/udp-echo1.factor | 8 +++ extra/benchmark/udp-echo2/authors.txt | 1 + extra/benchmark/udp-echo2/udp-echo2.factor | 8 +++ 12 files changed, 103 insertions(+), 50 deletions(-) delete mode 100644 extra/benchmark/file-server/file-server.factor rename extra/benchmark/{file-server => tcp-echo0}/authors.txt (100%) create mode 100644 extra/benchmark/tcp-echo0/tcp-echo0.factor create mode 100644 extra/benchmark/tcp-echo1/authors.txt create mode 100644 extra/benchmark/tcp-echo1/tcp-echo1.factor create mode 100644 extra/benchmark/tcp-echo2/authors.txt create mode 100644 extra/benchmark/tcp-echo2/tcp-echo2.factor rename extra/benchmark/{echo/echo.factor => udp-echo0/udp-echo0.factor} (62%) create mode 100644 extra/benchmark/udp-echo1/authors.txt create mode 100644 extra/benchmark/udp-echo1/udp-echo1.factor create mode 100644 extra/benchmark/udp-echo2/authors.txt create mode 100644 extra/benchmark/udp-echo2/udp-echo2.factor diff --git a/extra/benchmark/file-server/file-server.factor b/extra/benchmark/file-server/file-server.factor deleted file mode 100644 index 8dea55fa6e..0000000000 --- a/extra/benchmark/file-server/file-server.factor +++ /dev/null @@ -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 ; - -: ( -- obj ) - binary \ file-server new-threaded-server - f 0 >>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 ( -- ) - start-server [ - [ #times ] dip - server>address binary 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 diff --git a/extra/benchmark/file-server/authors.txt b/extra/benchmark/tcp-echo0/authors.txt similarity index 100% rename from extra/benchmark/file-server/authors.txt rename to extra/benchmark/tcp-echo0/authors.txt diff --git a/extra/benchmark/tcp-echo0/tcp-echo0.factor b/extra/benchmark/tcp-echo0/tcp-echo0.factor new file mode 100644 index 0000000000..8387a1ae3a --- /dev/null +++ b/extra/benchmark/tcp-echo0/tcp-echo0.factor @@ -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 ; + +: ( #times #bytes -- obj ) + binary \ tcp-echo new-threaded-server + swap >>#bytes + swap >>#times + f 0 >>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 + [ + \ 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 diff --git a/extra/benchmark/tcp-echo1/authors.txt b/extra/benchmark/tcp-echo1/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/benchmark/tcp-echo1/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/benchmark/tcp-echo1/tcp-echo1.factor b/extra/benchmark/tcp-echo1/tcp-echo1.factor new file mode 100644 index 0000000000..fd150cf10e --- /dev/null +++ b/extra/benchmark/tcp-echo1/tcp-echo1.factor @@ -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 diff --git a/extra/benchmark/tcp-echo2/authors.txt b/extra/benchmark/tcp-echo2/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/benchmark/tcp-echo2/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/benchmark/tcp-echo2/tcp-echo2.factor b/extra/benchmark/tcp-echo2/tcp-echo2.factor new file mode 100644 index 0000000000..af3aaef748 --- /dev/null +++ b/extra/benchmark/tcp-echo2/tcp-echo2.factor @@ -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 diff --git a/extra/benchmark/echo/echo.factor b/extra/benchmark/udp-echo0/udp-echo0.factor similarity index 62% rename from extra/benchmark/echo/echo.factor rename to extra/benchmark/udp-echo0/udp-echo0.factor index c5c0dab214..b4f5c8fc89 100644 --- a/extra/benchmark/echo/echo.factor +++ b/extra/benchmark/udp-echo0/udp-echo0.factor @@ -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 "127.0.0.1" 0 [ send/recv ] 2curry each ] with-destructors ; -MAIN: udp-echo + +: udp-echo0 ( -- ) 50,000 1 udp-echo ; + +MAIN: udp-echo0 diff --git a/extra/benchmark/udp-echo1/authors.txt b/extra/benchmark/udp-echo1/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/benchmark/udp-echo1/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/benchmark/udp-echo1/udp-echo1.factor b/extra/benchmark/udp-echo1/udp-echo1.factor new file mode 100644 index 0000000000..d385e7bc69 --- /dev/null +++ b/extra/benchmark/udp-echo1/udp-echo1.factor @@ -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 diff --git a/extra/benchmark/udp-echo2/authors.txt b/extra/benchmark/udp-echo2/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/benchmark/udp-echo2/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/benchmark/udp-echo2/udp-echo2.factor b/extra/benchmark/udp-echo2/udp-echo2.factor new file mode 100644 index 0000000000..563e492cdc --- /dev/null +++ b/extra/benchmark/udp-echo2/udp-echo2.factor @@ -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