Repository: qpid-proton Updated Branches: refs/heads/master 4a9f3b986 -> 994db75c9
NO-JIRA: [go] example receiver grants credit like other examples Default to N credits where N is expected message count. -prefetch option specifies a credit window instead Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/7856d2dc Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/7856d2dc Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/7856d2dc Branch: refs/heads/master Commit: 7856d2dc99ea50c2b07078c3544e68ca454023a3 Parents: 4a9f3b9 Author: Alan Conway <acon...@redhat.com> Authored: Mon Oct 15 10:22:54 2018 -0400 Committer: Alan Conway <acon...@redhat.com> Committed: Mon Oct 15 10:22:54 2018 -0400 ---------------------------------------------------------------------- go/examples/electron/receive.go | 15 +++++---- tests/example-benchmark.sh | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7856d2dc/go/examples/electron/receive.go ---------------------------------------------------------------------- diff --git a/go/examples/electron/receive.go b/go/examples/electron/receive.go index 9cab2eb..774e589 100644 --- a/go/examples/electron/receive.go +++ b/go/examples/electron/receive.go @@ -24,10 +24,11 @@ import ( "fmt" "log" "os" - "qpid.apache.org/amqp" - "qpid.apache.org/electron" "strings" "sync" + + "qpid.apache.org/amqp" + "qpid.apache.org/electron" ) // Usage and command-line flags @@ -39,8 +40,8 @@ URLs are of the form "amqp://<host>:<port>/<amqp-address>" flag.PrintDefaults() } -var count = flag.Uint64("count", 1, "Stop after receiving this many messages in total") -var prefetch = flag.Int("prefetch", 0, "enable a pre-fetch window to improve throughput") +var count = flag.Int("count", 1, "Stop after receiving this many messages in total") +var prefetch = flag.Int("prefetch", 0, "enable a pre-fetch window for flow control") var debug = flag.Bool("debug", false, "Print detailed debug output") var debugf = func(format string, data ...interface{}) {} // Default no debugging output @@ -80,8 +81,10 @@ func main() { connections <- c // Save connection so we can Close() when main() ends addr := strings.TrimPrefix(url.Path, "/") opts := []electron.LinkOption{electron.Source(addr)} - if *prefetch > 0 { + if *prefetch > 0 { // Use a pre-fetch window opts = append(opts, electron.Capacity(*prefetch), electron.Prefetch(true)) + } else { // Grant credit for all expected messages at once + opts = append(opts, electron.Capacity(*count), electron.Prefetch(false)) } r, err := c.Receiver(opts...) fatalIf(err) @@ -103,7 +106,7 @@ func main() { fmt.Printf("Listening on %d connections\n", len(urls)) // print each message until the count is exceeded. - for i := uint64(0); i < *count; i++ { + for i := 0; i < *count; i++ { m := <-messages debugf("%v\n", m.Body()) } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/7856d2dc/tests/example-benchmark.sh ---------------------------------------------------------------------- diff --git a/tests/example-benchmark.sh b/tests/example-benchmark.sh new file mode 100755 index 0000000..b6ca21c --- /dev/null +++ b/tests/example-benchmark.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Simple script to time running the examples in various languages. +# Should be run in the build directory. +# Use command line to run different combinations. +# For example to run C broker, Go sender and C++ receiver pass arguments: C GO CPP + +MESSAGES=100000 +CREDIT=100 + +BLD=$(pwd) + +C=$BLD/c/examples +C_BROKER="$C/broker" +C_SEND="$C/send localhost amqp x $MESSAGES" +C_RECV="$C/receive localhost amqp x $MESSAGES" + +GO=$BLD/go/examples/electron +GO_BROKER="$GO/broker" +GO_SEND="$GO/send -count $MESSAGES /x" +GO_RECV="$GO/receive -count $MESSAGES /x" + +CPP=$BLD/cpp/examples +CPP_BROKER="$CPP/broker" +CPP_SEND="$CPP/simple_send -a /x -m $MESSAGES" +CPP_RECV="$CPP/simple_recv -a /x -m $MESSAGES" + +amqp_busy() { ss -tlp | grep $* amqp; } + +start_broker() { + amqp_busy && { "amqp port busy"; exit 1; } + "$@" & BROKER_PID=$! + until amqp_busy -q; do sleep .1; done +} + +stop_broker() { + kill $BROKER_PID + wait $BROKER_PID 2> /dev/null +} + +run() { + echo + echo "run: $*" + BROKER=${!1} + SEND=${!2} + RECV=${!3} + start_broker $BROKER + time { + $RECV > /dev/null& RECV_PID=$! + $SEND + wait $RECV_PID + } + stop_broker +} + +if test -z "$*"; then + # By default run the broker/sender/receiver combo for each language + run C_BROKER C_SEND C_RECV + run GO_BROKER GO_SEND GO_RECV + run CPP_BROKER CPP_SEND CPP_RECV +else + while test -n "$*"; do + run ${1}_BROKER ${2}_SEND ${3}_RECV + shift; shift; shift + done +fi --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org