feat(compute-pressure) monitor cpu pressure (#13645)

pull/13641/head jitsi-meet_8876
Mihaela Dumitru 2 years ago committed by GitHub
parent ef3f20830d
commit 4461196ba3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      globals.d.ts
  2. 2
      globals.native.d.ts
  3. 13
      modules/API/API.js
  4. 1
      modules/API/external/external_api.js
  5. 1
      react/features/app/middlewares.any.ts
  6. 54
      react/features/base/app/middleware.ts
  7. 2
      webpack.config.js

2
globals.d.ts vendored

@ -19,6 +19,8 @@ declare global {
interfaceConfig?: any;
JitsiMeetJS?: any;
JitsiMeetElectron?: any;
PressureObserver?: any;
PressureRecord?: any;
// selenium tests handler
_sharedVideoPlayer: any;
alwaysOnTop: { api: any };

@ -17,6 +17,8 @@ interface IWindow {
innerWidth: number;
interfaceConfig: any;
location: ILocation;
PressureObserver?: any;
PressureRecord?: any;
self: any;
top: any;

@ -2059,6 +2059,19 @@ class API {
});
}
/**
* Notify the external application (if API is enabled) when the compute pressure changed.
*
* @param {Array} records - The new pressure records.
* @returns {void}
*/
notifyComputePressureChanged(records) {
this._sendEvent({
name: 'compute-pressure-changed',
records
});
}
/**
* Disposes the allocated resources.
*

@ -106,6 +106,7 @@ const events = {
'browser-support': 'browserSupport',
'camera-error': 'cameraError',
'chat-updated': 'chatUpdated',
'compute-pressure-changed': 'computePressureChanged',
'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
'data-channel-closed': 'dataChannelClosed',
'data-channel-opened': 'dataChannelOpened',

@ -1,6 +1,7 @@
import '../analytics/middleware';
import '../authentication/middleware';
import '../av-moderation/middleware';
import '../base/app/middleware';
import '../base/conference/middleware';
import '../base/config/middleware';
import '../base/jwt/middleware';

@ -0,0 +1,54 @@
import { AnyAction } from 'redux';
import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
import logger from './logger';
/**
* Experimental feature to monitor CPU pressure.
*/
let pressureObserver: typeof window.PressureObserver;
/**
* Middleware which intercepts app actions to handle changes to the related state.
*
* @param {Store} store - The redux store.
* @returns {Function}
*/
MiddlewareRegistry.register(() => (next: Function) => async (action: AnyAction) => {
switch (action.type) {
case APP_WILL_MOUNT: {
if ('PressureObserver' in globalThis) {
pressureObserver = new window.PressureObserver(
(records: typeof window.PressureRecord) => {
logger.info('Compute pressure state changed:', JSON.stringify(records));
if (typeof APP !== 'undefined') {
APP.API.notifyComputePressureChanged(records);
}
},
{ sampleRate: 1 }
);
try {
pressureObserver
.observe('cpu')
.catch((e: any) => logger.error('CPU pressure observer failed to start', e));
} catch (e: any) {
logger.error('CPU pressure observer failed to start', e);
}
}
break;
}
case APP_WILL_UNMOUNT: {
if (pressureObserver) {
pressureObserver.unobserve('cpu');
}
break;
}
}
return next(action);
});

@ -339,7 +339,7 @@ module.exports = (_env, argv) => {
...config.plugins,
...getBundleAnalyzerPlugin(analyzeBundle, 'external_api')
],
performance: getPerformanceHints(perfHintOptions, 35 * 1024)
performance: getPerformanceHints(perfHintOptions, 40 * 1024)
}),
Object.assign({}, config, {
entry: {

Loading…
Cancel
Save