Kevac Marko (mkevac) wrote,
Kevac Marko
mkevac

Apache mod_dbd and more than one connection pool

Apache mod_dbd and more than one connection pool



Introduction


Apache mod_dbd is a module for popular web server Apache HTTPD, which provides connection pooling to popular RDBMs for other modules. mod_dbd can provide only one connection pool per server (virtual server).

This article will explain how multiple pools per server capability was implemented and how it works.
Patch and testing module is in bug.

Configuration



mod_dbd configuration looks like this:
       DBDriver mysql
       DBDParams "host=172.20.30.65, port=..."
       DBDPersist On


In order to provide multiple pools capability, container was introduces, so configuration now looks like this:

    <DBDPool "marko1">
        DBDriver mysql
        DBDParams "host=172.20.30.65, port=..."
        DBDPersist On
    </DBDPool>

    <DBDPool "marko2">
        DBDriver mysql
        DBDParams "host=172.20.30.65, port=..."
        DBDPersist On
    </DBDPool>


In order to maintain compability, one can still configure pool without container, in which case this pool will have default name.


API



mod_dbd had this functions defined:

ap_dbd_open(apr_pool_t*, server_rec*);
ap_dbd_close(server_rec*, ap_dbd_t*);
ap_dbd_acquire(request_rec*);
ap_dbd_cacquire(conn_rec*);
ap_dbd_prepare(server_rec*, const char*, const char*);


Now all these functions have siblings with pool_name variable:

ap_dbd_open_pool(apr_pool_t*, server_rec*, const char*);
ap_dbd_close_pool(server_rec*, ap_dbd_t*, const char*);
ap_dbd_acquire_pool(request_rec*, const char*);
ap_dbd_cacquire_pool(conn_rec*, const char*);
ap_dbd_prepare_pool(server_rec*, const char*, const char*, const char*);


When old functions are used, pool with default pool name will be used. For named pools, one must use new functions.

Internal implementation



Module config



Module configuration structure svr_cfg, which enabled only one pool

 typedef struct {
     dbd_cfg_t *cfg;
     dbd_group_t *group;
 } svr_cfg;


was changed to hash of structures dbd_pool_t:

 typedef struct {
     dbd_cfg_t *cfg;
     dbd_group_t *group;
 } dbd_pool_t;

 typedef struct {
     apr_hash_t *pools; /* hash of dbd_pool_t structures */
 } svr_cfg;


New functions



Each of old functions without '_pool' is just wrapper to '_pool' functions. For example:

 DBD_DECLARE_NONSTD(void) ap_dbd_prepare(server_rec *s, const char *query,
                                         const char *label)
 {
     ap_dbd_prepare_pool(s, DBD_DEFAULT_POOL_NAME, query, label);
 }
Tags: apache, devel, opensource
Subscribe

  • Apache Portable Runtime binding for Lua

    На работе я частенько пишу модули для Apache HTTP Server и, соответственно, использую APR библиотеку. А еще в одном из модулей я сделал возможность…

  • real software engineering

    Потрясающее выступление на тему различия software engineering и других типов engineering. Как автора водопадной модели никто не понял и как нужно…

  • Erlang и node.js - сравнение

    Интересный диалог со сравнением Erlang и node.js. Не знаю ни того, ни другого. Erlang пока все еще в процессе изучения. levgem как…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments