PG-542: Performance improvement of pg_stat_monitor.
Saving the client IP address once per the lifetime of a backend. This avoid the expensive operation multiple times, and hence improving performance significantly.pull/382/head
parent
8482bcc347
commit
ccaa910c35
|
@ -1611,12 +1611,12 @@ pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info)
|
||||||
pgsmEntry *entry;
|
pgsmEntry *entry;
|
||||||
int sec_ctx;
|
int sec_ctx;
|
||||||
bool found_client_addr = false;
|
bool found_client_addr = false;
|
||||||
char app_name[APPLICATIONNAME_LEN] = "";
|
|
||||||
char *app_name_ptr = app_name;
|
char *app_name_ptr = app_name;
|
||||||
int app_name_len = 0;
|
|
||||||
MemoryContext oldctx;
|
MemoryContext oldctx;
|
||||||
char *datname = NULL;
|
char *datname = NULL;
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
|
static bool is_ip_set = false;
|
||||||
|
static uint32 ip = 0;
|
||||||
|
|
||||||
/* Create an entry in the pgsm memory context */
|
/* Create an entry in the pgsm memory context */
|
||||||
oldctx = MemoryContextSwitchTo(pgsm_get_ss()->pgsm_mem_cxt);
|
oldctx = MemoryContextSwitchTo(pgsm_get_ss()->pgsm_mem_cxt);
|
||||||
|
@ -1633,7 +1633,13 @@ pgsm_create_hash_entry(uint64 bucket_id, uint64 queryid, PlanInfo *plan_info)
|
||||||
entry->key.appid = pgsm_hash_string((const char *)app_name_ptr, app_name_len);
|
entry->key.appid = pgsm_hash_string((const char *)app_name_ptr, app_name_len);
|
||||||
|
|
||||||
/* client address */
|
/* client address */
|
||||||
entry->key.ip = pg_get_client_addr(&found_client_addr);
|
if (!is_ip_set)
|
||||||
|
{
|
||||||
|
ip = pg_get_client_addr(&found_client_addr);
|
||||||
|
is_ip_set = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->key.ip = ip;
|
||||||
|
|
||||||
/* PlanID, if there is one */
|
/* PlanID, if there is one */
|
||||||
entry->key.planid = plan_info ? plan_info->planid : 0;
|
entry->key.planid = plan_info ? plan_info->planid : 0;
|
||||||
|
|
Loading…
Reference in New Issue