diff options
author | Andrew Moss <1043609+amoss@users.noreply.github.com> | 2020-03-14 07:35:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-14 07:35:49 +0100 |
commit | 87a0559ec3f885ff64764ab1d48bb1cb52ce0ebe (patch) | |
tree | 4aaac1f709b5ab0d2d4b5c999811311d9efe3dfb /aclk/tests | |
parent | c999f89754072128d7efcf5581ad145ad8af5026 (diff) |
Improving the ACLK performance - initial changes (#8399)
Add an inspection point for VerneMQ in the local dev env. Remove the bottleneck in sending websocket messages, at the expense of increased CPU-load. Fixed the message encoding. Added support for stress testing - it is still enabled in the main loop so will fire stress-testing payloads when the ACLK is established.
Next patch will integrate the socket polling properly to reduce the CPU overhead and remove the stress testing payloads.
Diffstat (limited to 'aclk/tests')
-rwxr-xr-x | aclk/tests/launch-paho.sh | 4 | ||||
-rw-r--r-- | aclk/tests/paho-inspection.py | 57 | ||||
-rw-r--r-- | aclk/tests/paho.Dockerfile | 14 |
3 files changed, 75 insertions, 0 deletions
diff --git a/aclk/tests/launch-paho.sh b/aclk/tests/launch-paho.sh new file mode 100755 index 0000000000..1c2cb5f2c3 --- /dev/null +++ b/aclk/tests/launch-paho.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +docker build -f paho.Dockerfile . --build-arg "HOST_HOSTNAME=$(ping -c1 "$(hostname).local" | head -n1 | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*')" -t paho-client +docker run -it paho-client diff --git a/aclk/tests/paho-inspection.py b/aclk/tests/paho-inspection.py new file mode 100644 index 0000000000..b12b62da8c --- /dev/null +++ b/aclk/tests/paho-inspection.py @@ -0,0 +1,57 @@ +import ssl +import paho.mqtt.client as mqtt +import json +import time +import sys + +def on_connect(mqttc, obj, flags, rc): + if rc==0: + print("Successful connection", flush=True) + else : + print(f"Connection error rc={rc}", flush=True) + mqttc.subscribe("/agent/#",0) + +def on_disconnect(mqttc, obj, flags, rc): + print("disconnected rc: "+str(rc), flush=True) + +def on_message(mqttc, obj, msg): + print(f"{msg.topic} {len(msg.payload)}-bytes qos={msg.qos}", flush=True) + try: + print(f"Trying decode of {msg.payload[:60]}",flush=True) + api_msg = json.loads(msg.payload) + except Exception as e: + print(e,flush=True) + return + ts = api_msg["timestamp"] + mtype = api_msg["type"] + print(f"Message {mtype} time={ts} size {len(api_msg)}", flush=True) + now = time.time() + print(f"Current {now} -> Delay {now-ts}", flush=True) + +def on_publish(mqttc, obj, mid): + print("mid: "+str(mid), flush=True) + +def on_subscribe(mqttc, obj, mid, granted_qos): + print("Subscribed: "+str(mid)+" "+str(granted_qos), flush=True) + +def on_log(mqttc, obj, level, string): + print(string) + +print(f"Starting paho-inspection on {sys.argv[1]}", flush=True) +mqttc = mqtt.Client(transport='websockets',client_id="paho") +#mqttc.tls_set(certfile="server.crt", keyfile="server.key", cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLS, ciphers=None) +#mqttc.tls_set(ca_certs="server.crt", cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLS, ciphers=None) +mqttc.tls_set(cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLS, ciphers=None) +mqttc.tls_insecure_set(True) +mqttc.on_message = on_message +mqttc.on_connect = on_connect +mqttc.on_disconnect = on_disconnect +mqttc.on_publish = on_publish +mqttc.on_subscribe = on_subscribe +mqttc.username_pw_set("paho","paho") +mqttc.connect(sys.argv[1], 8443, 60) + +#mqttc.publish("/agent/mine","Test1") +#mqttc.subscribe("$SYS/#", 0) +print("Connected succesfully, monitoring /agent/#", flush=True) +mqttc.loop_forever() diff --git a/aclk/tests/paho.Dockerfile b/aclk/tests/paho.Dockerfile new file mode 100644 index 0000000000..d67cc4cb0c --- /dev/null +++ b/aclk/tests/paho.Dockerfile @@ -0,0 +1,14 @@ +FROM archlinux/base:latest + +RUN pacman -Syyu --noconfirm +RUN pacman --noconfirm --needed -S python-pip + +RUN pip install paho-mqtt + +RUN mkdir -p /opt/paho +COPY paho-inspection.py /opt/paho/ + +WORKDIR /opt/paho +ARG HOST_HOSTNAME +RUN echo $HOST_HOSTNAME >host +CMD ["/bin/bash", "-c", "/usr/sbin/python paho-inspection.py $(cat host)"] |