aboutsummaryrefslogtreecommitdiff
path: root/brep
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-03-19 15:10:50 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-03-19 19:58:33 +0300
commitf9d6c62ec593ec743a4ec9b25d7614606d27d4fa (patch)
tree1b00a70f0f74bc3d82d7190b20cf59fb355b0fa0 /brep
parent45aec70e4b577aaec17720b6082fe6b8ad0e243f (diff)
Use connection_pool_factory in brep module
Diffstat (limited to 'brep')
-rw-r--r--brep/database.cxx15
-rw-r--r--brep/options.cli7
2 files changed, 17 insertions, 5 deletions
diff --git a/brep/database.cxx b/brep/database.cxx
index 1f70881..4b56c37 100644
--- a/brep/database.cxx
+++ b/brep/database.cxx
@@ -7,6 +7,7 @@
#include <map>
#include <odb/pgsql/database.hxx>
+#include <odb/pgsql/connection-factory.hxx>
namespace brep
{
@@ -26,11 +27,11 @@ namespace brep
}
}
- shared_ptr<odb::database>
+ using namespace odb;
+
+ shared_ptr<database>
shared_database (const options::db& o)
{
- using odb::pgsql::database;
-
static std::map<options::db, weak_ptr<database>> databases;
auto i (databases.find (o));
@@ -40,14 +41,18 @@ namespace brep
return d;
}
+ unique_ptr<pgsql::connection_factory>
+ f (new pgsql::connection_pool_factory (o.db_max_connections ()));
+
shared_ptr<database> d (
- make_shared<database> (
+ make_shared<pgsql::database> (
o.db_user (),
o.db_password (),
o.db_name (),
o.db_host (),
o.db_port (),
- "options='-c default_transaction_isolation=serializable'"));
+ "options='-c default_transaction_isolation=serializable'",
+ move (f)));
databases[o] = d;
return d;
diff --git a/brep/options.cli b/brep/options.cli
index bcb335e..d63a561 100644
--- a/brep/options.cli
+++ b/brep/options.cli
@@ -72,6 +72,13 @@ namespace brep
"Database port number. If not specified, the default port is used."
}
+ size_t db-max-connections = 5
+ {
+ "<num>",
+ "The maximum number of concurrent database connections per web server
+ process. If 0, then no limitation is applied. The default is 5."
+ }
+
size_t db-retry = 10
{
"<num>",