Only check request time for readiness if cache has filled up

This commit is contained in:
Ajay 2024-04-21 13:38:32 -04:00
parent 063607fe30
commit 47ea6ae8d3
3 changed files with 9 additions and 4 deletions

View file

@ -194,7 +194,8 @@ addDefaults(config, {
deArrowPaywall: false,
useCacheForSegmentGroups: false,
maxConnections: 100,
maxResponseTime: 1000
maxResponseTime: 1000,
maxResponseTimeWhileLoadingCache: 2000
});
loadFromEnv(config);
migrate(config);

View file

@ -14,9 +14,11 @@ export async function getReady(req: Request, res: Response, server: Server): Pro
if (!connections
|| (connections < config.maxConnections
&& (!config.redis || redisStats.activeRequests < config.redis.maxConnections * 0.8)
&& (!config.redis || redisStats.avgReadTime < config.maxResponseTime || redisStats.activeRequests < 1)
&& (!config.postgres || postgresStats.activeRequests < config.postgres.maxActiveRequests * 0.8))
&& (!config.postgres || postgresStats.avgReadTime < config.maxResponseTime)) {
&& (!config.redis || redisStats.activeRequests < 1 || redisStats.avgReadTime < config.maxResponseTime
|| (redisStats.memoryCacheSize < config.redis.clientCacheSize * 0.8 && redisStats.avgReadTime < config.maxResponseTimeWhileLoadingCache))
&& (!config.postgres || postgresStats.activeRequests < config.postgres.maxActiveRequests * 0.8)
&& (!config.postgres || postgresStats.avgReadTime < config.maxResponseTime
|| (redisStats.memoryCacheSize < config.redis.clientCacheSize * 0.8 && postgresStats.avgReadTime < config.maxResponseTimeWhileLoadingCache)))) {
return res.sendStatus(200);
} else {
return res.sendStatus(500);

View file

@ -107,6 +107,8 @@ export interface SBSConfig {
deArrowPaywall: boolean,
useCacheForSegmentGroups: boolean
maxConnections: number;
maxResponseTime: number;
maxResponseTimeWhileLoadingCache: number;
}
export interface WebhookConfig {