Skip to content

Commit

Permalink
perf: fix windows cpu 100% usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor333Huesca authored and MauriceNino committed Jan 6, 2024
1 parent 9651122 commit 9c23e93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CONFIG } from './config';
import getNetworkInfo from './data/network';
import { getDynamicServerInfo } from './dynamic-info';
import { environment } from './environments/environment';
import { setupNetworking, setupOsVersion } from './setup';
import { setupNetworking, setupOsVersion, setupHostSpecific, tearDownHostSpecific } from './setup';
import {
getStaticServerInfo,
getStaticServerInfoObs,
Expand Down Expand Up @@ -91,6 +91,7 @@ if (!CONFIG.disable_integrations) {
server.listen(CONFIG.port, async () => {
console.log('listening on *:' + CONFIG.port);

await setupHostSpecific();
await setupNetworking();
await setupOsVersion();
await loadStaticServerInfo();
Expand Down Expand Up @@ -190,10 +191,12 @@ server.on('error', console.error);

process.on('uncaughtException', e => {
console.error(e);
tearDownHostSpecific();
process.exit(1);
});

process.on('unhandledRejection', e => {
console.error(e);
tearDownHostSpecific();
process.exit(1);
});
16 changes: 16 additions & 0 deletions apps/server/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { exec as exaca } from 'child_process';
import * as fs from 'fs';
import * as si from 'systeminformation';
import { promisify } from 'util';
import { CONFIG } from './config';
import { platformIsWindows } from './utils';

const exec = promisify(exaca);

Expand Down Expand Up @@ -100,3 +102,17 @@ export const setupOsVersion = async () => {
console.warn(e);
}
};

export const setupHostSpecific = async () => {
if (platformIsWindows) {
console.log('Acquiring Windows Persistent Powershell')
si.powerShellStart()
}
};

export const tearDownHostSpecific = () => {
if (platformIsWindows) {
console.log('Releasing Windows Persistent Powershell')
si.powerShellRelease()
}
};

0 comments on commit 9c23e93

Please sign in to comment.