Skip to content

Commit

Permalink
[FAB-6132] Provide Kafka environment for benchmark
Browse files Browse the repository at this point in the history
Add a 3 broker kafka environment for use when running benchmarks.

1. cd orderer/common/server

2. Start kafka:

   docker-compose up -d

3. Run all kafka benchmarks:

   BENCHMARK=true go test -run TestOrdererBenchmarkKafkaBroadcast

   or, specify a single benchmark permutation as follows:

   TestOrdererBenchmarkKafkaBroadcast/10ch/10000tx/10kb/10bc/0dc/10ord
   (The permutation has to be valid as defined in the source code)

Change-Id: I2e24c73dcb450f98992f6c21420fda64372012f6
Signed-off-by: Kostas Christidis <kostas@christidis.io>
Signed-off-by: Luis Sanchez <sanchezl@us.ibm.com>
  • Loading branch information
Luis Sanchez authored and kchristidis committed Sep 16, 2017
1 parent 61c8f1f commit 7a3f162
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 6 deletions.
40 changes: 34 additions & 6 deletions orderer/common/server/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,39 @@ import (
"github.com/stretchr/testify/assert"
)

// Usage: BENCHMARK=true go test -run=TestOrdererBenchmark[Solo|Kafka][Broadcast|Deliver]
// USAGE
//
// BENCHMARK=true go test -run=TestOrdererBenchmark[Solo|Kafka][Broadcast|Deliver]
//
// You can specify a specific test permutation by specifying the complete subtest
// name corresponding to the permutation you would like to run. e.g:
//
// TestOrdererBenchmark[Solo|Kafka][Broadcast|Deliver]/10ch/10000tx/10kb/10bc/0dc/10ord
//
// (The permutation has to be valid as defined in the source code)
//
// RUNNING KAFKA ORDERER BENCHMARKS
//
// A Kafka cluster is required to run the Kafka-based benchmark. The benchmark
// expects to find a seed broker is listening on localhost:9092.
//
// A suitable Kafka cluster is provided as a docker compose application defined
// in the docker-compose.yml file provided with this package. To run the Kafka
// benchmarks with the provided Kafaka cluster:
//
// From this package's directory, first run:
//
// docker-compose up -d
//
// Then execute:
//
// BENCHMARK=true go test -run TestOrdererBenchmarkKafkaBroadcast
//
// If you are not using the Kafka cluster provided in the docker-compose.yml,
// the list of seed brokers can be adjusted by setting the value of
// x_ORDERERS_KAFKA_BROKERS in the `envvars` map below.
//
// DESCRIPTION
//
// Benchmark test makes [ch] channels, creates [bc] clients per channel per orderer. There
// are [ord] orderer instances in total. A client ONLY interacts with ONE channel and ONE
Expand Down Expand Up @@ -69,10 +101,6 @@ import (
// as deliver is effectively retrieving pre-generated blocks, so it shouldn't be choked
// by slower broadcast.
//
// Note: At least three Kafka brokers listening on localhost:[9092-9094] are required to
// run the Kafka-based benchmark. This is set in the `envvars` map and can be adjusted
// if need be.
// TODO Spin up ephemeral Kafka containers for test

const (
MaxMessageCount = 10
Expand All @@ -92,7 +120,7 @@ var envvars = map[string]string{
localconfig.Prefix + "_ORDERER_BATCHSIZE_MAXMESSAGECOUNT": strconv.Itoa(MaxMessageCount),
localconfig.Prefix + "_ORDERER_BATCHSIZE_ABSOLUTEMAXBYTES": strconv.Itoa(AbsoluteMaxBytes) + " KB",
localconfig.Prefix + "_ORDERER_BATCHSIZE_PREFERREDMAXBYTES": strconv.Itoa(PreferredMaxBytes) + " KB",
localconfig.Prefix + "_ORDERER_KAFKA_BROKERS": "[localhost:9092, localhost:9093, localhost:9094]",
localconfig.Prefix + "_ORDERER_KAFKA_BROKERS": "[localhost:9092]",
}

type factors struct {
Expand Down
132 changes: 132 additions & 0 deletions orderer/common/server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
version: '3'

# Defines a 3 broker Kafka cluster environment.
# - Kafka brokers are exposed on the host network on ports 9092, 9192, & 9292.
# - No communication security (e.g. TLS) has been enabled.
# - A 3 node Zookeeper cluster is also defined, but not exposed to the host.
# - Kafka brokers use separate listeners for communication inside and outside
# the docker environment.
# - EXTERNAL listener ports are mapped to the host network.
# - REPLICATION listener ports are used for broker-to-broker communication.
#
# Host Kafka Internal Zookeeper
# Network Cluster Network Cluster
# ┌───┐ ┌───┐
# │ │ ┌───────────────┐ │ │ ┌──────┐
# ┌────┴─┐ │ ┌────┴─┐ │ │ │◀──▶│ 2181 ├─────────────┐
# │ 9092 │─┼──▶│ 9092 │ kafka0 │ │ │ └────┬─┘ │
# └────┬─┘ │ └────┬─┘ ┌─┴────┐ │ │ │ zookeeper0 │
# │ │ └─────────────┤ 9093 │◀──▶│ │ │ │
# │ │ └──────┘ │ │ └───────────────┘
# │ │ │ │
# │ │ ┌───────────────┐ │ │ ┌──────┐
# ┌────┴─┐ │ ┌────┴─┐ │ │ │◀──▶│ 2181 ├─────────────┐
# │ 9192 │─┼──▶│ 9092 │ kafka1 │ │ │ └────┬─┘ │
# └────┬─┘ │ └────┬─┘ ┌─┴────┐ │ │ │ zookeeper0 │
# │ │ └─────────────┤ 9093 │◀──▶│ │ │ │
# │ │ └──────┘ │ │ └───────────────┘
# │ │ │ │
# │ │ ┌───────────────┐ │ │ ┌──────┐
# ┌────┴─┐ │ ┌────┴─┐ │ │ │◀──▶│ 2181 ├─────────────┐
# │ 9292 │─┼──▶│ 9092 │ kafka2 │ │ │ └────┬─┘ │
# └────┬─┘ │ └────┬─┘ ┌─┴────┐ │ │ │ zookeeper0 │
# │ │ └─────────────┤ 9093 │◀──▶│ │ │ │
# │ │ └──────┘ │ │ └───────────────┘
# │ │ │ │
# └───┘ └───┘

services:

zookeeper0:
image: hyperledger/fabric-zookeeper
restart: always
environment:
- ZOO_MY_ID=200
- ZOO_SERVERS=server.200=zookeeper0:2888:3888 server.201=zookeeper1:2888:3888 server.202=zookeeper2:2888:3888

zookeeper1:
image: hyperledger/fabric-zookeeper
restart: always
environment:
- ZOO_MY_ID=201
- ZOO_SERVERS=server.200=zookeeper0:2888:3888 server.201=zookeeper1:2888:3888 server.202=zookeeper2:2888:3888

zookeeper2:
image: hyperledger/fabric-zookeeper
restart: always
environment:
- ZOO_MY_ID=202
- ZOO_SERVERS=server.200=zookeeper0:2888:3888 server.201=zookeeper1:2888:3888 server.202=zookeeper2:2888:3888

kafka0:
image: hyperledger/fabric-kafka
restart: always
environment:
- KAFKA_BROKER_ID=800
- KAFKA_HOST_NAME=kafka0
- KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
- KAFKA_LISTENERS=EXTERNAL://0.0.0.0:9092,REPLICATION://0.0.0.0:9093
- KAFKA_ADVERTISED_LISTENERS=EXTERNAL://localhost:9092,REPLICATION://kafka0:9093
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=EXTERNAL:PLAINTEXT,REPLICATION:PLAINTEXT
- KAFKA_INTER_BROKER_LISTENER_NAME=REPLICATION
- KAFKA_MESSAGE_MAX_BYTES=103809024
- KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
- KAFKA_MIN_INSYNC_REPLICAS=2
depends_on:
- zookeeper0
- zookeeper1
- zookeeper2
ports:
- 9092:9092

kafka1:
image: hyperledger/fabric-kafka
restart: always
environment:
- KAFKA_BROKER_ID=801
- KAFKA_HOST_NAME=kafka1
- KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
- KAFKA_LISTENERS=EXTERNAL://0.0.0.0:9092,REPLICATION://0.0.0.0:9093
- KAFKA_ADVERTISED_LISTENERS=EXTERNAL://localhost:9192,REPLICATION://kafka1:9093
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=EXTERNAL:PLAINTEXT,REPLICATION:PLAINTEXT
- KAFKA_INTER_BROKER_LISTENER_NAME=REPLICATION
- KAFKA_MESSAGE_MAX_BYTES=103809024
- KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
- KAFKA_MIN_INSYNC_REPLICAS=2
depends_on:
- zookeeper0
- zookeeper1
- zookeeper2
ports:
- 9192:9092

kafka2:
image: hyperledger/fabric-kafka
restart: always
environment:
- KAFKA_BROKER_ID=802
- KAFKA_HOST_NAME=kafka2
- KAFKA_ZOOKEEPER_CONNECT=zookeeper0:2181,zookeeper1:2181,zookeeper2:2181
- KAFKA_LISTENERS=EXTERNAL://0.0.0.0:9092,REPLICATION://0.0.0.0:9093
- KAFKA_ADVERTISED_LISTENERS=EXTERNAL://localhost:9292,REPLICATION://kafka2:9093
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=EXTERNAL:PLAINTEXT,REPLICATION:PLAINTEXT
- KAFKA_INTER_BROKER_LISTENER_NAME=REPLICATION
- KAFKA_MESSAGE_MAX_BYTES=103809024
- KAFKA_REPLICA_FETCH_MAX_BYTES=103809024
- KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE=false
- KAFKA_DEFAULT_REPLICATION_FACTOR=3
- KAFKA_MIN_INSYNC_REPLICAS=2
depends_on:
- zookeeper0
- zookeeper1
- zookeeper2
ports:
- 9292:9092

0 comments on commit 7a3f162

Please sign in to comment.