<commit_before>"use strict";

const v8 = require('v8-natives');   

let ServiceBroker = require("./src/service-broker");
let Context = require("./src/context");
let Transporters = require("./src/transporters");

let { generateToken, json2String } = require("./src/utils");
let Promise	= require("bluebird");


function createBrokers(Transporter, opts) {
	let b1 = new ServiceBroker({
		transporter: new Transporter(opts),
		//requestTimeout: 0,
		//logger: console,
		//logLevel: "debug",
		nodeID: "node-1"
	});

	let b2 = new ServiceBroker({
		transporter: new Transporter(opts),
		//requestTimeout: 0,
		//logger: console,
		//logLevel: "debug",
		nodeID: "node-2"
	});

	b2.createService({
		name: "echo",
		actions: {
			reply(ctx) {
				return ctx.params;
			}
		}
	});

	b1.start().then(() => b2.start());

	return [b1, b2];
}

let [b1, b2] = createBrokers(Transporters.Fake);

function translateStatus(status) {
	const texts = [
		"-",
		"Optimized",
		"Un-optimized",
		"Always Optimized",
		"Never Optimized",
		"?",
		"Maybe Optimized",
	];
	return texts[status];
}


let count = 0;
function doRequest() {
	count++;
	return b1.call("echo.reply", { a: count }).then(res => {
		if (count % 10000) {
			// Fast cycle
			doRequest();
		} else {
			// Slow cycle
			setImmediate(() => doRequest());
		}

	}).catch(err => {
		throw err;
	});
}
/*
const globalMsg = {
	nodeID: "server-2",
	requestID: generateToken(),
	action: "posts.empty",
	params: { a: 5 }
};

function doStringify() {
	const msg = {
		nodeID: "server-2",
		requestID: generateToken(),
		action: "posts.empty",
		params: { a: 5 }
	};

	count++;
	let res = json2String(msg);

	if (count % 1000) 
		doStringify();
	else
		setImmediate(() => doStringify());
}*/

setTimeout(() => {
	let startTime = Date.now();
	
	doRequest();
	//doStringify();

	setInterval(() => {<commit_msg>add res to perf<commit_after>"use strict";

const v8 = require('v8-natives');   

let ServiceBroker = require("./src/service-broker");
let Context = require("./src/context");
let Transporters = require("./src/transporters");

let { generateToken, json2String } = require("./src/utils");
let Promise	= require("bluebird");


function createBrokers(Transporter, opts) {
	let b1 = new ServiceBroker({
		transporter: new Transporter(opts),
		//requestTimeout: 0,
		//logger: console,
		//logLevel: "debug",
		nodeID: "node-1"
	});

	let b2 = new ServiceBroker({
		transporter: new Transporter(opts),
		//requestTimeout: 0,
		//logger: console,
		//logLevel: "debug",
		nodeID: "node-2"
	});

	b2.createService({
		name: "echo",
		actions: {
			reply(ctx) {
				return ctx.params;
			}
		}
	});

	b1.start().then(() => b2.start());

	return [b1, b2];
}

let [b1, b2] = createBrokers(Transporters.Fake);

function translateStatus(status) {
	const texts = [
		"-",
		"Optimized",
		"Un-optimized",
		"Always Optimized",
		"Never Optimized",
		"?",
		"Maybe Optimized",
	];
	return texts[status];
}


let count = 0;
function doRequest() {
	count++;
	return b1.call("echo.reply", { a: count }).then(res => {
		if (count % 10000) {
			// Fast cycle
			doRequest();
		} else {
			// Slow cycle
			setImmediate(() => doRequest());
		}
		return res;

	}).catch(err => {
		throw err;
	});
}
/*
const globalMsg = {
	nodeID: "server-2",
	requestID: generateToken(),
	action: "posts.empty",
	params: { a: 5 }
};

function doStringify() {
	const msg = {
		nodeID: "server-2",
		requestID: generateToken(),
		action: "posts.empty",
		params: { a: 5 }
	};

	count++;
	Promise.resolve(json2String(msg)).then(res => {
		if (count % 1000) 
			doStringify();
		else
			setImmediate(() => doStringify());

		return res;
	});

}*/

setTimeout(() => {
	let startTime = Date.now();
	
	doRequest();
	//doStringify();

	setInterval(() => {
{'fraction_non_alphanumeric': 0.1929217668972858, 'fraction_numerical': 0.017030335284725917, 'mean_word_length': 3.5289156626506024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '55656', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1360, 'n_words': 307}