Skip to content

Instantly share code, notes, and snippets.

View geek's full-sized avatar
🏠
Working from home

Wyatt Preul geek

🏠
Working from home
View GitHub Profile
server.route({
method: 'GET',
path: '/user/{userId}',
config: {
handler: retrieveUser,
response: {
sample: 50,
schema: {
name: Joi.string().required(),
email: Joi.string().required().email()
@geek
geek / pack-server.js
Last active August 29, 2015 14:02
Example of using server packs to register plugins
var Hapi = require('hapi');
var Good = require('good');
var Reptile = require('reptile');
var pack = new Hapi.Pack();
pack.server(8000, { labels: ['web']});
pack.server(8001, { labels: ['admin']});
pack.register(Good, function (err) {});
#!/usr/sbin/dtrace -s
pid$1::*HandleScopeC1*:entry
{
self->cone++;
}
pid$1::*HandleScopeD1*:entry
/self->cone/
{
> ::dmods -l
ld.so.1
dcmd Bind - Display a Binding Descriptor
dcmd Callers - Display Rt_map CALLERS binding descriptors
dcmd Depends - Display Rt_map DEPENDS binding descriptors
dcmd ElfDyn - Display Elf_Dyn entry
dcmd ElfEhdr - Display Elf_Ehdr entry
dcmd ElfPhdr - Display Elf_Phdr entry
dcmd Groups - Display Rt_map GROUPS group handles
@geek
geek / mem.js
Created June 24, 2013 17:34
Here is an example of code that grows the memory for a while then eventually stabilizes
var ChildProcess = require('child_process');
var maxMem = Math.round(process.memoryUsage().rss / (1024 * 1024)) * 2;
setInterval(function () {
ChildProcess.exec('echo', function () {
var mem = Math.round(process.memoryUsage().rss / (1024 * 1024));
console.log(mem + 'M used');
var Http = require('http');
setInterval(function () {
Http.get('http://localhost:9000/', function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
}, 5);
// Middle tier (similulates inbound and outbound traffic)
// Load modules
var Http = require('http');
setInterval(function () {
Http.request({ port: 9000 }).end();
}, 0);
var Http = require('http');
Http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
Http.request({ host: 'localhost', port: 9000}).end();
}).listen(8000);
var ChildProcess = require('child_process');
var maxMem = Math.round(process.memoryUsage().rss / (1024 * 1024)) * 2;
console.time('leak');
setInterval(function () {
ChildProcess.exec('echo', function () {
var mem = Math.round(process.memoryUsage().rss / (1024 * 1024));