This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// node.js worker_threads module example with for-await loop: main thread side | |
//$ node --exprimental-worker main.js | |
const path = require("path"); | |
const {Worker, MessageChannel} = require("worker_threads"); | |
// async queue as "asyncIterator" in ES2018 | |
class Queue { | |
constructor() { | |
this.polls = []; | |
this.gets = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function renderRoute(request, reply) { | |
const store = configureStore(); | |
store.dispatch(match(request.path, (error, redirectLocation, routerState) => { | |
if (redirectLocation) { | |
reply.redirect(redirectLocation.pathname + redirectLocation.search); | |
} else if (error) { | |
reply(error.message).code(500); | |
} else if (!routerState) { | |
reply('Not found').code(404); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"net/http" | |
"os/exec" | |
) | |
var ( | |
BUF_LEN = 1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util') | |
, Transform = require('stream').Transform | |
, StreamCombiner = require('./streamcombiner'); | |
var chunks1 = []; | |
var stream1 = new Transform(); | |
var soFar = ''; | |
stream1._transform = function(chunk, encoding, done) { | |
chunks1.push(chunk.toString()); | |
var pieces = (soFar + chunk).split('\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |