Coder Social home page Coder Social logo

cub's Introduction

cub

@cub/cub

NPM version build status Test coverage David deps Known Vulnerabilities npm download

a web framework for fibjs

Install

$ npm i @cub/cub --save

Quick Start

const Cub = require('@cub/cub');

const cub = new Cub();

cub.register(ctx => {
  ctx.body = 'Hello World!';
});

cub.listen(8000);

Usage

  • multi-register

Register function can be invoked many times to accept interceptor. All these registered interceptors will be executed one by one.

cub.register(ctx => {
  ctx.body = 'Hello';
});

cub.register(ctx => {
  ctx.body += ' World!';
});
  • stop execute register

If you want to stop running the flowing interceptor, just return false(only false accept) in the current interceptor.

cub.register(ctx => {
  ctx.body = 'Hello ';
  return false; // only `false` accept
});

cub.register(ctx => {
  ctx.body += ' World!';
});
  • If you want to execute some logic after the last interceptor has been invoked like koa design, you register a an instance of BaseInterceptor.
const BaseInterceptor = Cub.BaseInterceptor;

cub.register(new class extends BaseInterceptor {
  before (ctx){
    ctx.body = 'Hello';
  }

  after (ctx){
    ctx.body += ' World!';
  }
});

API

todo

Benchmark

Cub : 7W QPS

~ wrk -c100 -t10  -d5  --latency  http://127.0.0.1:8000
Running 5s test @ http://127.0.0.1:8000
  10 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.91ms    4.09ms  55.16ms   97.72%
    Req/Sec     7.11k     1.09k   15.14k    93.07%
  Latency Distribution
     50%    1.38ms
     75%    1.44ms
     90%    1.53ms
     99%   24.96ms
  357495 requests in 5.10s, 41.93MB read
Requests/sec:  70060.74
Transfer/sec:      8.22MB

Koa@2 with Node.js 7.10.0: 1.5W QPS

~ wrk -c100 -t10  -d5  --latency  http://127.0.0.1:8000
Running 5s test @ http://127.0.0.1:8000
  10 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     6.51ms    1.09ms  20.98ms   91.32%
    Req/Sec     1.54k   581.07    14.30k    99.80%
  Latency Distribution
     50%    6.40ms
     75%    6.84ms
     90%    7.33ms
     99%    9.78ms
  76959 requests in 5.10s, 10.94MB read
Requests/sec:  15093.17
Transfer/sec:      2.14MB

express@4 with Node.js 7.10.0: 1W QPS

~ wrk -c100 -t10  -d5  --latency  http://127.0.0.1:8000
Running 5s test @ http://127.0.0.1:8000
  10 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     9.13ms  769.26us  16.17ms   82.08%
    Req/Sec     1.10k    61.17     1.21k    74.20%
  Latency Distribution
     50%    8.94ms
     75%    9.38ms
     90%   10.05ms
     99%   11.95ms
  54787 requests in 5.02s, 11.23MB read
Requests/sec:  10920.82
Transfer/sec:      2.24MB

Questions & Suggestions

Please open an issue here.

License

MIT

cub's People

Contributors

ngot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.