update backend stuck/stall
This commit is contained in:
@@ -14,7 +14,7 @@ const poolConfig: PoolConfig = {
|
||||
database: environment.database.name,
|
||||
user: environment.database.user,
|
||||
password: environment.database.password,
|
||||
max: 20, // Maximum number of clients in the pool
|
||||
max: 30, // Maximum number of clients in the pool
|
||||
idleTimeoutMillis: 30000, // Close idle clients after 30 seconds
|
||||
connectionTimeoutMillis: 5000, // Return an error if connection takes longer than 5 seconds
|
||||
};
|
||||
@@ -26,6 +26,17 @@ pool.on('error', (err) => {
|
||||
logger.error('Unexpected error on idle database client', err);
|
||||
});
|
||||
|
||||
// Log pool exhaustion warnings every 60s (only when requests are waiting)
|
||||
setInterval(() => {
|
||||
if (pool.waitingCount > 0) {
|
||||
logger.warn('DB pool pressure detected', {
|
||||
total: pool.totalCount,
|
||||
idle: pool.idleCount,
|
||||
waiting: pool.waitingCount,
|
||||
});
|
||||
}
|
||||
}, 60_000).unref();
|
||||
|
||||
// Test database connection
|
||||
export const testConnection = async (): Promise<boolean> => {
|
||||
try {
|
||||
|
||||
11
backend/src/config/httpClient.ts
Normal file
11
backend/src/config/httpClient.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import axios from 'axios';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
|
||||
const httpClient = axios.create({
|
||||
timeout: 10_000,
|
||||
httpAgent: new http.Agent({ keepAlive: true, maxSockets: 20 }),
|
||||
httpsAgent: new https.Agent({ keepAlive: true, maxSockets: 20 }),
|
||||
});
|
||||
|
||||
export default httpClient;
|
||||
Reference in New Issue
Block a user