ws redis command improvements + test script

This commit is contained in:
Benjamin Sergeant
2019-03-27 13:41:46 -07:00
parent 91198aca0d
commit 497373d976
11 changed files with 161 additions and 59 deletions

View File

@ -7,6 +7,8 @@
#include <iostream>
#include <sstream>
#include <chrono>
#include <thread>
#include <atomic>
#include "IXRedisClient.h"
namespace ix
@ -36,11 +38,10 @@ namespace ix
std::cout << "Auth response: " << authResponse << ":" << port << std::endl;
}
std::chrono::time_point<std::chrono::steady_clock> lastTimePoint;
int msgPerSeconds = 0;
int msgCount = 0;
std::atomic<int> msgPerSeconds(0);
std::atomic<int> msgCount(0);
auto callback = [&lastTimePoint, &msgPerSeconds, &msgCount, verbose]
auto callback = [&msgPerSeconds, &msgCount, verbose]
(const std::string& message)
{
if (verbose)
@ -49,21 +50,7 @@ namespace ix
}
msgPerSeconds++;
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;
}
msgCount++;
};
auto responseCallback = [](const std::string& redisResponse)
@ -71,6 +58,22 @@ namespace ix
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;
if (!redisClient.subscribe(channel, responseCallback, callback))
{