Multi-backend echo testing; erlang server

This commit is contained in:
Tony Garnock-Jones 2014-05-04 17:06:45 -04:00
parent ac44a27691
commit 889323c061
5 changed files with 83 additions and 15 deletions

View File

@ -6,15 +6,22 @@
(require logbook)
(define server-entry-name (standard-logbook-entry-name))
(define server-entry-type #f)
(command-line #:program "echo-client.rkt"
#:once-each
["--logbook-entry-name" name
"set logbook entry name to use when recording run statistics"
(set! server-entry-name name)])
(set! server-entry-name name)]
["--logbook-entry-type" type
"set logbook entry type to use"
(set! server-entry-type type)])
(when (not server-entry-type)
(error 'echo-client "Please supply the --logbook-entry-type command-line argument."))
(define L (default-logbook))
(define E (logbook-entry L "minimart" server-entry-name "external-latency"))
(define E (logbook-entry L "minimart" server-entry-name server-entry-type))
(when (not (logbook-machine-info-recorded? E))
(logbook-record-machine-info! E))
(define Tgrowth (logbook-table E "client-grow-times" #:column-spec '(initial-count

View File

@ -9,12 +9,19 @@
(require racket/cmdline)
(define server-entry-name #f)
(define server-entry-type #f)
(command-line #:program "echo-server.rkt"
#:once-each
["--logbook-entry-name" name
"set logbook entry name to use when recording run statistics"
(set! server-entry-name name)])
(set! server-entry-name name)]
["--logbook-entry-type" type
"set logbook entry type to use"
(set! server-entry-type type)])
(when (not server-entry-type)
(error 'echo-server "Please supply the --logbook-entry-type command-line argument."))
(define L (default-logbook))
(define E (logbook-entry L "minimart" server-entry-name "external-latency"))

View File

@ -3,22 +3,41 @@
-export([start/0]).
start() ->
{ok, LSock} = gen_tcp:listen(5999, [{active, true}, {packet, line}, {reuseaddr, true}]),
accept_loop(LSock).
Port = 5999,
CounterPid = spawn(fun () -> counter(0) end),
{ok, LSock} = gen_tcp:listen(Port, [{active, true}, {packet, line}, {reuseaddr, true}]),
io:format("Erlang echo server running on port ~p.~n", [Port]),
accept_loop(LSock, CounterPid).
accept_loop(LSock) ->
case gen_tcp:accept(LSock) of
{ok, Sock} ->
gen_tcp:controlling_process(Sock, spawn(fun () -> connection(Sock) end)),
accept_loop(LSock)
counter(Count) ->
receive
inc ->
counter(Count + 1);
dec ->
case Count - 1 of
0 ->
io:format("Exiting on zero connection count.~n"),
init:stop();
NewCount ->
counter(NewCount)
end
end.
connection(Sock) ->
accept_loop(LSock, CounterPid) ->
case gen_tcp:accept(LSock) of
{ok, Sock} ->
CounterPid ! inc,
gen_tcp:controlling_process(Sock, spawn(fun () -> connection(Sock, CounterPid) end)),
accept_loop(LSock, CounterPid)
end.
connection(Sock, CounterPid) ->
receive
{tcp, _, Line} ->
gen_tcp:send(Sock, Line),
connection(Sock);
connection(Sock, CounterPid);
{tcp_closed, _} ->
CounterPid ! dec,
ok;
Other ->
error_logger:error_report({connection, unhandled, Other})

View File

@ -2,11 +2,27 @@
(require racket/match)
(require racket/system)
(require racket/string)
(require racket/port)
(require racket/cmdline)
(require logbook)
(define server-variation #f)
(command-line #:program "external-latency.rkt"
#:once-any
["--erlang" "use erlang server" (set! server-variation 'erlang)]
["--minimart" "use minimart server" (set! server-variation 'minimart)])
(when (not server-variation)
(error 'external-latency "Please choose a server variation."))
(define entry-type (format "external-latency-~a" server-variation))
(define L (default-logbook))
(define E (standard-logbook-entry L "minimart" "external-latency"))
(define E (standard-logbook-entry L "minimart" entry-type))
(define entry-name (logbook-entry-name E))
(define Tmachine (logbook-table E "machine-info" "machine-info"))
(define (start-bg command)
(match-define (list #f #f pid #f control)
@ -18,13 +34,29 @@
(log-info "Starting server...")
(define server-control
(start-bg (format "racket echo-server.rkt --logbook-entry-name ~a" entry-name)))
(start-bg
(match server-variation
['minimart
(format "racket echo-server.rkt --logbook-entry-name ~a --logbook-entry-type ~a"
entry-name
entry-type)]
['erlang
(define erlang-version-command
"erl -noshell -eval 'io:format(erlang:system_info(otp_release)), halt().'")
(write-logbook-datum! Tmachine
#:label "erlang-version"
(string-trim (with-output-to-string
(lambda () (system erlang-version-command)))))
"./run-erlang-server.sh"])))
(sleep 5)
(log-info "Starting client...")
(define client-control
(start-bg (format "racket echo-client.rkt --logbook-entry-name ~a" entry-name)))
(start-bg
(format "racket echo-client.rkt --logbook-entry-name ~a --logbook-entry-type ~a"
entry-name
entry-type)))
(log-info "Waiting for client termination...")
(client-control 'wait)

3
run-erlang-server.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
erlc echoserver.erl
erl -noshell -run echoserver start