mirror of https://github.com/citusdata/citus.git
Probabilistic tracking for new tenants.
parent
dc7aa52d00
commit
a8d3805bd6
|
@ -2402,7 +2402,6 @@ RegisterCitusConfigVariables(void)
|
|||
PGC_POSTMASTER,
|
||||
GUC_STANDARD,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
DefineCustomEnumVariable(
|
||||
"citus.stat_tenants_log_level",
|
||||
gettext_noop("Sets the level of citus_stat_tenants log messages"),
|
||||
|
@ -2424,6 +2423,17 @@ RegisterCitusConfigVariables(void)
|
|||
GUC_STANDARD,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
|
||||
DefineCustomIntVariable(
|
||||
"citus.stat_tenants_sample_rate_for_new_tenants",
|
||||
gettext_noop("Sampling rate for new tenants in citus_stat_tenants."),
|
||||
NULL,
|
||||
&StatTenantsSampleRateForNewTenants,
|
||||
100, 1, 100,
|
||||
PGC_USERSET,
|
||||
GUC_STANDARD,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
DefineCustomEnumVariable(
|
||||
"citus.stat_tenants_track",
|
||||
gettext_noop("Enables/Disables the stats collection for citus_stat_tenants."),
|
||||
|
|
|
@ -77,7 +77,7 @@ int StatTenantsLogLevel = CITUS_LOG_LEVEL_OFF;
|
|||
int StatTenantsPeriod = (time_t) 60;
|
||||
int StatTenantsLimit = 100;
|
||||
int StatTenantsTrack = STAT_TENANTS_TRACK_NONE;
|
||||
|
||||
int StatTenantsSampleRateForNewTenants = 100;
|
||||
|
||||
PG_FUNCTION_INFO_V1(citus_stat_tenants_local);
|
||||
PG_FUNCTION_INFO_V1(citus_stat_tenants_local_reset);
|
||||
|
@ -177,8 +177,6 @@ citus_stat_tenants_local(PG_FUNCTION_ARGS)
|
|||
}
|
||||
|
||||
|
||||
#include "miscadmin.h"
|
||||
|
||||
/*
|
||||
* citus_stat_tenants_local_reset resets monitor for tenant statistics
|
||||
* on the local node.
|
||||
|
@ -186,9 +184,6 @@ citus_stat_tenants_local(PG_FUNCTION_ARGS)
|
|||
Datum
|
||||
citus_stat_tenants_local_reset(PG_FUNCTION_ARGS)
|
||||
{
|
||||
/* ereport(NOTICE, (errmsg("MyProcPid: %d", MyProcPid))); */
|
||||
/*sleep(10); */
|
||||
|
||||
MultiTenantMonitor *monitor = GetMultiTenantMonitor();
|
||||
|
||||
/* if monitor is not created yet, there is nothing to reset */
|
||||
|
@ -268,6 +263,21 @@ AttributeTask(char *tenantId, int colocationId, CmdType commandType)
|
|||
return;
|
||||
}
|
||||
|
||||
TenantStatsHashKey key = { 0 };
|
||||
FillTenantStatsHashKey(&key, tenantId, colocationId);
|
||||
|
||||
MultiTenantMonitor *monitor = GetMultiTenantMonitor();
|
||||
bool found = false;
|
||||
hash_search(monitor->tenants, &key, HASH_FIND, NULL);
|
||||
|
||||
int randomValue = rand() % 100;
|
||||
|
||||
/* If the tenant is not found in the hash table, we will track the query with a probability of StatTenantsSampleRateForNewTenants.*/
|
||||
if (!(!found && randomValue < StatTenantsSampleRateForNewTenants))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeToColocationGroupId = colocationId;
|
||||
strncpy_s(AttributeToTenant, MAX_TENANT_ATTRIBUTE_LENGTH, tenantId,
|
||||
MAX_TENANT_ATTRIBUTE_LENGTH - 1);
|
||||
|
|
|
@ -121,5 +121,6 @@ extern int StatTenantsLogLevel;
|
|||
extern int StatTenantsPeriod;
|
||||
extern int StatTenantsLimit;
|
||||
extern int StatTenantsTrack;
|
||||
extern int StatTenantsSampleRateForNewTenants;
|
||||
|
||||
#endif /*CITUS_ATTRIBUTE_H */
|
||||
|
|
Loading…
Reference in New Issue