- Identify total average [R]equests per second
- Identify average response [T]ime per request
- Calculate:
((R * T) / 1000) * 1.2
Ex:
((200 RPM * 200ms) / 1000) * 1.2 = 48 connections required
// This middleware example takes in the entire swagger spec and tries to find the route in it. | |
const validate = require('swagger-route-validator'); | |
const spec = require('./my-spec'); | |
function validateRequest(req, res, next) { | |
const layer = app._router.stack.find(bloc => bloc.route && bloc.regexp.exec(req.originalUrl) !== null); | |
// Check if route exists | |
if (!layer) return next(); |
export function to<T = any>(promise: Promise<T>): Promise<[null, T] | [any, null?]> { | |
return promise | |
.then((data) => [null, data] as [null, T]) | |
.catch((err) => [err] as [any]); | |
} |
export function deferred<T>() { | |
let resolve: (value?: T | PromiseLike<T>) => void; | |
let reject: (reason?: any) => void; | |
const promise = new Promise<T>((res, rej) => { | |
resolve = res; | |
reject = rej; | |
}); | |
return { promise, resolve, reject }; | |
} |
((R * T) / 1000) * 1.2
Ex:
((200 RPM * 200ms) / 1000) * 1.2 = 48 connections required
#!/bin/bash | |
# Go setup: | |
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) | |
source ~/.gvm/scripts/gvm | |
sudo apt-get install bison -y | |
gvm install go1.14 -B | |
gvm use go1.14 |
function romanToNum(str) { | |
const symbols = 'IVXLCDM'; | |
let acc = ''; | |
// Reverse iterate through the provided characters | |
for (let i = str.length - 1; i >= 0; i--) { | |
// Get the associated roman character symbol's order in the list | |
let index = symbols.indexOf(str[i]); | |
// Calculate the value for the symbol 1 || 5 ^ 10 based on the previous index value | |
let value = (index % 2 === 0 ? 1 : 5) * (10**(index>>1)); |
const { promisify } = require('util'); | |
const stream = collection.find(); | |
const next = promisify(stream.nextObject); | |
let row; | |
while(null !== (row = await next(stream))) { | |
// do stuff with your row | |
} |
# Final production image | |
# =============================== | |
FROM node:14 as final | |
RUN mkdir /app && chown node:node /app | |
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64 | |
RUN chmod +x /usr/local/bin/dumb-init | |
USER node |
const toRadians = num => num * Math.PI / 180; | |
// Get the long, lat values for the desired dc | |
module.exports.datacenters = { | |
'ap-east-1': [22.29, 114.16 ], | |
'ap-northeast-1': [35.41, 139.42 ], | |
'ap-northeast-2': [37.56, 126.98 ], | |
'ap-northeast-3': [34.65, 136 ], | |
'ap-south-1': [19.08, 72.88 ], | |
'ap-southeast-1': [1.37, 103.8 ], |
/** | |
* Multi-process request | |
*/ | |
/* Requires ------------------------------------------------------------------*/ | |
const crypto = require('crypto'); | |
const path = require('path'); | |
const fork = require('child_process').fork; |