Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jslint node: true, plusplus: true*/
- 'use strict';
- var RAND_MAX = 9999,
- users = {},
- current_active = 0;
- function get_random_id() {
- return Math.floor(Math.random() * RAND_MAX);
- }
- function do_logout(cb) {
- var id = get_random_id();
- if (users.hasOwnProperty(id)) {
- delete users[id];
- current_active--; // Would fire event here on delete of key
- }
- cb();
- process.nextTick(function () {
- do_logout(cb);
- });
- }
- function do_login(cb) {
- var time = +new Date(),
- id = get_random_id();
- if (!users.hasOwnProperty(id)) {
- current_active++; // Would fire event here on insert of key
- }
- users[id] = time;
- cb();
- process.nextTick(function () {
- do_login(cb);
- });
- }
- function run_benchmark() {
- var start = new Date(),
- done = 0,
- last = 0;
- function cb(v) {
- done++;
- }
- setInterval(function () {
- var x, doneTime = +new Date() - 10000;
- for (x in users) {
- if (users.hasOwnProperty(x) && users[x] < doneTime) {
- delete users[x];
- current_active--; // Would fire event here on expire
- }
- }
- }, 500);
- setInterval(function () {
- console.log('Throughput:', (done - last), 'r/s, currently active:', current_active);
- last = done;
- }, 1000);
- do_logout(cb);
- do_login(cb);
- }
- run_benchmark();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement