mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 08:41:16 +00:00
FairMQ: Add uuid generator to tools & let tests use it for session names.
This commit is contained in:
parent
85aab51bd4
commit
0dc4000187
|
@ -110,6 +110,7 @@ set(FAIRMQ_HEADER_FILES
|
|||
tools/Network.h
|
||||
tools/Strings.h
|
||||
tools/Version.h
|
||||
tools/Unique.h
|
||||
zeromq/FairMQMessageZMQ.h
|
||||
zeromq/FairMQPollerZMQ.h
|
||||
zeromq/FairMQUnmanagedRegionZMQ.h
|
||||
|
@ -269,6 +270,8 @@ target_link_libraries(runConfigExample FairMQ)
|
|||
add_executable(shmmonitor shmem/runMonitor.cxx)
|
||||
target_link_libraries(shmmonitor FairMQ)
|
||||
|
||||
add_executable(uuidGen run/runUuidGenerator.cxx)
|
||||
target_link_libraries(uuidGen FairMQ)
|
||||
|
||||
####################
|
||||
# aggregate target #
|
||||
|
|
|
@ -13,10 +13,7 @@
|
|||
#include <nanomsg/FairMQTransportFactoryNN.h>
|
||||
#endif /* NANOMSG_FOUND */
|
||||
#include <FairMQLogger.h>
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -36,7 +33,7 @@ auto FairMQTransportFactory::CreateTransportFactory(const std::string& type, con
|
|||
// Generate uuid if empty
|
||||
if (finalId == "")
|
||||
{
|
||||
finalId = boost::uuids::to_string(boost::uuids::random_generator()());
|
||||
finalId = fair::mq::tools::Uuid();
|
||||
}
|
||||
|
||||
if (type == "zeromq")
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <fairmq/tools/Network.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <fairmq/tools/Version.h>
|
||||
#include <fairmq/tools/Unique.h>
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
#endif // FAIR_MQ_TOOLS_H
|
||||
|
|
58
fairmq/run/runUuidGenerator.cxx
Normal file
58
fairmq/run/runUuidGenerator.cxx
Normal file
|
@ -0,0 +1,58 @@
|
|||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::program_options;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool hash = false;
|
||||
|
||||
options_description desc("Options");
|
||||
desc.add_options()
|
||||
("hash,h", value<bool>(&hash)->implicit_value(true), "Generates UUID and returns its hash.")
|
||||
("help", "Print help");
|
||||
|
||||
variables_map vm;
|
||||
store(parse_command_line(argc, argv, desc), vm);
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
cout << "UUID generator" << endl << desc << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
notify(vm);
|
||||
|
||||
if (hash)
|
||||
{
|
||||
std::cout << fair::mq::tools::UuidHash() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << fair::mq::tools::Uuid() << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cerr << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit" << endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -35,12 +35,12 @@ FairMQ::Transport FairMQTransportFactorySHM::fTransportType = FairMQ::Transport:
|
|||
|
||||
FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const FairMQProgOptions* config)
|
||||
: FairMQTransportFactory(id)
|
||||
, fSessionName("default")
|
||||
, fSessionName()
|
||||
, fContext(nullptr)
|
||||
, fHeartbeatSocket(nullptr)
|
||||
, fHeartbeatThread()
|
||||
, fSendHeartbeats(true)
|
||||
, fShMutex(bipc::open_or_create, std::string("fmq_shm_" + fSessionName + "_mutex").c_str())
|
||||
, fShMutex(nullptr)
|
||||
, fDeviceCounter(nullptr)
|
||||
, fManager(nullptr)
|
||||
{
|
||||
|
@ -62,6 +62,7 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||
{
|
||||
numIoThreads = config->GetValue<int>("io-threads");
|
||||
fSessionName = config->GetValue<string>("session");
|
||||
fSessionName.resize(8); // shorten the session name, to acomodate for name size limit on some systems (MacOS)
|
||||
// fSegmentName = "fmq_shm_" + fSessionName + "_main";
|
||||
segmentSize = config->GetValue<size_t>("shm-segment-size");
|
||||
}
|
||||
|
@ -70,6 +71,10 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||
LOG(WARN) << "shmem: FairMQProgOptions not available! Using defaults.";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fShMutex = fair::mq::tools::make_unique<bipc::named_mutex>(bipc::open_or_create, std::string("fmq_shm_" + fSessionName + "_mutex").c_str());
|
||||
|
||||
if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0)
|
||||
{
|
||||
LOG(ERROR) << "shmem: failed configuring context, reason: " << zmq_strerror(errno);
|
||||
|
@ -85,7 +90,7 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||
LOG(DEBUG) << "shmem: created/opened shared memory segment of " << segmentSize << " bytes. Available are " << fManager->Segment().get_free_memory() << " bytes.";
|
||||
|
||||
{
|
||||
bipc::scoped_lock<bipc::named_mutex> lock(fShMutex);
|
||||
bipc::scoped_lock<bipc::named_mutex> lock(*fShMutex);
|
||||
|
||||
fDeviceCounter = fManager->Segment().find<DeviceCounter>(bipc::unique_instance).first;
|
||||
if (fDeviceCounter)
|
||||
|
@ -121,6 +126,12 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
|
|||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
}
|
||||
}
|
||||
catch(bipc::interprocess_exception& e)
|
||||
{
|
||||
LOG(ERROR) << "Could not initialize shared memory transport: " << e.what();
|
||||
throw runtime_error("Cannot update configuration. Socket method (bind/connect) not specified.");
|
||||
}
|
||||
|
||||
fSendHeartbeats = true;
|
||||
fHeartbeatThread = thread(&FairMQTransportFactorySHM::SendHeartbeats, this);
|
||||
|
@ -267,7 +278,7 @@ FairMQTransportFactorySHM::~FairMQTransportFactorySHM()
|
|||
bool lastRemoved = false;
|
||||
|
||||
{ // mutex scope
|
||||
bipc::scoped_lock<bipc::named_mutex> lock(fShMutex);
|
||||
bipc::scoped_lock<bipc::named_mutex> lock(*fShMutex);
|
||||
|
||||
(fDeviceCounter->fCount)--;
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class FairMQTransportFactorySHM : public FairMQTransportFactory
|
|||
void* fHeartbeatSocket;
|
||||
std::thread fHeartbeatThread;
|
||||
std::atomic<bool> fSendHeartbeats;
|
||||
boost::interprocess::named_mutex fShMutex;
|
||||
std::unique_ptr<boost::interprocess::named_mutex> fShMutex;
|
||||
fair::mq::shmem::DeviceCounter* fDeviceCounter;
|
||||
std::unique_ptr<fair::mq::shmem::Manager> fManager;
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
@ -19,13 +20,15 @@ using namespace fair::mq::test;
|
|||
|
||||
auto RunPoller(string transport, int pollType) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto pollout = execute_result{"", 0};
|
||||
thread poll_out_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice
|
||||
<< " --id pollout_"<< transport
|
||||
<< " --control static --verbosity DEBUG --log-color false"
|
||||
<< " --mq-config \"" << mqConfig << "\"";
|
||||
<< " --session " << session << " --mq-config \"" << mqConfig << "\"";
|
||||
pollout = execute(cmd.str(), "[POLLOUT]");
|
||||
});
|
||||
|
||||
|
@ -35,7 +38,7 @@ auto RunPoller(string transport, int pollType) -> void
|
|||
cmd << runTestDevice
|
||||
<< " --id pollin_" << transport
|
||||
<< " --control static --verbosity DEBUG --log-color false"
|
||||
<< " --mq-config \"" << mqConfig << "\" --poll-type " << pollType;
|
||||
<< " --session " << session << " --mq-config \"" << mqConfig << "\" --poll-type " << pollType;
|
||||
pollin = execute(cmd.str(), "[POLLIN]");
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
@ -19,11 +20,13 @@ using namespace fair::mq::test;
|
|||
|
||||
auto RunPubSub(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto pub = execute_result{"", 0};
|
||||
thread pub_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id pub_" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
pub = execute(cmd.str(), "[PUB]");
|
||||
});
|
||||
|
||||
|
@ -31,7 +34,7 @@ auto RunPubSub(string transport) -> void
|
|||
thread sub1_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id sub_1" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
sub1 = execute(cmd.str(), "[SUB1]");
|
||||
});
|
||||
|
||||
|
@ -39,7 +42,7 @@ auto RunPubSub(string transport) -> void
|
|||
thread sub2_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id sub_2" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
sub2 = execute(cmd.str(), "[SUB2]");
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
@ -19,11 +20,13 @@ using namespace fair::mq::test;
|
|||
|
||||
auto RunPushPull(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto push = execute_result{"", 100};
|
||||
thread push_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id push_" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
push = execute(cmd.str(), "[PUSH]");
|
||||
});
|
||||
|
||||
|
@ -31,7 +34,7 @@ auto RunPushPull(string transport) -> void
|
|||
thread pull_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id pull_" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
pull = execute(cmd.str(), "[PULL]");
|
||||
});
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include <FairMQParts.h>
|
||||
#include <FairMQLogger.h>
|
||||
#include <FairMQTransportFactory.h>
|
||||
#include <fairmq/Tools.h>
|
||||
#include <options/FairMQProgOptions.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
@ -23,7 +26,14 @@ namespace
|
|||
using namespace std;
|
||||
|
||||
auto RunSingleThreadedMultipart(string transport, string address) -> void {
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport);
|
||||
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
FairMQProgOptions config;
|
||||
config.SetValue<string>("session", std::to_string(session));
|
||||
config.SetValue<int>("io-threads", 1);
|
||||
config.SetValue<size_t>("shm-segment-size", 20000000);
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
|
||||
auto push = FairMQChannel{"Push", "push", factory};
|
||||
ASSERT_TRUE(push.Bind(address));
|
||||
auto pull = FairMQChannel{"Pull", "pull", factory};
|
||||
|
@ -55,7 +65,13 @@ auto RunSingleThreadedMultipart(string transport, string address) -> void {
|
|||
|
||||
auto RunMultiThreadedMultipart(string transport, string address) -> void
|
||||
{
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport);
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
FairMQProgOptions config;
|
||||
config.SetValue<string>("session", std::to_string(session));
|
||||
config.SetValue<int>("io-threads", 1);
|
||||
config.SetValue<size_t>("shm-segment-size", 20000000);
|
||||
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
|
||||
auto push = FairMQChannel{"Push", "push", factory};
|
||||
ASSERT_TRUE(push.Bind(address));
|
||||
auto pull = FairMQChannel{"Pull", "pull", factory};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
#include <thread>
|
||||
|
@ -19,11 +20,13 @@ using namespace fair::mq::test;
|
|||
|
||||
auto RunReqRep(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
|
||||
auto rep = execute_result{ "", 0 };
|
||||
thread rep_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id rep_" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
rep = execute(cmd.str(), "[REP]");
|
||||
});
|
||||
|
||||
|
@ -31,7 +34,7 @@ auto RunReqRep(string transport) -> void
|
|||
thread req1_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id req_1" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
req1 = execute(cmd.str(), "[REQ1]");
|
||||
});
|
||||
|
||||
|
@ -39,7 +42,7 @@ auto RunReqRep(string transport) -> void
|
|||
thread req2_thread([&]() {
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id req_2" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
req2 = execute(cmd.str(), "[REQ2]");
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "runner.h"
|
||||
#include <fairmq/Tools.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream> // std::stringstream
|
||||
|
||||
|
@ -18,9 +19,10 @@ using namespace fair::mq::test;
|
|||
|
||||
auto RunTransferTimeout(string transport) -> void
|
||||
{
|
||||
size_t session{fair::mq::tools::UuidHash()};
|
||||
stringstream cmd;
|
||||
cmd << runTestDevice << " --id transfer_timeout_" << transport << " --control static --verbosity DEBUG "
|
||||
<< "--log-color false --mq-config \"" << mqConfig << "\"";
|
||||
<< "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
|
||||
auto res = execute(cmd.str());
|
||||
|
||||
cerr << res.error_out;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <fairmq/tools/Network.h>
|
||||
#include <fairmq/tools/Strings.h>
|
||||
#include <fairmq/tools/Version.h>
|
||||
#include <fairmq/tools/Unique.h>
|
||||
|
||||
namespace FairMQ
|
||||
{
|
||||
|
@ -22,6 +23,9 @@ using fair::mq::tools::getDefaultRouteNetworkInterface;
|
|||
|
||||
using fair::mq::tools::S;
|
||||
|
||||
using fair::mq::tools::Uuid;
|
||||
using fair::mq::tools::UuidHash;
|
||||
|
||||
using fair::mq::tools::Version;
|
||||
|
||||
} // namespace tools
|
||||
|
|
47
fairmq/tools/Unique.h
Normal file
47
fairmq/tools/Unique.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/********************************************************************************
|
||||
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIR_MQ_TOOLS_UNIQUE_H
|
||||
#define FAIR_MQ_TOOLS_UNIQUE_H
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
namespace tools
|
||||
{
|
||||
|
||||
// generates UUID string
|
||||
inline std::string Uuid()
|
||||
{
|
||||
boost::uuids::random_generator gen;
|
||||
boost::uuids::uuid u = gen();
|
||||
return boost::uuids::to_string(u);
|
||||
}
|
||||
|
||||
// generates UUID and returns its hash
|
||||
inline std::size_t UuidHash()
|
||||
{
|
||||
boost::uuids::random_generator gen;
|
||||
boost::hash<boost::uuids::uuid> uuid_hasher;
|
||||
boost::uuids::uuid u = gen();
|
||||
return uuid_hasher(u);
|
||||
}
|
||||
|
||||
} /* namespace tools */
|
||||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
#endif /* FAIR_MQ_TOOLS_UNIQUE_H */
|
Loading…
Reference in New Issue
Block a user