Skip to content

Commit ffb1d94

Browse files
committed
performance - read only pool POC
Signed-off-by: Amit Prinz Setter <alphaprinz@gmail.com>
1 parent 5374f8a commit ffb1d94

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/util/postgres_client.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,10 @@ class PostgresTable {
626626
}
627627

628628

629-
get_pool() {
630-
const pool = this.client.get_pool(this.pool_key);
629+
get_pool(key = this.pool_key) {
630+
const pool = this.client.get_pool(key);
631631
if (!pool) {
632-
throw new Error(`The postgres clients pool ${this.pool_key} disconnected`);
632+
throw new Error(`The postgres clients pool ${key} disconnected`);
633633
}
634634
return pool;
635635
}
@@ -1494,6 +1494,10 @@ class PostgresClient extends EventEmitter {
14941494
md: {
14951495
instance: null,
14961496
size: config.POSTGRES_MD_MAX_CLIENTS
1497+
},
1498+
read_only: {
1499+
instance: null,
1500+
size: config.POSTGRES_DEFAULT_MAX_CLIENTS
14971501
}
14981502
};
14991503

@@ -1507,6 +1511,7 @@ class PostgresClient extends EventEmitter {
15071511
} else {
15081512
// get the connection configuration. first from env, then from file, then default
15091513
const host = process.env.POSTGRES_HOST || fs_utils.try_read_file_sync(process.env.POSTGRES_HOST_PATH) || '127.0.0.1';
1514+
const host_ro = process.env.POSTGRES_HOST_RO || fs_utils.try_read_file_sync(process.env.POSTGRES_HOST_RO_PATH);
15101515
const user = process.env.POSTGRES_USER || fs_utils.try_read_file_sync(process.env.POSTGRES_USER_PATH) || 'postgres';
15111516
const password = process.env.POSTGRES_PASSWORD || fs_utils.try_read_file_sync(process.env.POSTGRES_PASSWORD_PATH) || 'noobaa';
15121517
const database = process.env.POSTGRES_DBNAME || fs_utils.try_read_file_sync(process.env.POSTGRES_DBNAME_PATH) || 'nbcore';
@@ -1520,6 +1525,7 @@ class PostgresClient extends EventEmitter {
15201525
port,
15211526
...params,
15221527
};
1528+
this.pools.read_only.host = host_ro;
15231529
}
15241530
// As we now also support external DB we don't want to print secret user data
15251531
// so this code will mask out passwords from the printed pool params
@@ -1718,8 +1724,12 @@ class PostgresClient extends EventEmitter {
17181724
if (!pool) {
17191725
throw new Error(`create_pool: the pool ${name} is not defined in pools object`);
17201726
}
1727+
const new_pool_params = _.clone(this.new_pool_params);
1728+
if (pool.host) {
1729+
new_pool_params.host = pool.host;
1730+
}
17211731
if (!pool.instance) {
1722-
pool.instance = new Pool({ ...this.new_pool_params, max: pool.size });
1732+
pool.instance = new Pool({ ...new_pool_params, max: pool.size });
17231733
if (!pool._error_listener) {
17241734
pool.error_listener = err => {
17251735
dbg.error(`got error on postgres pool ${name}`, err);

0 commit comments

Comments
 (0)