feat: initial proposal for multithreaded execution

This commit is contained in:
Thomas Dupont
2022-05-13 11:27:31 +02:00
committed by Joachim Van Herwegen
parent 32245fc604
commit 236bbc6e5d
40 changed files with 880 additions and 97 deletions

View File

@@ -1,6 +1,6 @@
import cluster from 'cluster';
import AsyncLock from 'async-lock';
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier';
import type { SingleThreaded } from '../../init/cluster/SingleThreaded';
import { getLoggerFor } from '../../logging/LogUtil';
import { InternalServerError } from '../errors/InternalServerError';
import type { ResourceLocker } from './ResourceLocker';
@@ -11,7 +11,7 @@ import type { ResourceLocker } from './ResourceLocker';
* in a memory leak if locks are never unlocked, so make sure this is covered with expiring locks for example,
* and/or proper `finally` handles.
*/
export class MemoryResourceLocker implements ResourceLocker {
export class MemoryResourceLocker implements ResourceLocker, SingleThreaded {
protected readonly logger = getLoggerFor(this);
private readonly locker: AsyncLock;
@@ -20,10 +20,6 @@ export class MemoryResourceLocker implements ResourceLocker {
public constructor() {
this.locker = new AsyncLock();
this.unlockCallbacks = {};
if (cluster.isWorker) {
this.logger.warn(`MemoryResourceLocker is not thread-safe/process-safe!
You should only use this locker in a single-thread/single-process CSS setup.`);
}
}
public async acquire(identifier: ResourceIdentifier): Promise<void> {