Multi-backend echo testing; erlang server
This commit is contained in:
parent
ac44a27691
commit
889323c061
|
@ -6,15 +6,22 @@
|
||||||
(require logbook)
|
(require logbook)
|
||||||
|
|
||||||
(define server-entry-name (standard-logbook-entry-name))
|
(define server-entry-name (standard-logbook-entry-name))
|
||||||
|
(define server-entry-type #f)
|
||||||
|
|
||||||
(command-line #:program "echo-client.rkt"
|
(command-line #:program "echo-client.rkt"
|
||||||
#:once-each
|
#:once-each
|
||||||
["--logbook-entry-name" name
|
["--logbook-entry-name" name
|
||||||
"set logbook entry name to use when recording run statistics"
|
"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 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))
|
(when (not (logbook-machine-info-recorded? E))
|
||||||
(logbook-record-machine-info! E))
|
(logbook-record-machine-info! E))
|
||||||
(define Tgrowth (logbook-table E "client-grow-times" #:column-spec '(initial-count
|
(define Tgrowth (logbook-table E "client-grow-times" #:column-spec '(initial-count
|
||||||
|
|
|
@ -9,12 +9,19 @@
|
||||||
(require racket/cmdline)
|
(require racket/cmdline)
|
||||||
|
|
||||||
(define server-entry-name #f)
|
(define server-entry-name #f)
|
||||||
|
(define server-entry-type #f)
|
||||||
|
|
||||||
(command-line #:program "echo-server.rkt"
|
(command-line #:program "echo-server.rkt"
|
||||||
#:once-each
|
#:once-each
|
||||||
["--logbook-entry-name" name
|
["--logbook-entry-name" name
|
||||||
"set logbook entry name to use when recording run statistics"
|
"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 L (default-logbook))
|
||||||
(define E (logbook-entry L "minimart" server-entry-name "external-latency"))
|
(define E (logbook-entry L "minimart" server-entry-name "external-latency"))
|
||||||
|
|
|
@ -3,22 +3,41 @@
|
||||||
-export([start/0]).
|
-export([start/0]).
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
{ok, LSock} = gen_tcp:listen(5999, [{active, true}, {packet, line}, {reuseaddr, true}]),
|
Port = 5999,
|
||||||
accept_loop(LSock).
|
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) ->
|
counter(Count) ->
|
||||||
case gen_tcp:accept(LSock) of
|
receive
|
||||||
{ok, Sock} ->
|
inc ->
|
||||||
gen_tcp:controlling_process(Sock, spawn(fun () -> connection(Sock) end)),
|
counter(Count + 1);
|
||||||
accept_loop(LSock)
|
dec ->
|
||||||
|
case Count - 1 of
|
||||||
|
0 ->
|
||||||
|
io:format("Exiting on zero connection count.~n"),
|
||||||
|
init:stop();
|
||||||
|
NewCount ->
|
||||||
|
counter(NewCount)
|
||||||
|
end
|
||||||
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
|
receive
|
||||||
{tcp, _, Line} ->
|
{tcp, _, Line} ->
|
||||||
gen_tcp:send(Sock, Line),
|
gen_tcp:send(Sock, Line),
|
||||||
connection(Sock);
|
connection(Sock, CounterPid);
|
||||||
{tcp_closed, _} ->
|
{tcp_closed, _} ->
|
||||||
|
CounterPid ! dec,
|
||||||
ok;
|
ok;
|
||||||
Other ->
|
Other ->
|
||||||
error_logger:error_report({connection, unhandled, Other})
|
error_logger:error_report({connection, unhandled, Other})
|
||||||
|
|
|
@ -2,11 +2,27 @@
|
||||||
|
|
||||||
(require racket/match)
|
(require racket/match)
|
||||||
(require racket/system)
|
(require racket/system)
|
||||||
|
(require racket/string)
|
||||||
|
(require racket/port)
|
||||||
|
(require racket/cmdline)
|
||||||
(require logbook)
|
(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 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 entry-name (logbook-entry-name E))
|
||||||
|
(define Tmachine (logbook-table E "machine-info" "machine-info"))
|
||||||
|
|
||||||
(define (start-bg command)
|
(define (start-bg command)
|
||||||
(match-define (list #f #f pid #f control)
|
(match-define (list #f #f pid #f control)
|
||||||
|
@ -18,13 +34,29 @@
|
||||||
|
|
||||||
(log-info "Starting server...")
|
(log-info "Starting server...")
|
||||||
(define server-control
|
(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)
|
(sleep 5)
|
||||||
|
|
||||||
(log-info "Starting client...")
|
(log-info "Starting client...")
|
||||||
(define client-control
|
(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...")
|
(log-info "Waiting for client termination...")
|
||||||
(client-control 'wait)
|
(client-control 'wait)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
erlc echoserver.erl
|
||||||
|
erl -noshell -run echoserver start
|
Loading…
Reference in New Issue