KASM-3574 worker cleanup (#49)

* KASM-3574 worker cleanup

Co-authored-by: mattmcclaskey <matt@kasmweb.com>
This commit is contained in:
Matt McClaskey 2022-11-15 12:15:40 -05:00 committed by GitHub
parent 34305e9956
commit 2f01048bc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 102 additions and 71 deletions

View File

@ -28,12 +28,23 @@ export default class TightDecoder {
}
}
enableQOI() {
if (!this._enableQOI) {
this._enableQOIWorkers();
// ===== PROPERTIES =====
get enableQOI() { return this._enableQOI; }
set enableQOI(enabled) {
if(this._enableQOI === enabled) {
return;
}
return this._enableQOI; //did it succeed
if (enabled) {
this._enableQOI = this._enableQOIWorkers();
} else {
this._enableQOI = false;
this._disableQOIWorkers();
}
}
// ===== Public Methods =====
decodeRect(x, y, width, height, sock, display, depth, frame_id) {
if (this._ctl === null) {
@ -87,6 +98,8 @@ export default class TightDecoder {
return ret;
}
// ===== Private Methods =====
_fillRect(x, y, width, height, sock, display, depth, frame_id) {
if (sock.rQwait("TIGHT", 3)) {
return false;
@ -398,12 +411,33 @@ export default class TightDecoder {
return this._scratchBuffer;
}
async _disableQOIWorkers() {
if (this._workers) {
this._enableQOI = false;
this._availableWorkers = null;
this._sabs = null;
this._sabsR = null;
this._arrs = null;
this._arrsR = null;
this._qoiRects = null;
this._rectQlooping = null;
for await (let i of Array.from(Array(this._threads).keys())) {
this._workers[i].terminate();
delete this._workers[i];
}
this._workers = null;
}
}
_enableQOIWorkers() {
const supportsSharedArrayBuffers = typeof SharedArrayBuffer !== "undefined";
if (!supportsSharedArrayBuffers) {
Log.Warn("Enabling QOI Failed, client not compatible.");
return false;
}
let fullPath = window.location.pathname;
let path = fullPath.substring(0, fullPath.lastIndexOf('/')+1);
let sabTest = typeof SharedArrayBuffer;
if (sabTest !== 'undefined') {
this._enableQOI = true;
if ((window.navigator.hardwareConcurrency) && (window.navigator.hardwareConcurrency >= 4)) {
this._threads = 16;
} else {
@ -455,9 +489,7 @@ export default class TightDecoder {
for (let i = 0; i < this._threads; i++) {
this._workers[i].postMessage({path:path});
}
} else {
this._enableQOI = false;
Log.Warn("Enabling QOI Failed, client not compatible.");
}
return true;
}
}

View File

@ -491,15 +491,14 @@ export default class RFB extends EventTargetMixin {
if(this._enableQOI === enabled) {
return;
}
if (enabled) {
if (!this._decoders[encodings.encodingTight].enableQOI()) {
//enabling qoi failed
return;
}
this._decoders[encodings.encodingTight].enableQOI = enabled;
this._enableQOI = this._decoders[encodings.encodingTight].enableQOI
if (this._enableQOI === enabled) {
this._pendingApplyEncodingChanges = true;
}
this._enableQOI = enabled;
this._pendingApplyEncodingChanges = true;
}
get antiAliasing() { return this._display.antiAliasing; }