Made connection count aligned with thread count
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
namespace Database {
|
namespace Database {
|
||||||
|
|
||||||
// Session living class handling the database and the login
|
// Session living class handling the database and the login
|
||||||
Db::Db(const std::filesystem::path& dbPath)
|
Db::Db(const std::filesystem::path& dbPath, std::size_t connectionCount)
|
||||||
{
|
{
|
||||||
LMS_LOG(DB, INFO) << "Creating connection pool on file " << dbPath.string();
|
LMS_LOG(DB, INFO) << "Creating connection pool on file " << dbPath.string();
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ Db::Db(const std::filesystem::path& dbPath)
|
|||||||
connection->executeSql("pragma journal_mode=WAL");
|
connection->executeSql("pragma journal_mode=WAL");
|
||||||
connection->executeSql("pragma synchronous=normal");
|
connection->executeSql("pragma synchronous=normal");
|
||||||
|
|
||||||
auto connectionPool = std::make_unique<Wt::Dbo::FixedSqlConnectionPool>(std::move(connection), 10);
|
auto connectionPool = std::make_unique<Wt::Dbo::FixedSqlConnectionPool>(std::move(connection), connectionCount);
|
||||||
connectionPool->setTimeout(std::chrono::seconds(10));
|
connectionPool->setTimeout(std::chrono::seconds(10));
|
||||||
|
|
||||||
_connectionPool = std::move(connectionPool);
|
_connectionPool = std::move(connectionPool);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Db
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Db(const std::filesystem::path& dbPath);
|
Db(const std::filesystem::path& dbPath, std::size_t connectionCount = 10);
|
||||||
~Db();
|
~Db();
|
||||||
|
|
||||||
Db(const Db&) = delete;
|
Db(const Db&) = delete;
|
||||||
|
|||||||
+12
-7
@@ -44,6 +44,16 @@
|
|||||||
#include "utils/String.hpp"
|
#include "utils/String.hpp"
|
||||||
#include "utils/WtLogger.hpp"
|
#include "utils/WtLogger.hpp"
|
||||||
|
|
||||||
|
static
|
||||||
|
std::size_t
|
||||||
|
getThreadCount()
|
||||||
|
{
|
||||||
|
const unsigned long configHttpServerThreadCount {Service<IConfig>::get()->getULong("http-server-thread-count", 0)};
|
||||||
|
|
||||||
|
// Reserve at least 2 threads since we still have some blocking IO (for example when reading from ffmpeg)
|
||||||
|
return configHttpServerThreadCount ? configHttpServerThreadCount : std::max<unsigned long>(2, std::thread::hardware_concurrency());
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
generateWtConfig(std::string execPath)
|
generateWtConfig(std::string execPath)
|
||||||
@@ -54,7 +64,6 @@ generateWtConfig(std::string execPath)
|
|||||||
const std::filesystem::path wtLogFilePath {Service<IConfig>::get()->getPath("log-file", "/var/log/lms.log")};
|
const std::filesystem::path wtLogFilePath {Service<IConfig>::get()->getPath("log-file", "/var/log/lms.log")};
|
||||||
const std::filesystem::path wtAccessLogFilePath {Service<IConfig>::get()->getPath("access-log-file", "/var/log/lms.access.log")};
|
const std::filesystem::path wtAccessLogFilePath {Service<IConfig>::get()->getPath("access-log-file", "/var/log/lms.access.log")};
|
||||||
const std::filesystem::path wtResourcesPath {Service<IConfig>::get()->getPath("wt-resources", "/usr/share/Wt/resources")};
|
const std::filesystem::path wtResourcesPath {Service<IConfig>::get()->getPath("wt-resources", "/usr/share/Wt/resources")};
|
||||||
const unsigned long configHttpServerThreadCount {Service<IConfig>::get()->getULong("http-server-thread-count", 0)};
|
|
||||||
|
|
||||||
args.push_back(execPath);
|
args.push_back(execPath);
|
||||||
args.push_back("--config=" + wtConfigPath.string());
|
args.push_back("--config=" + wtConfigPath.string());
|
||||||
@@ -81,11 +90,7 @@ generateWtConfig(std::string execPath)
|
|||||||
if (!wtAccessLogFilePath.empty())
|
if (!wtAccessLogFilePath.empty())
|
||||||
args.push_back("--accesslog=" + wtAccessLogFilePath.string());
|
args.push_back("--accesslog=" + wtAccessLogFilePath.string());
|
||||||
|
|
||||||
{
|
args.push_back("--threads=" + std::to_string(getThreadCount()));
|
||||||
// Reserve at least 2 threads since we still have some blocking IO (for example when reading from ffmpeg)
|
|
||||||
const unsigned long httpServerThreadCount {configHttpServerThreadCount ? configHttpServerThreadCount : std::max<unsigned long>(2, std::thread::hardware_concurrency())};
|
|
||||||
args.push_back("--threads=" + std::to_string(httpServerThreadCount));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate the wt_config.xml file
|
// Generate the wt_config.xml file
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
@@ -221,7 +226,7 @@ int main(int argc, char* argv[])
|
|||||||
IOContextRunner ioContextRunner {ioContext, std::max<unsigned long>(2, std::thread::hardware_concurrency())};
|
IOContextRunner ioContextRunner {ioContext, std::max<unsigned long>(2, std::thread::hardware_concurrency())};
|
||||||
|
|
||||||
// Initializing a connection pool to the database that will be shared along services
|
// Initializing a connection pool to the database that will be shared along services
|
||||||
Database::Db database {config->getPath("working-dir") / "lms.db"};
|
Database::Db database {config->getPath("working-dir") / "lms.db", getThreadCount()};
|
||||||
{
|
{
|
||||||
Database::Session session {database};
|
Database::Session session {database};
|
||||||
session.prepareTables();
|
session.prepareTables();
|
||||||
|
|||||||
Reference in New Issue
Block a user