nope/modules/mod-GRPC-Interface/test/performance-broker.ts
2020-09-08 16:59:06 +02:00

56 lines
1.6 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2018-05-22 12:42:35
* @modify date 2018-08-17 07:29:51
* @desc [description]
*/
/** Clear the Screen */
declare const process: any;
import { Builder } from '../../Assembly-Builder/src/Container-Builder.FileLoader';
import * as BENCHMARK from '../../Benchmark/assembly/manual-assembly';
import * as LOGGING from '../../Logger/assembly/manual-assembly';
import * as GRPC from '../../mod-GRPC-Interface/assembly/manual-assembly';
Builder.load();
Builder.on('loaded', () => {
Builder.instance.container.get<LOGGING.Printer>(LOGGING.TYPES.Printer).printLog('info');
/** Create the GRPC-Broker */
const _broker = Builder.instance.container.get<GRPC.Broker>(GRPC.TYPES.GrpcBroker) as GRPC.Broker;
const _greeter = _broker.createClient('greeter', 'Proto-Repository\\protos\\helloworld.proto', 'helloworld', 'greeter', 'localhost:50051');
const max = 1000;
const _benchmark = Builder.instance.container.get<BENCHMARK.BenchmarkModule>(BENCHMARK.TYPES.BenchmarkModule).generateBenchmarkFunction(max, 'GPRC-STUBS');
if (_greeter) {
let i = max * 20 + 1;
console.time('benchmark');
const callFunc = () => {
if (i >= 0) {
_benchmark();
(_greeter as GRPC.Stub).call('sayhello', { name: 'test' }, (_error, _data) => callFunc());
i--;
} else {
console.timeEnd('benchmark');
}
};
(_greeter as GRPC.Stub).call('sayhello', { name: 'test' }, (_error, _data) => callFunc());
}
});