make job queue size configurable

pull/929/head
Jeff Becker 5 years ago
parent 853108ce6e
commit dd48b149ca
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -51,6 +51,15 @@ namespace llarp
void void
RouterConfig::fromSection(string_view key, string_view val) RouterConfig::fromSection(string_view key, string_view val)
{ {
if(key == "job-queue-size")
{
auto sval = svtoi(val);
if(sval >= 1024)
{
m_JobQueueSize = sval;
LogInfo("Set job queue size to ", m_JobQueueSize);
}
}
if(key == "default-protocol") if(key == "default-protocol")
{ {
m_DefaultLinkProto = tostr(val); m_DefaultLinkProto = tostr(val);

@ -121,10 +121,13 @@ namespace llarp
int m_workerThreads = 1; int m_workerThreads = 1;
int m_numNetThreads = 1; int m_numNetThreads = 1;
size_t m_JobQueueSize = size_t{1024 * 8};
std::string m_DefaultLinkProto = "iwp"; std::string m_DefaultLinkProto = "iwp";
public: public:
// clang-format off // clang-format off
size_t jobQueueSize() const { return fromEnv(m_JobQueueSize, "JOB_QUEUE_SIZE"); }
size_t minConnectedRouters() const { return fromEnv(m_minConnectedRouters, "MIN_CONNECTED_ROUTERS"); } size_t minConnectedRouters() const { return fromEnv(m_minConnectedRouters, "MIN_CONNECTED_ROUTERS"); }
size_t maxConnectedRouters() const { return fromEnv(m_maxConnectedRouters, "MAX_CONNECTED_ROUTERS"); } size_t maxConnectedRouters() const { return fromEnv(m_maxConnectedRouters, "MAX_CONNECTED_ROUTERS"); }
std::string encryptionKeyfile() const { return fromEnv(m_encryptionKeyfile, "ENCRYPTION_KEYFILE"); } std::string encryptionKeyfile() const { return fromEnv(m_encryptionKeyfile, "ENCRYPTION_KEYFILE"); }

@ -51,7 +51,6 @@ namespace llarp
bool bool
Context::Configure() Context::Configure()
{ {
logic = std::make_shared< Logic >();
// llarp::LogInfo("loading config at ", configfile); // llarp::LogInfo("loading config at ", configfile);
if(configfile.size()) if(configfile.size())
{ {
@ -73,6 +72,10 @@ namespace llarp
threads = 1; threads = 1;
worker = std::make_shared< llarp::thread::ThreadPool >(threads, 1024, worker = std::make_shared< llarp::thread::ThreadPool >(threads, 1024,
"llarp-worker"); "llarp-worker");
auto jobQueueSize = config->router.jobQueueSize();
if(jobQueueSize < 1024)
jobQueueSize = 1024;
logic = std::make_shared< Logic >(jobQueueSize);
nodedb_dir = config->netdb.nodedbDir(); nodedb_dir = config->netdb.nodedbDir();

@ -13,8 +13,8 @@ namespace llarp
llarp_timer_tick_all_async(m_Timer, m_Thread, now); llarp_timer_tick_all_async(m_Timer, m_Thread, now);
} }
Logic::Logic() Logic::Logic(size_t sz)
: m_Thread(llarp_init_threadpool(1, "llarp-logic")) : m_Thread(llarp_init_threadpool(1, "llarp-logic", sz))
, m_Timer(llarp_init_timer()) , m_Timer(llarp_init_timer())
{ {
llarp_threadpool_start(m_Thread); llarp_threadpool_start(m_Thread);

@ -11,7 +11,7 @@ namespace llarp
class Logic class Logic
{ {
public: public:
Logic(); Logic(size_t queueLength = size_t{1024 * 8});
~Logic(); ~Logic();

@ -8,11 +8,11 @@
#include <queue> #include <queue>
struct llarp_threadpool * struct llarp_threadpool *
llarp_init_threadpool(int workers, const char *name) llarp_init_threadpool(int workers, const char *name, size_t queueLength)
{ {
if(workers <= 0) if(workers <= 0)
workers = 1; workers = 1;
return new llarp_threadpool(workers, name); return new llarp_threadpool(workers, name, queueLength);
} }
void void

@ -48,7 +48,7 @@ struct llarp_threadpool
#endif #endif
struct llarp_threadpool * struct llarp_threadpool *
llarp_init_threadpool(int workers, const char *name); llarp_init_threadpool(int workers, const char *name, size_t queueLength);
void void
llarp_free_threadpool(struct llarp_threadpool **tp); llarp_free_threadpool(struct llarp_threadpool **tp);

Loading…
Cancel
Save