Skip to content

Commit

Permalink
Merge pull request #73 from emqx/bump-lee
Browse files Browse the repository at this point in the history
Bump lee
  • Loading branch information
ieQu1 authored Jan 2, 2025
2 parents 8ef2b51 + 98ca65d commit e614221
Show file tree
Hide file tree
Showing 26 changed files with 659 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install additional packages
run: |
apt-get update
apt-get install -y openjdk-11-jdk asciidoctor xsltproc docbook-xsl
apt-get install -y texinfo install-info
- name: Compile and run tests
env:
BUILD_WITHOUT_QUIC: "true"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
name: Install additional packages
run: |
apt-get update
apt-get install -y openjdk-11-jdk asciidoctor xsltproc docbook-xsl python3-pygments
apt-get install -y texinfo install-info
- name: Build
shell: bash
run: |
export BUILD_WITHOUT_QUIC=1
git config --global --add safe.directory $(pwd)
make release
tar czf docs.tar.gz _build/lee_doc/html _build/lee_doc/man _build/lee_doc/src/
tar czf docs.tar.gz doc/html doc/info
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ TAGS
/*.tar.gz
/emqttb
/libquicer_nif.so
doc/lee
doc/info
doc/html
perf.data
40 changes: 10 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
REBAR ?= $(CURDIR)/rebar3
REBAR_URL ?= https://s3.amazonaws.com/rebar3/rebar3
XSLTNG := _build/lee_doc/docbook-xslTNG-2.1.2/libs/docbook-xslTNG-2.1.2.jar
DOCBOOK := _build/lee_doc/src/output.xml
MANPAGE_STYLESHEET ?= /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
WWW := _build/lee_doc/html/index.html
MANPAGE := _build/lee_doc/man/emqttb.1
CAN_BUILD_DOCS ?= true
TEXINFO := doc/src/emqttb.texi doc/lee/cli_params.texi doc/lee/os_env.texi doc/lee/value.texi

.PHONY: all
all: $(REBAR)
Expand All @@ -28,40 +23,25 @@ release: compile docs
@$(REBAR) as emqttb tar
@$(CURDIR)/scripts/rename-package.sh

$(DOCBOOK): scripts/docgen.escript compile
escript scripts/docgen.escript $@

.PHONY: docs
ifeq ($(CAN_BUILD_DOCS), true)
docs: $(MANPAGE) $(WWW)
else
docs:
@echo "!! Docs are not being built"
endif
docs: doc/info/emqttb.info doc/html/index.html

$(MANPAGE): $(DOCBOOK)
xsltproc -o "$$(dirname $<)/../man/" $(MANPAGE_STYLESHEET) "$<"
doc/info/emqttb.info: $(TEXINFO)
texi2any -I doc/lee --info -o $@ $<
install-info $@ doc/info/dir

$(WWW): $(DOCBOOK) $(XSLTNG)
mkdir -p "$$(dirname $@)"
cd $$(dirname $@) ;\
java -jar $(CURDIR)/$(XSLTNG) resource-base-uri='./' chunk-output-base-uri='./' \
verbatim-syntax-highlight-languages='bash erlang' \
mathml-js='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' \
chunk=index.html persistent-toc=true chunk-nav=true $(CURDIR)/$<
cp -R _build/lee_doc/docbook-xslTNG-2.1.2/resources/* $$(dirname $@)
doc/html/index.html: $(TEXINFO)
texi2any -I doc/lee --html -c INFO_JS_DIR=js -c HTML_MATH=mathjax -o doc/html/ $<

$(XSLTNG):
cd _build/lee_doc/ && \
wget https://github.com/docbook/xslTNG/releases/download/2.1.2/docbook-xslTNG-2.1.2.zip && \
unzip docbook-xslTNG-2.1.2.zip
$(TEXINFO): scripts/docgen.escript compile
scripts/docgen.escript doc/lee

.PHONY: clean
clean: distclean

.PHONY: distclean
distclean:
@rm -rf _build erl_crash.dump rebar3.crashdump rebar.lock emqttb
@rm -rf _build erl_crash.dump rebar3.crashdump rebar.lock emqttb doc/lee doc/html doc/info

$(REBAR):
@curl -skfL "$(REBAR_URL)" -o $@
Expand Down
14 changes: 10 additions & 4 deletions bin/emqttb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ RUNNER_ROOT_DIR="{{ runner_root_dir }}"
RUNNER_ESCRIPT_DIR="{{ runner_escript_dir }}"
ERTS_VSN="{{ erts_vsn }}"

ERTS_PATH=$RUNNER_ROOT_DIR/erts-$ERTS_VSN/bin
ERTS_PATH="${RUNNER_ROOT_DIR}/erts-${ERTS_VSN}/bin"

export INFOPATH="${INFOPATH}:${RUNNER_ROOT_DIR}/doc/info"

ulimit -n $(ulimit -Hn)

help() {
info emqttb "${@}"
}

if [ $# -eq 2 ] && [ $1 = "--help" ]; then
man -l "${RUNNER_ROOT_DIR}/doc/man/emqttb-${2}.1"
help "${2}"
elif [ $# -eq 1 ] && [ $1 = "--help" ]; then
man -l "${RUNNER_ROOT_DIR}/doc/man/emqttb.1"
help
elif [ $# -eq 0 ]; then
man -l "${RUNNER_ROOT_DIR}/doc/man/emqttb.1"
help
else
exec ${ERTS_PATH}/escript ${RUNNER_ESCRIPT_DIR}/emqttb "$@"
fi
46 changes: 46 additions & 0 deletions doc/src/autorate_descr.texi
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
When the loadgen creates too much traffic, the system may get overloaded.
In this case, the test usually has to be restarted all over again with different parameters.
This can be very expensive in man-hours and computing resources.

In order to prevent that, emqttb can tune some parameters (such as message publishing interval)
automatically using
@url{https://controlguru.com/integral-reset-windup-jacketing-logic-and-the-velocity-pi-form/,PI controller}.

The following formula is used for the error function:

@math{e=(a_{SP} - a_{PV}) a_{coeff}}

@node Autoscale
@section Autoscale

A special autorate controlling the rate of spawning new clients is implicitly created for each client group.
Its name usually follows the pattern @code{%scenario%/conn_interval}.

By default, the number of pending (unacked) connections is used as the process variable.
Number of pending connections is a metric that responds very fast to target overload, so it makes a reasonable default.

For example the following command can automatically adjust the rate of connections:

@example
./emqttb --pushgw @@conn -I 10ms -N 5_000 \
@@a -a conn/conninterval -V 1000 --setpoint 10
@end example

@node SCRAM
@section SCRAM

Normally, autorate adjusts the control variable gradually.
However, sometimes the system under test becomes overloaded suddenly, and in this case slowly decreasing the pressure may not be efficient enough.
To combat this situation, @code{emqttb} has "SCRAM" mechanism, that immediately resets the control variable to a @ref{value/autorate/_/scram/override,configured safe value}.
This happens when the value of process variable exceeds a @ref{value/autorate/_/scram/threshold,certain threshold}.

SCRAM mode remains in effect until the number of pending connections becomes less than @math{\frac{t h}{100}}
where @math{t} is threshold, and @math{h} is @ref{value/autorate/_/scram/hysteresis,hystersis}.

@node Autorate List
@section List of autorate variables
@include autorate.texi

@node Metrics List
@section List of metrics
@include metric.texi
94 changes: 94 additions & 0 deletions doc/src/emqttb.texi
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename emqttb.info
@settitle EMQTTB
@c %**end of header

@dircategory EMQTTB: an MQTT load generator.
@direntry
* EMQTTB: (emqttb).
@end direntry

@copying
A scriptable autotuning MQTT load generator.

Copyright @copyright{} 2022-2025 EMQ Technologies Co., Ltd. All Rights Reserved.

@end copying

@include schema.texi

@c The document itself

@titlepage
@title EMQTTB
@subtitle A scriptable autotuning MQTT load generator
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage

@c Output the table of the contents at the beginning.
@contents

@ifnottex
@node Top
@top EMQTTB

@insertcopying
@end ifnottex

@node Introduction
@chapter Introduction
@include intro.texi

@node Invokation
@chapter Invokation
EMQTTB executable accepts named CLI arguments (such as @option{--foo} or -f positional arguments and actions. Actions are special CLI arguments that start with @@ character (e.g. @option{@@pub}). Actions correspond to different load-generation scenarios, such as @option{@@pub} and @option{@@sub}, client group configurations (@option{@@g}) and autorates (@option{@@g}).

Each CLI action defines its own scope of named and positional CLI arguments. Positional arguments are always specified after named arguments within the scope. There is also a global scope of arguments that don’t belong to any action. Global arguments are specified before the very first action.

Example:

@example
emqttb --foo --bar 1 positional1 positional2 @@action1 --foo 1 positional1 @@action2 ...
|___________| |_____________________| |_________________|
|regular args positional args | action1 scope
|___________________________________|
global scope
@end example

Flag negation:

Boolean flag arguments can be set to false by adding @code{no-} prefix, for example @option{--no-pushgw}.

Short boolean flags can be set to false using @code{+} sigil instead of @code{-}.

@node CLI
@section CLI Arguments
@lowersections
@include cli_param.texi
@raisesections

@node OS Environment Variables
@section OS Environment Variables
@lowersections
@include os_env.texi
@raisesections

@node Autorate
@chapter Autorate
@include autorate_descr.texi

@node All Values
@chapter All Configurable Values
@include value.texi

@node Index
@unnumbered Index

@syncodeindex vr cp
@syncodeindex fn cp
@printindex cp

@bye
55 changes: 55 additions & 0 deletions doc/src/intro.texi
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@node Concepts
@section Concepts: Worker, Group, Scenario...

@b{Worker} is a process that corresponds to a single MQTT client.

@b{Behavior} is a callback module containing functions that workers run in a loop.

@b{Group} is a supervised colletion of workers running the same behavior and sharing the same configuration. Group manager controls the number of workers, restarts failed workers and implements ramp up/down logic.

@b{Scenario} is a callback module that creates several worker groups and manupulates group configuration using autorate.

@b{Autorate} a process that adjusts group parameters (such as number of workers in the group, or worker configuration) based on constants or dynamic parameters, e.g. available RAM or CPU load, observed latency and so on.

@node Topic Patterns
@section Topic Patterns

@code{emqttb} supports pattern substitution in the topic names.

@table @samp
@item %n
replaced with the worker ID (integer)
@item %g
replaced with the group ID
@item %h
replaced with the hostname
@end table


@node Verify Message Sequence
@section Message Sequence Verification

@code{emqttb} has builtin tools for detecting message loss and repetition.

@quotation Warning
Publishers should insert metadata into the payloads in order for this feature to work.
@end quotation

@quotation Warning
This feature can use a lot of RAM to store the sequence numbers for each triple of sender client id, receiver client id, and MQTT topic.
@end quotation

Errors about missing messages and warnings about duplicate messages are printed to the emqttb log.

@heading Prometheus metrics

@table @code
@item emqttb_repeats_number
number of times when the sequence number of the message goes backwards
@item emqttb_gaps_number
number of times when the sequence number of the message skips the messages (a gap)
@item emqttb_repeat_size
rolling average; size of the repeated sequence
@item emqttb_gap_size
rolling average; size of the gap
@end table
Loading

0 comments on commit e614221

Please sign in to comment.