Skip to content

Instantly share code, notes, and snippets.

View sreepurnajasti's full-sized avatar

sreepurna sreepurnajasti

View GitHub Profile
@sreepurnajasti
sreepurnajasti / down.js
Created February 10, 2017 07:12
A test case which implements an multi-client download by calibrating the libuv loop
var app = require('appmetrics');
var mon = app.monitor();
var http = require('http');
var util = require('util');
mon.on('eventloop', function(d) {
console.log(Math.round(d.latency.avg));
});
var string = 'http://' + process.argv[2] + ':' + process.argv[3] + '/';
@sreepurnajasti
sreepurnajasti / exp.js
Last active February 15, 2017 12:15
A testcase which can holds to 128* 100 connections parllely and matching the data chunk with a specified word and storing its word count in a file.
var http = require('http');
var util = require('util');
var fs = require("fs");
var string = 'http://' + process.argv[2] + ':' + process.argv[3] + '/';
var out = fs.createWriteStream('./out.txt');
var start = process.hrtime();
@sreepurnajasti
sreepurnajasti / perf_modifiednode.txt
Created February 15, 2017 12:17
perf report for exp.js
25.40%node libc-2.17.so [.] memchr
16.84%node [kernel.kallsyms] [k] copy_user_enhanced_fast_string
10.57%node node [.] v8::internal::StringSearch<unsigned char, unsigned char>::LinearSearch(v8::internal::StringSearch<unsigned char, unsigned char>*, v8::internal::Vector<unsigned char const>, int)
10.40%node libc-2.17.so [.] __memcpy_ssse3_back
4.88%node node [.] v8::internal::Factory::NewStringFromUtf8(v8::internal::Vector<char const>, v8::internal::PretenureFlag)
1.95%node [kernel.kallsyms] [k] free_hot_cold_page
1.77%node [kernel.kallsyms] [k] put_page
1.05%node [kernel.kallsyms] [k] iowrite16
1.04%node perf-27128.map [.] Builtin:RegExpPrototypeExec
1.01%node [kernel.kallsyms] [k] __do_softirq
var http = require('http');
var fs = require('fs');
var data = fs.readFileSync('./data.in');
var server = http.createServer(function(req, res) {
console.log('connected');
res.end(data);
});
server.listen(25000);
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@sreepurnajasti
sreepurnajasti / cpu.js
Created April 27, 2017 06:21
This is a program which causes high cpu consumption of Node production anomaly
var obj;
var str = JSON.stringify(console);
while (true) {
obj = JSON.parse(str);
str = JSON.stringify(obj);
}
@sreepurnajasti
sreepurnajasti / cluster.js
Last active June 12, 2018 06:51
simple cluster application
var cluster = require('cluster');
var count = 0;
function *sendRequest(){
for (var i=0; i<10000; i++) {
count++;
yield i;
if(count == 10){
process.exit(0);
}
}
@sreepurnajasti
sreepurnajasti / index.html
Last active June 18, 2018 09:20
upload single file from client to server
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple Multer Upload Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form action="/" enctype="multipart/form-data" method="post">
<input type="file" name="file-to-upload">
@sreepurnajasti
sreepurnajasti / main.html
Created June 19, 2018 08:27
upload single file from client( jquery, ajax) to server(express, multer)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Upload File</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
@sreepurnajasti
sreepurnajasti / main.html
Last active January 27, 2023 00:51
send form data from html form using jquery ajax(serialize method) to express Nodejs
<!doctype html>
<html>
<head>
<title>AJAX/Express Example</title>
</head>
<body>
<form id="signup" method="POST" action="/addUser">
<div>
<label for="name">Name</label>
<input name="name"type="text" id="name" />