Adding Helpers to uninstall services etc. Fixing AMQP-Parallel example

This commit is contained in:
Martin Karkowski 2021-06-07 08:00:14 +02:00
parent 2c3a6ddb36
commit 15644f1a9e
6 changed files with 156 additions and 81 deletions

View File

@ -0,0 +1,18 @@
set DIR=%~dp0
cd "%DIR%"
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
%@Try%
@REM Uninstall IO-Server
node .\dist\lib\cli\ioServerService.js -m uninstall
%@EndTry%
:@Catch
echo uninstall IO-Server
:@EndCatch
@REM Uninstall all Services
for /f "delims=" %%a in ('dir /s /o /b *03-uninstall.bat') do (
echo %%a
call %%a
)

View File

@ -0,0 +1,18 @@
set DIR=%~dp0
cd "%DIR%"
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
%@Try%
@REM Uninstall IO-Server
node .\dist\lib\cli\ioServerService.js -m uninstall
%@EndTry%
:@Catch
echo uninstall IO-Server
:@EndCatch
@REM Uninstall all Services
for /f "delims=" %%a in ('dir /s /o /b *03-uninstall.bat') do (
echo %%a
call %%a
)

34
lib/index.ts Normal file
View File

@ -0,0 +1,34 @@
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2021-06-04 19:38:37
* @modify date 2021-06-04 19:38:37
* @desc This is the exporter for the NoPE-JS Library
*
*/
import { Bridge } from "./communication/bridge";
import { getLayer } from "./communication/getLayer";
import { AmqpLayer } from "./communication/layers/amqpLayer";
import { IoSocketMirrorServer } from "./communication/mirrors/ioSocketMirrorServer";
import { IJsonSchema } from "./types/IJSONSchema";
export const communication = {
getLayer,
layer: {
AmqpLayer
},
mirrors: {
IoSocketMirrorServer
},
bridge: Bridge
};
export type types = {
IJSONSchema: IJsonSchema
}
export const helpers = {
};

View File

@ -2,7 +2,7 @@
"name": "nope-backend",
"version": "1.0.0",
"description": "Nodejs Backend, combining nextjs with openapi",
"main": "index.js",
"main": "dist/index.js",
"bin": {
"nope-js": "./bin/nope"
},

View File

@ -1,60 +1,70 @@
import 'reflect-metadata';
import { promisify } from 'util';
import { AmqpLayer } from "../lib/communication/amqpLayer";
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2021-06-04 19:17:56
* @modify date 2021-06-04 19:17:56
* @desc [description]
*/
import "reflect-metadata";
import { promisify } from "util";
import { runNopeBackend } from "../lib/cli/runNopeBackend";
import { getNopeLogger } from "../lib/logger/getLogger";
import { NopeObservable } from "../lib/observables/nopeObservable";
const client = new AmqpLayer('localhost');
const sleep = promisify(setTimeout)
const logger = getNopeLogger('dispatcher','info')
const sleep = promisify(setTimeout);
const logger = getNopeLogger("dispatcher","info");
const main = async () => {
let max = 10000;
await sleep(1000);
logger.info("Creating Dispatcher");
const dispatcher = await runNopeBackend({skipLoadingConfig: true, channel:"amqp", log: "info"});
logger.info("Dispatcher ready");
const max = 10000;
await sleep(1000);
const promises = [];
const dispatcher = new nopeDispatcher({ communicator: client, logger }, () => new NopeObservable());
await sleep(500);
let c = 0
let c = 0;
// Call Tasks Parallel!
const start = Date.now();
while (c < 10) {
dispatcher.performCall('func', [c++]).catch(e => console.error(e));
try {
logger.info("Dispatching Call", c);
promises.push(dispatcher.performCall("func", [c++]));
} catch(e){
logger.error(e);
}
}
const dispatched = Date.now();
// Now Wait for all Open Task
await Promise.all(promises);
const end = Date.now();
logger.info("Dispatching took",dispatched-start,"[ms]");
logger.info("Calling took",end-start,"[ms]");
// Benchmark:
c = 0
// Call Tasks Parallel!
while (c < max) {
await dispatcher.performCall('benchmark', [], {
paramsHasNoCallback: true,
});
c++;
}
await sleep(500);
const obs01 = new NopeObservable<number>();
dispatcher.registerObservable(obs01, {
mode: 'publish',
topic: 'test.var'
mode: "publish",
topic: "test.var",
schema: {}
});
obs01.setContent(1200);
await sleep(500);
c = 0;
while (c < max) {
obs01.setContent(c++);
}
c = 0;
while(c < max){
await client.emit('publish','benchmark', c++);
}
}
};
main();

View File

@ -1,70 +1,65 @@
import 'reflect-metadata';
import { promisify } from 'util';
import { AmqpLayer } from "../lib/communication/amqpLayer";
import { nopeDispatcher } from "../lib/dispatcher/nopeDispatcher";
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2021-06-04 19:18:50
* @modify date 2021-06-04 19:18:50
* @desc [description]
*/
import "reflect-metadata";
import { promisify } from "util";
import { runNopeBackend } from "../lib/cli/runNopeBackend";
import { getNopeLogger } from "../lib/logger/getLogger";
import { NopeObservable } from "../lib/observables/nopeObservable";
import { generateBenchmarkFunction } from "../modules/funcs/generateBenchmarkFunction";
const sleep = promisify(setTimeout);
const logger = getNopeLogger("dispatcher","info");
const client = new AmqpLayer('localhost');
const sleep = promisify(setTimeout)
const logger = getNopeLogger('dispatcher','info')
/**
* Helper that will create a Sleep Function
* @param name
* @param delay
* @returns
*/
function genFunc(name, delay) {
const logger = getNopeLogger('debug',name)
return (idx: number) => {
return new Promise((resolve, reject) => {
try {
logger.info('started ' + idx.toString());
setTimeout(() => {
logger.info('finished ' + idx.toString());
resolve();
}, delay);
} catch(e){
reject(e)
}
})
}
}
const logger = getNopeLogger("debug",name);
return async (idx: number) => {
logger.info("started",name,"with input=",idx);
await sleep(delay);
logger.info("waited",name,"with input=",idx);
};
}
const main = async () => {
await sleep(1000);
const dispatcher = new nopeDispatcher({ communicator: client, logger }, () => new NopeObservable());
logger.info("Creating Dispatcher");
const dispatcher = await runNopeBackend({skipLoadingConfig: true, channel:"amqp", log: "info"});
logger.info("Dispatcher ready");
const benchmarkFunction = generateBenchmarkFunction(1000, 'Function');
const benchmarkDirect = generateBenchmarkFunction(1000, 'Direct');
const benchmarkObservable = generateBenchmarkFunction(1000, 'Observable');
const benchmarkFunction = generateBenchmarkFunction(1000, "Function");
const benchmarkObservable = generateBenchmarkFunction(1000, "Observable");
// Register Functions
dispatcher.registerFunction(genFunc('dispatcher-1-slow', 2000), {
id: 'func'
dispatcher.registerFunction(genFunc("dispatcher-1-slow", 2000), {
id: "func"
});
dispatcher.registerFunction(async () => benchmarkFunction(), {
id: 'benchmark'
id: "benchmark"
});
await client.on('subscribe','benchmark', benchmarkDirect);
await sleep(500);
const obs01 = new NopeObservable<number>();
obs01.subscribe(benchmarkObservable);
dispatcher.registerObservable(obs01, {
mode: 'subscribe',
topic: 'test.var'
});
dispatcher.registerObservable(obs01, {
mode: 'subscribe',
topic: 'test.var'
});
}
mode: "subscribe",
topic: "test.var",
schema: {}
});
};
main();