forked from misskey-dev/misskey
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve chart performance (misskey-dev#7360)
* wip * wip * wip * wip * wip * Update chart.ts * wip * Improve server performance * wip * wip
- Loading branch information
Showing
32 changed files
with
891 additions
and
163 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class chartV221615966519402 implements MigrationInterface { | ||
name = 'chartV221615966519402' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "__chart__active_users" ADD "___local_users" character varying array NOT NULL DEFAULT '{}'::varchar[]`); | ||
await queryRunner.query(`ALTER TABLE "__chart__active_users" ADD "___remote_users" character varying array NOT NULL DEFAULT '{}'::varchar[]`); | ||
await queryRunner.query(`ALTER TABLE "__chart__hashtag" ADD "___local_users" character varying array NOT NULL DEFAULT '{}'::varchar[]`); | ||
await queryRunner.query(`ALTER TABLE "__chart__hashtag" ADD "___remote_users" character varying array NOT NULL DEFAULT '{}'::varchar[]`); | ||
await queryRunner.query(`ALTER TABLE "__chart__test_unique" ADD "___foo" character varying array NOT NULL DEFAULT '{}'::varchar[]`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "__chart__test_unique" DROP COLUMN "___foo"`); | ||
await queryRunner.query(`ALTER TABLE "__chart__hashtag" DROP COLUMN "___remote_users"`); | ||
await queryRunner.query(`ALTER TABLE "__chart__hashtag" DROP COLUMN "___local_users"`); | ||
await queryRunner.query(`ALTER TABLE "__chart__active_users" DROP COLUMN "___remote_users"`); | ||
await queryRunner.query(`ALTER TABLE "__chart__active_users" DROP COLUMN "___local_users"`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type FIXME = any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// https://gist.github.com/nfantone/1eaa803772025df69d07f4dbf5df7e58 | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @callback BeforeShutdownListener | ||
* @param {string} [signalOrEvent] The exit signal or event name received on the process. | ||
*/ | ||
|
||
/** | ||
* System signals the app will listen to initiate shutdown. | ||
* @const {string[]} | ||
*/ | ||
const SHUTDOWN_SIGNALS = ['SIGINT', 'SIGTERM']; | ||
|
||
/** | ||
* Time in milliseconds to wait before forcing shutdown. | ||
* @const {number} | ||
*/ | ||
const SHUTDOWN_TIMEOUT = 15000; | ||
|
||
/** | ||
* A queue of listener callbacks to execute before shutting | ||
* down the process. | ||
* @type {BeforeShutdownListener[]} | ||
*/ | ||
const shutdownListeners = []; | ||
|
||
/** | ||
* Listen for signals and execute given `fn` function once. | ||
* @param {string[]} signals System signals to listen to. | ||
* @param {function(string)} fn Function to execute on shutdown. | ||
*/ | ||
const processOnce = (signals, fn) => { | ||
return signals.forEach(sig => process.once(sig, fn)); | ||
}; | ||
|
||
/** | ||
* Sets a forced shutdown mechanism that will exit the process after `timeout` milliseconds. | ||
* @param {number} timeout Time to wait before forcing shutdown (milliseconds) | ||
*/ | ||
const forceExitAfter = timeout => () => { | ||
setTimeout(() => { | ||
// Force shutdown after timeout | ||
console.warn(`Could not close resources gracefully after ${timeout}ms: forcing shutdown`); | ||
return process.exit(1); | ||
}, timeout).unref(); | ||
}; | ||
|
||
/** | ||
* Main process shutdown handler. Will invoke every previously registered async shutdown listener | ||
* in the queue and exit with a code of `0`. Any `Promise` rejections from any listener will | ||
* be logged out as a warning, but won't prevent other callbacks from executing. | ||
* @param {string} signalOrEvent The exit signal or event name received on the process. | ||
*/ | ||
async function shutdownHandler(signalOrEvent) { | ||
console.warn(`Shutting down: received [${signalOrEvent}] signal`); | ||
|
||
for (const listener of shutdownListeners) { | ||
try { | ||
await listener(signalOrEvent); | ||
} catch (err) { | ||
console.warn(`A shutdown handler failed before completing with: ${err.message || err}`); | ||
} | ||
} | ||
|
||
return process.exit(0); | ||
} | ||
|
||
/** | ||
* Registers a new shutdown listener to be invoked before exiting | ||
* the main process. Listener handlers are guaranteed to be called in the order | ||
* they were registered. | ||
* @param {BeforeShutdownListener} listener The shutdown listener to register. | ||
* @returns {BeforeShutdownListener} Echoes back the supplied `listener`. | ||
*/ | ||
export function beforeShutdown(listener) { | ||
shutdownListeners.push(listener); | ||
return listener; | ||
} | ||
|
||
// Register shutdown callback that kills the process after `SHUTDOWN_TIMEOUT` milliseconds | ||
// This prevents custom shutdown handlers from hanging the process indefinitely | ||
processOnce(SHUTDOWN_SIGNALS, forceExitAfter(SHUTDOWN_TIMEOUT)); | ||
|
||
// Register process shutdown callback | ||
// Will listen to incoming signal events and execute all registered handlers in the stack | ||
processOnce(SHUTDOWN_SIGNALS, shutdownHandler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as Queue from 'bull'; | ||
import config from '../config'; | ||
|
||
export function initialize(name: string, limitPerSec = -1) { | ||
return new Queue(name, { | ||
redis: { | ||
port: config.redis.port, | ||
host: config.redis.host, | ||
password: config.redis.pass, | ||
db: config.redis.db || 0, | ||
}, | ||
prefix: config.redis.prefix ? `${config.redis.prefix}:queue` : 'queue', | ||
limiter: limitPerSec > 0 ? { | ||
max: limitPerSec * 5, | ||
duration: 5000 | ||
} : undefined | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import config from '../config'; | ||
import { initialize as initializeQueue } from './initialize'; | ||
|
||
export const deliverQueue = initializeQueue('deliver', config.deliverJobPerSec || 128); | ||
export const inboxQueue = initializeQueue('inbox', config.inboxJobPerSec || 16); | ||
export const dbQueue = initializeQueue('db'); | ||
export const objectStorageQueue = initializeQueue('objectStorage'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.