Skip to content

[mysql] increase and monitor poolsize #18457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/gitpod-db/src/typeorm/typeorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class TypeORM {
namingStrategy: new DefaultNamingStrategy(),
extra: {
// default is 10 (see https://github.com/mysqljs/mysql#pool-options), which is too low for our use case
connectionLimit: 20,
connectionLimit: 40,
},
};
}
Expand Down
17 changes: 17 additions & 0 deletions components/server/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import { Container } from "inversify";
import { Server } from "./server";
import { log, LogrusLogLevel } from "@gitpod/gitpod-protocol/lib/util/logging";
import { TracingManager } from "@gitpod/gitpod-protocol/lib/util/tracing";
import { TypeORM } from "@gitpod/gitpod-db/lib";
import { dbConnectionsFree, dbConnectionsTotal } from "./prometheus-metrics";
if (process.env.NODE_ENV === "development") {
require("longjohn");
}
Expand All @@ -76,9 +78,24 @@ export async function start(container: Container) {
}
});

const interval = setInterval(async () => {
try {
const connection = await container.get(TypeORM).getConnection();
const pool: any = (connection.driver as any).pool;
const activeConnections = pool._allConnections.length;
const freeConnections = pool._freeConnections.length;

dbConnectionsTotal.set(activeConnections);
dbConnectionsFree.set(freeConnections);
} catch (error) {
log.error("Error updating TypeORM metrics", error);
}
}, 5000);

process.on("SIGTERM", async () => {
log.info("SIGTERM received, stopping");
await server.stop();
clearInterval(interval);
});

const tracing = container.get(TracingManager);
Expand Down
12 changes: 12 additions & 0 deletions components/server/src/prometheus-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@ export function registerServerMetrics(registry: prometheusClient.Registry) {
registry.registerMetric(redisUpdatesReceived);
registry.registerMetric(redisUpdatesCompletedTotal);
registry.registerMetric(updateSubscribersRegistered);
registry.registerMetric(dbConnectionsTotal);
registry.registerMetric(dbConnectionsFree);
}

export const dbConnectionsTotal = new prometheusClient.Gauge({
name: "gitpod_typeorm_total_connections",
help: "Total number of connections in TypeORM pool",
});

export const dbConnectionsFree = new prometheusClient.Gauge({
name: "gitpod_typeorm_free_connections",
help: "Number of free connections in TypeORM pool",
});

const loginCompletedTotal = new prometheusClient.Counter({
name: "gitpod_login_completed_total",
help: "Total number of logins completed into gitpod, by status",
Expand Down