From f9d6c62ec593ec743a4ec9b25d7614606d27d4fa Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 19 Mar 2016 15:10:50 +0300 Subject: Use connection_pool_factory in brep module --- NEWS | 13 ++++++++++--- brep/database.cxx | 15 ++++++++++----- brep/options.cli | 7 +++++++ etc/brep-module.conf | 4 ++++ web/apache/service | 20 ++++++++++---------- web/apache/service.cxx | 8 ++++---- web/apache/service.txx | 2 +- 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index d384f21..7a788df 100644 --- a/NEWS +++ b/NEWS @@ -4,8 +4,15 @@ Version 0.3.0 Apache2 server. The configuration can be specified at the Apache2 root, VistualHost, and Location levels. - * Add support for custom web page logo and menu entries. See comments in - the etc/brep-module.conf file for details. + * Support for custom web page logo and menu entries. See comments in the + etc/brep-module.conf file for details. + + * Ability to specify the maximum number of concurrent database connections + per web server process. See comments in the etc/brep-module.conf file for + details. + + * Ability to specify the maximum number of times to retry database + transactions. See comments in the etc/brep-module.conf file for details. * Display SHA256 package checksum on the package version details pages. @@ -20,7 +27,7 @@ Version 0.3.0 * Remove a DROP FUNCTION statement that caused an error on older PostgreSQL versions. - * On startup log brep module name to Apache2 log. + * On startup log brep module version to Apache2 log. Version 0.2.2 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 #include +#include namespace brep { @@ -26,11 +27,11 @@ namespace brep } } - shared_ptr + using namespace odb; + + shared_ptr shared_database (const options::db& o) { - using odb::pgsql::database; - static std::map> databases; auto i (databases.find (o)); @@ -40,14 +41,18 @@ namespace brep return d; } + unique_ptr + f (new pgsql::connection_pool_factory (o.db_max_connections ())); + shared_ptr d ( - make_shared ( + make_shared ( 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 + { + "", + "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 { "", diff --git a/etc/brep-module.conf b/etc/brep-module.conf index 05fd278..82a21e1 100644 --- a/etc/brep-module.conf +++ b/etc/brep-module.conf @@ -49,6 +49,10 @@ menu About=?about # db-host # db-port +# The maximum number of concurrent database connections per web server +# process. If 0, then no limitation is applied. +# +# db-max-connections 5 # The maximum number of times to retry database transactions in the # face of recoverable failures (deadlock, loss of connection, etc). diff --git a/web/apache/service b/web/apache/service index c663323..b50bc13 100644 --- a/web/apache/service +++ b/web/apache/service @@ -35,10 +35,10 @@ namespace web // It then initializes each of these "context exemplars" with the (merged) // set of configuration options. Finally, when handling a request, it // copies the corresponding "context exemplar" to create the "handling - // instance". Note that the "context exemplars" are create before the - // provided exemplar is initialized. As a result, it is possible to detect - // if the module's copy constructor is used to create a "context exemplar" - // or a "handling instance". + // instance". Note that the "context exemplars" are created as a copy of + // the provided exemplar, which is never initialized. As a result, it is + // possible to detect if the module's copy constructor is used to create a + // "context exemplar" or a "handling instance". // class service: ::module { @@ -86,7 +86,7 @@ namespace web // contexts options with the ones from the enclosing servers. // // 5. Apache calls worker_initializer() which creates module exemplar - // for each directory configuration context having + // for each directory configuration context that have // 'SetHandler ' directive in effect for it. // // References: @@ -172,13 +172,13 @@ namespace web enum class request_handling { // Configuration scope has 'SetHandler ' directive - // specified. The module allowed to handle a request in the scope. + // specified. The module is allowed to handle a request in the scope. // allowed, // Configuration scope has 'SetHandler |None' - // directive specified. The module disallowed to handle a request in - // the scope. + // directive specified. The module is disallowed to handle a request + // in the scope. // disallowed, @@ -307,13 +307,13 @@ namespace web module& exemplar_; option_descriptions option_descriptions_; - // The context objects pointed by the key can change during the + // The context objects pointed to by the key can change during the // configuration phase. // using options = std::map; options options_; - // The context objects pointed by the key can not change during the + // The context objects pointed to by the key can not change during the // request handling phase. // using exemplars = std::map>; diff --git a/web/apache/service.cxx b/web/apache/service.cxx index 6679194..7104731 100644 --- a/web/apache/service.cxx +++ b/web/apache/service.cxx @@ -69,9 +69,9 @@ namespace web }; } - // Track if the module allowed to handle a request in the specific + // Track if the module is allowed to handle a request in the specific // configuration scope. The module exemplar will be created (and - // initialized) only for configuration contexts having + // initialized) only for configuration contexts that have // 'SetHandler ' in effect for the corresponding scope. // *d++ = @@ -217,8 +217,8 @@ namespace web auto i (options_.find (enclosing)); // The enclosing context may have no options. It can be the context of a - // server having no configuration directives in it's immediate scope, - // but having ones in it's enclosed scope (directory or virtual server). + // server that has no configuration directives in it's immediate scope, + // but has ones in it's enclosed scope (directory or virtual server). // if (i != options_.end ()) { diff --git a/web/apache/service.txx b/web/apache/service.txx index 2e8a3e5..e517abe 100644 --- a/web/apache/service.txx +++ b/web/apache/service.txx @@ -25,7 +25,7 @@ namespace web const M* exemplar (dynamic_cast (&exemplar_)); assert (exemplar != nullptr); - // For each directory configuration context, for which the module + // For each directory configuration context, for which the module is // allowed to handle a request, create the module exemplar as a deep // copy of the exemplar_ member, and initialize it with the // context-specific option list. -- cgit v1.1