Skip to content

Commit

Permalink
chore(nestjs) push latest bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Sep 9, 2018
1 parent d588050 commit fa3ee7e
Show file tree
Hide file tree
Showing 43 changed files with 4,970 additions and 3,410 deletions.
48 changes: 48 additions & 0 deletions benchmarks/all_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.......................
express
.......................
Running 10s test @ http://localhost:3000
8 threads and 1024 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 47.78ms 19.09ms 212.47ms 66.94%
Req/Sec 1.31k 268.90 2.07k 72.38%
104687 requests in 10.02s, 21.47MB read
Socket errors: connect 0, read 877, write 0, timeout 0
Requests/sec: 10444.24
Transfer/sec: 2.14MB
.......................
fastify
.......................
Running 10s test @ http://localhost:3000
8 threads and 1024 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 19.16ms 7.24ms 114.56ms 58.84%
Req/Sec 3.23k 782.93 4.92k 78.75%
256793 requests in 10.02s, 33.55MB read
Socket errors: connect 0, read 846, write 0, timeout 0
Requests/sec: 25619.91
Transfer/sec: 3.35MB
.......................
nest
.......................
Running 10s test @ http://localhost:3000
8 threads and 1024 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 49.39ms 16.95ms 174.21ms 69.37%
Req/Sec 1.23k 468.57 2.48k 59.25%
98406 requests in 10.06s, 20.27MB read
Socket errors: connect 0, read 875, write 0, timeout 0
Requests/sec: 9779.15
Transfer/sec: 2.01MB
.......................
nest-fastify
.......................
Running 10s test @ http://localhost:3000
8 threads and 1024 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 26.63ms 11.03ms 91.14ms 72.37%
Req/Sec 2.29k 801.61 4.71k 71.88%
182595 requests in 10.04s, 24.03MB read
Socket errors: connect 0, read 888, write 0, timeout 0
Requests/sec: 18192.36
Transfer/sec: 2.39MB
7 changes: 7 additions & 0 deletions benchmarks/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const express = require('express');
const app = express();

app.get('/', async (req, res) => res.send('Hello world'));
app.listen(3000);
5 changes: 5 additions & 0 deletions benchmarks/fastify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const fastify = require('fastify')();
fastify.get('/', async (req, reply) => reply.send('Hello world'));
fastify.listen(3000);
9 changes: 9 additions & 0 deletions benchmarks/nest-fastify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions benchmarks/nest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions benchmarks/nest/app.controller.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class AppController {
root(): string;
}
28 changes: 28 additions & 0 deletions benchmarks/nest/app.controller.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benchmarks/nest/app.controller.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benchmarks/nest/app.module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare class AppModule {}
20 changes: 20 additions & 0 deletions benchmarks/nest/app.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benchmarks/nest/app.module.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions benchmarks/nest/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions benchmarks/nest/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions benchmarks/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

echo 'Library:' $1
node $1 &
pid=$!

sleep 2

wrk 'http://localhost:3000' \
-d 10 \
-c 1024 \
-t 8

kill $pid
23 changes: 23 additions & 0 deletions benchmarks/run_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

: > all_output.txt

lib=(express fastify nest nest-fastify)
for item in ${lib[*]}
do
echo '.......................' >> all_output.txt
echo $item >> all_output.txt
echo '.......................' >> all_output.txt

node $item &
pid=$!

sleep 2

wrk 'http://localhost:3000' \
-d 10 \
-c 1024 \
-t 8 >> all_output.txt

kill $pid
done
4 changes: 4 additions & 0 deletions bundle/core/helpers/application-ref-host.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare class ApplicationReferenceHost {
private _applicationRef;
applicationRef: any;
}
11 changes: 11 additions & 0 deletions bundle/core/helpers/application-ref-host.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ApplicationReferenceHost {
set applicationRef(applicationRef) {
this._applicationRef = applicationRef;
}
get applicationRef() {
return this._applicationRef;
}
}
exports.ApplicationReferenceHost = ApplicationReferenceHost;
2 changes: 2 additions & 0 deletions bundle/core/helpers/external-context-creator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Controller, Transform } from '@nestjs/common/interfaces';
import 'reflect-metadata';
import { GuardsConsumer } from '../guards/guards-consumer';
import { GuardsContextCreator } from '../guards/guards-context-creator';
import { NestContainer } from '../injector/container';
import { Module } from '../injector/module';
import { ModulesContainer } from '../injector/modules-container';
import { InterceptorsConsumer } from '../interceptors/interceptors-consumer';
Expand All @@ -29,6 +30,7 @@ export declare class ExternalContextCreator {
private readonly pipesConsumer;
private readonly contextUtils;
constructor(guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer, modulesContainer: ModulesContainer, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer);
static fromContainer(container: NestContainer): ExternalContextCreator;
create<T extends ParamsMetadata = ParamsMetadata>(instance: Controller, callback: (...args) => any, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory): (...args: any[]) => Promise<any>;
findContextModuleName(constructor: Function): string;
findComponentByClassName(module: Module, className: string): boolean;
Expand Down
9 changes: 9 additions & 0 deletions bundle/core/helpers/external-context-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const constants_1 = require("@nestjs/common/constants");
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
require("reflect-metadata");
const constants_2 = require("../guards/constants");
const guards_consumer_1 = require("../guards/guards-consumer");
const guards_context_creator_1 = require("../guards/guards-context-creator");
const interceptors_consumer_1 = require("../interceptors/interceptors-consumer");
const interceptors_context_creator_1 = require("../interceptors/interceptors-context-creator");
const pipes_consumer_1 = require("../pipes/pipes-consumer");
const pipes_context_creator_1 = require("../pipes/pipes-context-creator");
const context_utils_1 = require("./context-utils");
class ExternalContextCreator {
constructor(guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer, modulesContainer, pipesContextCreator, pipesConsumer) {
Expand All @@ -17,6 +23,9 @@ class ExternalContextCreator {
this.pipesConsumer = pipesConsumer;
this.contextUtils = new context_utils_1.ContextUtils();
}
static fromContainer(container) {
return new ExternalContextCreator(new guards_context_creator_1.GuardsContextCreator(container, container.applicationConfig), new guards_consumer_1.GuardsConsumer(), new interceptors_context_creator_1.InterceptorsContextCreator(container, container.applicationConfig), new interceptors_consumer_1.InterceptorsConsumer(), container.getModules(), new pipes_context_creator_1.PipesContextCreator(container, container.applicationConfig), new pipes_consumer_1.PipesConsumer());
}
create(instance, callback, methodName, metadataKey, paramsFactory) {
const module = this.findContextModuleName(instance.constructor);
const pipes = this.pipesContextCreator.create(instance, callback, module);
Expand Down
1 change: 1 addition & 0 deletions bundle/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './adapters';
export { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from './constants';
export { BaseExceptionFilter } from './exceptions/base-exception-filter';
export { ApplicationReferenceHost } from './helpers/application-ref-host';
export { ModuleRef } from './injector/module-ref';
export { HTTP_SERVER_REF } from './injector/tokens';
export { MiddlewareBuilder } from './middleware/builder';
Expand Down
2 changes: 2 additions & 0 deletions bundle/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ exports.APP_INTERCEPTOR = constants_1.APP_INTERCEPTOR;
exports.APP_PIPE = constants_1.APP_PIPE;
var base_exception_filter_1 = require("./exceptions/base-exception-filter");
exports.BaseExceptionFilter = base_exception_filter_1.BaseExceptionFilter;
var application_ref_host_1 = require("./helpers/application-ref-host");
exports.ApplicationReferenceHost = application_ref_host_1.ApplicationReferenceHost;
var module_ref_1 = require("./injector/module-ref");
exports.ModuleRef = module_ref_1.ModuleRef;
var tokens_1 = require("./injector/tokens");
Expand Down
11 changes: 11 additions & 0 deletions bundle/core/injector/container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { DynamicModule } from '@nestjs/common';
import { Type } from '@nestjs/common/interfaces/type.interface';
import 'reflect-metadata';
import { ApplicationConfig } from '../application-config';
import { ApplicationReferenceHost } from '../helpers/application-ref-host';
import { ExternalContextCreator } from '../helpers/external-context-creator';
import { Reflector } from '../services';
import { Module } from './module';
import { ModulesContainer } from './modules-container';
export declare class NestContainer {
Expand All @@ -10,6 +13,10 @@ export declare class NestContainer {
private readonly moduleCompiler;
private readonly modules;
private readonly dynamicModulesMetadata;
private readonly reflector;
private readonly applicationRefHost;
private externalContextCreator;
private modulesContainer;
private applicationRef;
constructor(_applicationConfig?: ApplicationConfig);
readonly applicationConfig: ApplicationConfig | undefined;
Expand All @@ -34,6 +41,10 @@ export declare class NestContainer {
bindGlobalsToRelatedModules(module: Module): void;
bindGlobalModuleToModule(module: Module, globalModule: Module): any;
getDynamicMetadataByToken(token: string, metadataKey: keyof DynamicModule): any[];
getReflector(): Reflector;
getExternalContextCreator(): ExternalContextCreator;
getApplicationRefHost(): ApplicationReferenceHost;
getModulesContainer(): ModulesContainer;
}
export interface InstanceWrapper<T> {
name: any;
Expand Down
27 changes: 27 additions & 0 deletions bundle/core/injector/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const constants_1 = require("@nestjs/common/constants");
require("reflect-metadata");
const invalid_module_exception_1 = require("../errors/exceptions/invalid-module.exception");
const unknown_module_exception_1 = require("../errors/exceptions/unknown-module.exception");
const application_ref_host_1 = require("../helpers/application-ref-host");
const external_context_creator_1 = require("../helpers/external-context-creator");
const services_1 = require("../services");
const compiler_1 = require("./compiler");
const module_1 = require("./module");
const modules_container_1 = require("./modules-container");
Expand All @@ -14,12 +17,18 @@ class NestContainer {
this.moduleCompiler = new compiler_1.ModuleCompiler();
this.modules = new modules_container_1.ModulesContainer();
this.dynamicModulesMetadata = new Map();
this.reflector = new services_1.Reflector();
this.applicationRefHost = new application_ref_host_1.ApplicationReferenceHost();
}
get applicationConfig() {
return this._applicationConfig;
}
setApplicationRef(applicationRef) {
this.applicationRef = applicationRef;
if (!this.applicationRefHost) {
return;
}
this.applicationRefHost.applicationRef = applicationRef;
}
getApplicationRef() {
return this.applicationRef;
Expand Down Expand Up @@ -126,5 +135,23 @@ class NestContainer {
}
return [];
}
getReflector() {
return this.reflector;
}
getExternalContextCreator() {
if (!this.externalContextCreator) {
this.externalContextCreator = external_context_creator_1.ExternalContextCreator.fromContainer(this);
}
return this.externalContextCreator;
}
getApplicationRefHost() {
return this.applicationRefHost;
}
getModulesContainer() {
if (!this.modulesContainer) {
this.modulesContainer = this.getModules();
}
return this.modulesContainer;
}
}
exports.NestContainer = NestContainer;
11 changes: 8 additions & 3 deletions bundle/core/injector/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Controller, DynamicModule, Injectable, NestModule } from '@nestjs/common/interfaces';
import { Type } from '@nestjs/common/interfaces/type.interface';
import { ApplicationReferenceHost } from '../helpers/application-ref-host';
import { ExternalContextCreator } from '../helpers/external-context-creator';
import { Reflector } from '../services/reflector.service';
import { InstanceWrapper, NestContainer } from './container';
import { ModulesContainer } from './modules-container';
export interface CustomComponent {
provide: any;
name: string;
Expand Down Expand Up @@ -40,10 +44,11 @@ export declare class Module {
addCoreInjectables(container: NestContainer): void;
addModuleRef(): void;
addModuleAsComponent(): void;
addReflector(): void;
addReflector(reflector: Reflector): void;
addApplicationRef(applicationRef: any): void;
addExternalContextCreator(container: NestContainer): void;
addModulesContainer(container: NestContainer): void;
addExternalContextCreator(externalContextCreator: ExternalContextCreator): void;
addModulesContainer(modulesContainer: ModulesContainer): void;
addApplicationRefHost(applicationRefHost: ApplicationReferenceHost): void;
addInjectable(injectable: Type<Injectable>): string;
addComponent(component: ComponentMetatype): string;
isCustomProvider(component: ComponentMetatype): component is CustomClass | CustomFactory | CustomValue;
Expand Down
Loading

0 comments on commit fa3ee7e

Please sign in to comment.