Skip to content

Instantly share code, notes, and snippets.

View seriousManual's full-sized avatar
🐷
stuff

Manuel Ernst seriousManual

🐷
stuff
View GitHub Profile
@seriousManual
seriousManual / asynchronicity_synchronicity
Created February 15, 2012 08:42
showing the problem of asynchrounos functions that behave not asynchrounos
function myObject() {
function initialize() {
//do something
someAsynchrounosFunction( function (err, data) {
this.emit( 'init' );
} );
}
initialize();
@seriousManual
seriousManual / node_irrational_highCPU
Created March 29, 2012 13:13
replicating very high cpu usage when not doing any calculation at all
var data = []
,number = 5000
,numberElements = 130
,numberQueries = 15;
for( var i = 0; i < number; i++ ) {
data[ i ] = {};
for( var x = 0; x < numberElements; x++ ) {
@seriousManual
seriousManual / gist:2909389
Created June 11, 2012 10:01
replicating process.send not working anymore. after a while messages sent from worker do not reach the master instance when under heavy load (~7000req/s).
var cluster = require( 'cluster' )
,http = require( 'http' );
if ( cluster.isMaster ) {
for (var i = 0; i < 8; i++) {
var worker = cluster.fork();
worker.on( 'message', function() {
console.log( Math.random() );
} );
@seriousManual
seriousManual / gist:4139428
Created November 24, 2012 12:12
emitted events are not acting asynchronous
var EE = require( 'events').EventEmitter;
var utils = require( 'util' );
function MyEmitter() {
EE.call( this );
var that = this;
this.doit = function() {
//doing something.....
@seriousManual
seriousManual / udp socket send in cluster environment
Last active December 17, 2015 20:29
minimal example that shows that the process dies when someone tries to send a udp package in an cluster environment
var dgram = require('dgram');
var cluster = require('cluster');
var http = require('http');
var socket = dgram.createSocket("udp4");
if (cluster.isMaster) {
for (var i = 0; i < 4; i++) {
cluster.fork();
}
var server;
var app = express();
fooHandler.on('initialized', function(error) {
server = app.listen(configuration.port);
});
process.on('uncaughtexception', function (error) {
//throws if the server is not acutally running
server.close(function() {
futex(0x7fad86ffd9d0, FUTEX_WAIT, 14380, NULL
(gdb) bt
#0 0x0000003322009080 in pthread_join () from /lib64/libpthread.so.0
#1 0x00000000006d431e in uv_thread_join ()
#2 0x00000000005868ea in ?? ()
#3 0x000000332180f77e in _dl_fini () from /lib64/ld-linux-x86-64.so.2
#4 0x0000003321c39931 in __run_exit_handlers () from /lib64/libc.so.6
#5 0x0000003321c399b5 in exit () from /lib64/libc.so.6
#6 0x000000000058cbc7 in node::Exit(v8::Arguments const&) ()
var cp = require('child_process');
var c = cp.execFile("/bin/false");
c.on('exit', function() {
console.log("got exit");
});
describe('sample test request', function () {
var response, body;
before(function (done) {
var options = {
url: BASE_URL + 'outputDebugInfo',
headers: {
'foo': 'bar'
}
};
var spawn = require('child_process').spawn;
var path = require('path');
var pathToMockServer = path.join(__dirname, '../../tests/mockServer/server');
var mockServerProcess;
before(function (done) {
console.error('\nStarting mock server...');
mockServerProcess = spawn('node', [pathToMockServer]);