Skip to content

Commit

Permalink
stream-info-service: Avoid creating indexes and reduce pool size
Browse files Browse the repository at this point in the history
Realized that every stream-info-service is trying to create all
the DB tables and indexes on startup. Theoretically they return
quickly as they already exist, but it still means we open up to
10 connections from each instance everytime a broadcaster pod
starts (or the stream-info restarts).

This is hopefully what's been causing connection issues with Postgres
just now.
  • Loading branch information
victorges committed Oct 9, 2024
1 parent d25ae47 commit 5171923
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
11 changes: 11 additions & 0 deletions packages/api/src/app/stream-info/parse-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ export function parseCli() {
type: "string",
demandOption: true,
},
"postgres-create-tables": {
describe:
"create tables and indexes on the database if they don't exist",
type: "boolean",
default: false,
},
"postgres-conn-pool-size": {
describe: "size of the postgres connection pool",
type: "number",
default: 5,
},
})
.help()
.parse();
Expand Down
29 changes: 21 additions & 8 deletions packages/api/src/app/stream-info/stream-info-app.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import express, { Router } from "express";
import "express-async-errors"; // it monkeypatches, i guess
import morgan from "morgan";
import { db } from "../../store";
import { healthCheck } from "../../middleware";
import logger from "../../logger";
import { Stream } from "../../schema/types";
import fetch from "node-fetch";
import { hostname } from "os";
import logger from "../../logger";
import { healthCheck } from "../../middleware";
import { Stream } from "../../schema/types";
import { db } from "../../store";

import { DBStream } from "../../store/stream-table";
import {
StatusResponse,
MasterPlaylist,
MasterPlaylistDictionary,
StatusResponse,
} from "./livepeer-types";
import { DBStream } from "../../store/stream-table";
import { CliArgs } from "./parse-cli";

const pollInterval = 2 * 1000; // 2s
Expand Down Expand Up @@ -377,9 +377,22 @@ class statusPoller {
}

export default async function makeApp(params: CliArgs) {
const { port, postgresUrl, ownRegion, listen = true, broadcaster } = params;
const {
port,
postgresUrl,
ownRegion,
listen = true,
broadcaster,
postgresCreateTables,
postgresConnPoolSize,
} = params;
// Storage init
await db.start({ postgresUrl, appName: "stream-info" });
await db.start({
postgresUrl,
appName: "stream-info",
createTablesOnDb: postgresCreateTables,
poolMaxSize: postgresConnPoolSize,
});

const { router } = await makeRouter(params);
const app = express();
Expand Down

0 comments on commit 5171923

Please sign in to comment.