Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start a benchmark setup, then improve start times #42

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions benchmark/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
42 changes: 42 additions & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties

# Eclipse
.project
.classpath
.settings/
bin/

# IntelliJ
.idea
*.ipr
*.iml
*.iws

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode
.factorypath

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Local environment
.env

# non-quarkus
kubeconfig
44 changes: 44 additions & 0 deletions benchmark/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
[ -z "$DEBUG" ] || set -x
set -eo pipefail
WORKDIR="$(dirname $0)"
[ "$WORKDIR" != "." ] || WORKDIR="$PWD"

# NS=kkv-benchmark

# export KUBECONFIG="$WORKDIR/kubeconfig"
# echo "Hint: y-kubie ctx -f '$WORKDIR/kubeconfig'" -n $NS

# y-k3d cluster create kkv-benchmark || echo "Cluster already exists?"

# kubectl create namespace $NS
# kubectl config set-context --current --namespace=$NS

# kubectl -n $NS apply -k github.com/Yolean/kubernetes-kafka/variants/dev-small?ref=kafka-2.8.0

# skaffold dev --tail=true --port-forward=true --status-check=false

docker rm -f kkv-benchmark-kafka || true
docker build -t kafka-kraft:local kafka-kraft/
docker run -p 9094:9094 --name kkv-benchmark-kafka --rm -d kafka-kraft:local

echo "Running benchmark prepare"
# quarkus:dev with a main-class that terminates ends up here:
# https://github.com/quarkusio/quarkus/blob/c87b6fae3db21b10e225f81936d848eb05c09fec/core/deployment/src/main/java/io/quarkus/deployment/dev/IsolatedDevModeMain.java#L114
#mvn compile quarkus:dev -Dquarkus.package.main-class=prepare
mvn package -Dmaven.test.skip=true
java -jar target/quarkus-app/quarkus-run.jar

echo "Kafka starting..."
echo ""
echo "Starting kkv in dev mode ..."
echo "(the benchmark app can be started in a new shell using: mvn quarkus:dev -Dquarkus.package.main-class=)"
echo ""
(cd ../; mvn quarkus:dev \
-Dquarkus.http.port=8090 \
-Dkafka_bootstrap=localhost:9094 \
-Dtopic=kkv-benchmark \
-Dkafka_group_id=kkv1 \
-Dkafka_offset_reset=earliest \
-Dtarget=http://localhost:8080/kkv-benchmark/onupdate \
)
7 changes: 7 additions & 0 deletions benchmark/kafka-kraft/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM solsson/kafka:2.8.0-nonroot@sha256:a4a6d0d6fe723ec838d3c26ccb402ec0356e4b7016193ef620b11daa2c789a35

COPY server.properties config/

COPY start-dev.sh .

ENTRYPOINT ["./start-dev.sh"]
131 changes: 131 additions & 0 deletions benchmark/kafka-kraft/server.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# This configuration file is intended for use in KRaft mode, where
# Apache ZooKeeper is not present. See config/kraft/README.md for details.
#

# only for dev
auto.create.topics=true

############################# Server Basics #############################

# The role of this server. Setting this puts us in KRaft mode
process.roles=broker,controller

# The node id associated with this instance's roles
node.id=1

# The connect string for the controller quorum
controller.quorum.voters=1@localhost:9093

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9094,CONTROLLER://:9093
inter.broker.listener.name=PLAINTEXT

# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured. Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://localhost:9094

# Listener, host name, and port for the controller to advertise to the brokers. If
# this server is a controller, this listener must be configured.
controller.listener.names=CONTROLLER

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
listener.security.protocol.map=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma separated list of directories under which to store log files
log.dirs=/home/nonroot/kafka-data

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Internal Topic Settings #############################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended to ensure availability such as 3.
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
# 1. Durability: Unflushed data may be lost if you are not using replication.
# 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
# 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=-1

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000
8 changes: 8 additions & 0 deletions benchmark/kafka-kraft/start-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -x

ID=$(./bin/kafka-storage.sh random-uuid | tail -n 1)

./bin/kafka-storage.sh format -t $ID -c ./config/server.properties

./bin/kafka-server-start.sh ./config/server.properties
3 changes: 3 additions & 0 deletions benchmark/kafkaproxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM envoyproxy/envoy:v1.18.2@sha256:e8b37c1d75787dd1e712ff389b0d37337dc8a174a63bed9c34ba73359dc67da7

COPY envoy.yaml /etc/envoy/envoy.yaml
38 changes: 38 additions & 0 deletions benchmark/kafkaproxy/envoy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
admin:
access_log_path: /dev/null
address:
socket_address:
address: 0.0.0.0
port_value: 9091
static_resources:
listeners:
- address:
socket_address:
#address: 127.0.0.1
address: 0.0.0.0 # for port-forward
port_value: 9094
filter_chains:
- filters:
- name: envoy.filters.network.kafka_broker
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.kafka_broker.v3.KafkaBroker
stat_prefix: exampleprefix
- name: envoy.filters.network.tcp_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
stat_prefix: tcp
cluster: localkafka
clusters:
- name: localkafka
connect_timeout: 0.25s
type: strict_dns
lb_policy: round_robin
load_assignment:
cluster_name: some_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: bootstrap
port_value: 9092
62 changes: 62 additions & 0 deletions benchmark/kustomize/kkv-benchmark-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# apiVersion: apps/v1
# kind: StatefulSet
# metadata:
# name: kkv
# labels: &labels
# app: kkv
# spec:
# replicas: 1
# serviceName: kkv-example
apiVersion: apps/v1
kind: Deployment
metadata:
name: kkv
labels: &labels
app: kkv
spec:
replicas: 1
selector:
matchLabels: *labels
template:
metadata:
labels: *labels
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8081"
prometheus.io/path: "/stats/prometheus"
spec:
containers:
- name: kafkaproxy
image: builds-registry.ystack.svc.cluster.local/yolean/kkv-benchmark-kafkaproxy
ports:
- containerPort: 9094
name: kafka-localhost
- name: kkv
image: builds-registry.ystack.svc.cluster.local/yolean/kafka-keyvalue
ports:
- containerPort: 8090
name: api
- containerPort: 5005
name: debugger
env:
- name: kafka_bootstrap
value: localhost:9094
- name: kafka_group_id
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: topic
value: kkv-benchmark
- name: kafka_offset_reset
value: earliest
- name: target
value: http://127.0.0.1:8080/204/__TOPIC__
readinessProbe:
httpGet:
path: /q/health/ready
port: api
livenessProbe:
httpGet:
path: /q/health/live
port: api
initialDelaySeconds: 30
3 changes: 3 additions & 0 deletions benchmark/kustomize/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace: kkv-benchmark
resources:
- kkv-benchmark-app.yaml
Loading