ws redis command improvements + test script
This commit is contained in:
parent
3388bb50e1
commit
7767c96a9e
1
DOCKER_VERSION
Normal file
1
DOCKER_VERSION
Normal file
@ -0,0 +1 @@
|
|||||||
|
1.3.2
|
31
Dockerfile
31
Dockerfile
@ -1,31 +0,0 @@
|
|||||||
FROM debian:stretch
|
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get -y install g++
|
|
||||||
RUN apt-get -y install libssl-dev
|
|
||||||
RUN apt-get -y install gdb
|
|
||||||
RUN apt-get -y install screen
|
|
||||||
RUN apt-get -y install procps
|
|
||||||
RUN apt-get -y install lsof
|
|
||||||
RUN apt-get -y install libz-dev
|
|
||||||
RUN apt-get -y install vim
|
|
||||||
RUN apt-get -y install make
|
|
||||||
RUN apt-get -y install cmake
|
|
||||||
RUN apt-get -y install curl
|
|
||||||
RUN apt-get -y install python
|
|
||||||
RUN apt-get -y install netcat
|
|
||||||
|
|
||||||
# debian strech cmake is too old for building with Docker
|
|
||||||
COPY makefile .
|
|
||||||
RUN ["make", "install_cmake_for_linux"]
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-rc4-Linux-x86_64/bin
|
|
||||||
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
|
||||||
|
|
||||||
# RUN ["make"]
|
|
||||||
|
|
||||||
EXPOSE 8765
|
|
||||||
CMD ["/ws/ws", "transfer", "--port", "8765", "--host", "0.0.0.0"]
|
|
1
Dockerfile
Symbolic link
1
Dockerfile
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
Dockerfile.dev
|
31
Dockerfile.dev
Normal file
31
Dockerfile.dev
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
FROM debian:stretch
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get -y install g++
|
||||||
|
RUN apt-get -y install libssl-dev
|
||||||
|
RUN apt-get -y install gdb
|
||||||
|
RUN apt-get -y install screen
|
||||||
|
RUN apt-get -y install procps
|
||||||
|
RUN apt-get -y install lsof
|
||||||
|
RUN apt-get -y install libz-dev
|
||||||
|
RUN apt-get -y install vim
|
||||||
|
RUN apt-get -y install make
|
||||||
|
RUN apt-get -y install cmake
|
||||||
|
RUN apt-get -y install curl
|
||||||
|
RUN apt-get -y install python
|
||||||
|
RUN apt-get -y install netcat
|
||||||
|
|
||||||
|
# debian strech cmake is too old for building with Docker
|
||||||
|
COPY makefile .
|
||||||
|
RUN ["make", "install_cmake_for_linux"]
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-rc4-Linux-x86_64/bin
|
||||||
|
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
||||||
|
|
||||||
|
# RUN ["make"]
|
||||||
|
|
||||||
|
EXPOSE 8765
|
||||||
|
CMD ["/ws/ws", "transfer", "--port", "8765", "--host", "0.0.0.0"]
|
30
Dockerfile.prod
Normal file
30
Dockerfile.prod
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
FROM debian:buster
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update
|
||||||
|
|
||||||
|
RUN apt-get -y install g++
|
||||||
|
RUN apt-get -y install libssl-dev
|
||||||
|
RUN apt-get -y install libz-dev
|
||||||
|
RUN apt-get -y install make
|
||||||
|
|
||||||
|
RUN apt-get -y install wget
|
||||||
|
RUN mkdir -p /tmp/cmake
|
||||||
|
WORKDIR /tmp/cmake
|
||||||
|
RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
RUN tar zxf cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
|
||||||
|
RUN adduser app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-Linux-x86_64/bin
|
||||||
|
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
||||||
|
|
||||||
|
RUN ["make"]
|
||||||
|
|
||||||
|
# Now run in usermode
|
||||||
|
USER app
|
||||||
|
|
||||||
|
EXPOSE 8765
|
||||||
|
CMD ["bash"]
|
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
ws:
|
||||||
|
stdin_open: true
|
||||||
|
tty: true
|
||||||
|
image: bsergean/ws:build
|
||||||
|
ports:
|
||||||
|
- "8765:8765"
|
||||||
|
entrypoint: bash
|
||||||
|
networks:
|
||||||
|
- ws-net
|
||||||
|
depends_on:
|
||||||
|
- redis1
|
||||||
|
|
||||||
|
redis1:
|
||||||
|
image: redis:alpine
|
||||||
|
networks:
|
||||||
|
- ws-net
|
||||||
|
|
||||||
|
networks:
|
||||||
|
ws-net:
|
14
makefile
14
makefile
@ -9,8 +9,20 @@ brew:
|
|||||||
mkdir -p build && (cd build ; cmake .. ; make -j install)
|
mkdir -p build && (cd build ; cmake .. ; make -j install)
|
||||||
|
|
||||||
.PHONY: docker
|
.PHONY: docker
|
||||||
|
|
||||||
|
NAME := bsergean/ws
|
||||||
|
TAG := $(shell cat DOCKER_VERSION)
|
||||||
|
IMG := ${NAME}:${TAG}
|
||||||
|
LATEST := ${NAME}:latest
|
||||||
|
BUILD := ${NAME}:build
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
docker build -t ws:latest .
|
docker build -t ${IMG} .
|
||||||
|
docker tag ${IMG} ${BUILD}
|
||||||
|
|
||||||
|
docker_push:
|
||||||
|
docker tag ${IMG} ${LATEST}
|
||||||
|
docker push ${LATEST}
|
||||||
|
|
||||||
run:
|
run:
|
||||||
docker run --cap-add sys_ptrace -it ws:latest
|
docker run --cap-add sys_ptrace -it ws:latest
|
||||||
|
25
ws/test_ws_redis.sh
Normal file
25
ws/test_ws_redis.sh
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Handle Ctrl-C by killing all sub-processing AND exiting
|
||||||
|
trap cleanup INT
|
||||||
|
|
||||||
|
function cleanup {
|
||||||
|
kill `cat /tmp/pidfile.subscribe`
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
REDIS_HOST=${REDIS_HOST:=localhost}
|
||||||
|
|
||||||
|
ws redis_subscribe --pidfile /tmp/pidfile.subscribe --host $REDIS_HOST foo &
|
||||||
|
|
||||||
|
# Wait for the subscriber to be ready
|
||||||
|
sleep 0.5
|
||||||
|
|
||||||
|
# Now publish messages
|
||||||
|
ws redis_publish -c 100000 --host ${REDIS_HOST} foo bar
|
||||||
|
|
||||||
|
# Wait a little for all messages to be received
|
||||||
|
sleep 0.5
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
cleanup
|
@ -49,6 +49,7 @@ int main(int argc, char** argv)
|
|||||||
int transferTimeout = 1800;
|
int transferTimeout = 1800;
|
||||||
int maxRedirects = 5;
|
int maxRedirects = 5;
|
||||||
int delayMs = -1;
|
int delayMs = -1;
|
||||||
|
int count = 1;
|
||||||
|
|
||||||
CLI::App* sendApp = app.add_subcommand("send", "Send a file");
|
CLI::App* sendApp = app.add_subcommand("send", "Send a file");
|
||||||
sendApp->add_option("url", url, "Connection url")->required();
|
sendApp->add_option("url", url, "Connection url")->required();
|
||||||
@ -106,6 +107,7 @@ int main(int argc, char** argv)
|
|||||||
redisPublishApp->add_option("--password", password, "Password");
|
redisPublishApp->add_option("--password", password, "Password");
|
||||||
redisPublishApp->add_option("channel", channel, "Channel")->required();
|
redisPublishApp->add_option("channel", channel, "Channel")->required();
|
||||||
redisPublishApp->add_option("message", message, "Message")->required();
|
redisPublishApp->add_option("message", message, "Message")->required();
|
||||||
|
redisPublishApp->add_option("-c", count, "Count");
|
||||||
|
|
||||||
CLI::App* redisSubscribeApp = app.add_subcommand("redis_subscribe", "Redis subscriber");
|
CLI::App* redisSubscribeApp = app.add_subcommand("redis_subscribe", "Redis subscriber");
|
||||||
redisSubscribeApp->add_option("--port", redisPort, "Port");
|
redisSubscribeApp->add_option("--port", redisPort, "Port");
|
||||||
@ -113,6 +115,7 @@ int main(int argc, char** argv)
|
|||||||
redisSubscribeApp->add_option("--password", password, "Password");
|
redisSubscribeApp->add_option("--password", password, "Password");
|
||||||
redisSubscribeApp->add_option("channel", channel, "Channel")->required();
|
redisSubscribeApp->add_option("channel", channel, "Channel")->required();
|
||||||
redisSubscribeApp->add_flag("-v", verbose, "Verbose");
|
redisSubscribeApp->add_flag("-v", verbose, "Verbose");
|
||||||
|
redisSubscribeApp->add_option("--pidfile", pidfile, "Pid file");
|
||||||
|
|
||||||
CLI11_PARSE(app, argc, argv);
|
CLI11_PARSE(app, argc, argv);
|
||||||
|
|
||||||
@ -169,7 +172,8 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
else if (app.got_subcommand("redis_publish"))
|
else if (app.got_subcommand("redis_publish"))
|
||||||
{
|
{
|
||||||
return ix::ws_redis_publish_main(hostname, redisPort, password, channel, message);
|
return ix::ws_redis_publish_main(hostname, redisPort, password,
|
||||||
|
channel, message, count);
|
||||||
}
|
}
|
||||||
else if (app.got_subcommand("redis_subscribe"))
|
else if (app.got_subcommand("redis_subscribe"))
|
||||||
{
|
{
|
||||||
|
3
ws/ws.h
3
ws/ws.h
@ -44,7 +44,8 @@ namespace ix
|
|||||||
int port,
|
int port,
|
||||||
const std::string& password,
|
const std::string& password,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
const std::string& message);
|
const std::string& message,
|
||||||
|
int count);
|
||||||
|
|
||||||
int ws_redis_subscribe_main(const std::string& hostname,
|
int ws_redis_subscribe_main(const std::string& hostname,
|
||||||
int port,
|
int port,
|
||||||
|
@ -14,7 +14,8 @@ namespace ix
|
|||||||
int port,
|
int port,
|
||||||
const std::string& password,
|
const std::string& password,
|
||||||
const std::string& channel,
|
const std::string& channel,
|
||||||
const std::string& message)
|
const std::string& message,
|
||||||
|
int count)
|
||||||
{
|
{
|
||||||
RedisClient redisClient;
|
RedisClient redisClient;
|
||||||
if (!redisClient.connect(hostname, port))
|
if (!redisClient.connect(hostname, port))
|
||||||
@ -35,12 +36,15 @@ namespace ix
|
|||||||
std::cout << "Auth response: " << authResponse << ":" << port << std::endl;
|
std::cout << "Auth response: " << authResponse << ":" << port << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << "Publishing message " << message
|
for (int i = 0; i < count; i++)
|
||||||
<< " to " << channel << "..." << std::endl;
|
|
||||||
if (!redisClient.publish(channel, message))
|
|
||||||
{
|
{
|
||||||
std::cerr << "Error publishing to channel " << channel << std::endl;
|
//std::cerr << "Publishing message " << message
|
||||||
return 1;
|
// << " to " << channel << "..." << std::endl;
|
||||||
|
if (!redisClient.publish(channel, message))
|
||||||
|
{
|
||||||
|
std::cerr << "Error publishing to channel " << channel << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
#include "IXRedisClient.h"
|
#include "IXRedisClient.h"
|
||||||
|
|
||||||
namespace ix
|
namespace ix
|
||||||
@ -36,11 +38,10 @@ namespace ix
|
|||||||
std::cout << "Auth response: " << authResponse << ":" << port << std::endl;
|
std::cout << "Auth response: " << authResponse << ":" << port << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::steady_clock> lastTimePoint;
|
std::atomic<int> msgPerSeconds(0);
|
||||||
int msgPerSeconds = 0;
|
std::atomic<int> msgCount(0);
|
||||||
int msgCount = 0;
|
|
||||||
|
|
||||||
auto callback = [&lastTimePoint, &msgPerSeconds, &msgCount, verbose]
|
auto callback = [&msgPerSeconds, &msgCount, verbose]
|
||||||
(const std::string& message)
|
(const std::string& message)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
@ -49,21 +50,7 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgPerSeconds++;
|
msgPerSeconds++;
|
||||||
|
msgCount++;
|
||||||
auto now = std::chrono::steady_clock::now();
|
|
||||||
if (now - lastTimePoint > std::chrono::seconds(1))
|
|
||||||
{
|
|
||||||
lastTimePoint = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
msgCount += msgPerSeconds;
|
|
||||||
|
|
||||||
// #messages 901 msg/s 150
|
|
||||||
std::cout << "#messages " << msgCount << " "
|
|
||||||
<< "msg/s " << msgPerSeconds
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
msgPerSeconds = 0;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto responseCallback = [](const std::string& redisResponse)
|
auto responseCallback = [](const std::string& redisResponse)
|
||||||
@ -71,6 +58,22 @@ namespace ix
|
|||||||
std::cout << "Redis subscribe response: " << redisResponse << std::endl;
|
std::cout << "Redis subscribe response: " << redisResponse << std::endl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto timer = [&msgPerSeconds, &msgCount]
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
std::cout << "#messages " << msgCount << " "
|
||||||
|
<< "msg/s " << msgPerSeconds
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
msgPerSeconds = 0;
|
||||||
|
auto duration = std::chrono::seconds(1);
|
||||||
|
std::this_thread::sleep_for(duration);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::thread t(timer);
|
||||||
|
|
||||||
std::cerr << "Subscribing to " << channel << "..." << std::endl;
|
std::cerr << "Subscribing to " << channel << "..." << std::endl;
|
||||||
if (!redisClient.subscribe(channel, responseCallback, callback))
|
if (!redisClient.subscribe(channel, responseCallback, callback))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user