This file contains hidden or 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 HTTP = require('http'), Sys = require('sys'); | |
function readableSize(bytes) { | |
var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB']; | |
var e = Math.floor(Math.log(bytes)/Math.log(1024)); | |
return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e]; | |
} | |
function getMem(nice) { |
This file contains hidden or 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 httpProxy = require('http-proxy'); | |
// | |
// Addresses to use in the round robin proxy | |
// | |
var addresses = [ | |
{ | |
host: 'ws1.0.0.0', | |
port: 80 | |
}, |
This file contains hidden or 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 startFast; | |
var startSlow; | |
var size = 1000000; // million | |
var loopCount = 0; | |
var setTimeoutTest = function () { | |
loopCount++; | |
if ( loopCount == ( size - 1 ) ) { | |
console.log( 'setTimeout result: ' + ( new Date() - startFast ) + 'ms' ); |
This file contains hidden or 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
setTimeout(function() { | |
console.log('timeout'); | |
}, 0); | |
// simulate extreme cpu load | |
var d = +new Date; | |
console.log(new Date); | |
while (d + 2000 > new Date); | |
console.log(new Date); |
This file contains hidden or 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
type message = {author: string | |
; text: string} | |
room = Network.cloud("room"): Network.network(message) | |
user_update(x: message) = | |
line = <div class="line"> | |
<div class="user">{x.author}:</div> | |
<div class="message">{x.text}</div> | |
</div> |
This file contains hidden or 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
# Config ideal for load balancing many back-end Virtual Hosts with a pair of load balancers (one is for fail-over). | |
# HAProxy's ACL is ideal for dedicating more resources to certain virtual hosts especially to handle traffic spikes. | |
# Reference: | |
# http://www.techrawr.com/2009/09/18/using-the-acl-in-haproxy-for-load-balancing-named-virtual-hosts | |
# Don't copy blindly, change to suit your needs; at a minimum:- | |
# change maxconn based on your back-end server(s) capabilities | |
# enable/disable cookie option - disable if you don't want sticky sessions |
This file contains hidden or 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 express = require('express'); | |
var redis = require('redis'); | |
const serverType = process.argv[2]; | |
const serverHost = process.argv[3]; | |
const serverPort = parseInt(process.argv[4]); | |
const redisPort = 6379; | |
const redisHost = '127.0.0.1'; |
This file contains hidden or 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
(function (ctr,t) { | |
function inc () { ctr++ } | |
function display (ntps,ntpsStr,i,lps,lpsStr,ratioStr) { | |
ntps= ctr*1e3/(Date.now()-t); //nextTicks per second | |
ntpsStr= ", nextTicksPerSecond: "+ ntps.toFixed(1); | |
ctr= 0, i= 100e6, t= Date.now(); | |
while (i--) { inc() } |
This file contains hidden or 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 startFast; | |
var startSlow; | |
var size = 1000000; // million | |
var loopCount = 0; | |
var setTimeoutTest = function () { | |
loopCount++; | |
if ( loopCount == ( size - 1 ) ) { | |
console.log( 'setTimeout result: ' + ( new Date() - startFast ) + 'ms' ); |
This file contains hidden or 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 p = require('./point'); | |
> var o = new p.Point(); | |
> o.setX(6); | |
> o.setY(9); | |
> console.log(o.get()); | |
{ x: 6, y: 9 } |