Unverified Commit f457b201 authored by kladko's avatar kladko

SKALE-4586 Added Thread Pool

parent ecde0240
This diff is collapsed.
This diff is collapsed.
......@@ -42,9 +42,11 @@ using namespace std;
shared_ptr <ZMQServer> ZMQServer::zmqServer = nullptr;
ZMQServer::ZMQServer(bool _checkSignature, bool _checkKeyOwnership, const string &_caCertFile)
: outgoingQueue(NUM_ZMQ_WORKER_THREADS), checkSignature(_checkSignature), checkKeyOwnership(_checkKeyOwnership),
: incomingQueue(NUM_ZMQ_WORKER_THREADS), checkSignature(_checkSignature), checkKeyOwnership(_checkKeyOwnership),
caCertFile(_caCertFile), ctx(make_shared<zmq::context_t>(1)) {
CHECK_STATE(NUM_ZMQ_WORKER_THREADS > 1);
socket = make_shared<zmq::socket_t>(*ctx, ZMQ_ROUTER);
if (_checkSignature) {
......@@ -277,12 +279,20 @@ void ZMQServer::doOneServerLoop() {
CHECK_STATE2(msg, ZMQ_COULD_NOT_PARSE);
uint64_t index = 0;
if ((dynamic_pointer_cast<BLSSignReqMessage>(msg)!= nullptr) ||
dynamic_pointer_cast<ECDSASignReqMessage>(msg)) {
index = NUM_ZMQ_WORKER_THREADS - 1;
} else {
index = 0;
}
auto element = pair<shared_ptr<ZMQMessage>, shared_ptr<zmq::message_t>>(msg, identity);
incomingQueue.at(index).enqueue(element);
result = msg->process();
} catch (ExitRequestedException) {
throw;
......
......@@ -34,6 +34,7 @@
#include "Agent.h"
#include "WorkerThreadPool.h"
#include "ZMQMessage.h"
using namespace moodycamel;
......@@ -41,6 +42,7 @@ typedef enum {GOT_INCOMING_MSG = 0, GOT_OUTFOING_MSG = 1} PollResult;
static const uint64_t NUM_ZMQ_WORKER_THREADS = 2;
class ZMQServer : public Agent{
uint64_t workerThreads;
......@@ -48,9 +50,9 @@ class ZMQServer : public Agent{
string caCertFile;
string caCert;
ReaderWriterQueue<pair<string, shared_ptr<zmq_msg_t>>> outgoingQueue;
ReaderWriterQueue<pair<string, shared_ptr<zmq::message_t>>> outgoingQueue;
vector<ReaderWriterQueue<pair<string, shared_ptr<zmq_msg_t>>>> incomingQueue;
vector<ReaderWriterQueue<pair<shared_ptr<ZMQMessage>, shared_ptr<zmq::message_t>>>> incomingQueue;
bool checkKeyOwnership = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment