fork: function(count) {
   if (syscalls.fork() == 0) {
     console.log("In child process: " + syscalls.getpid());
     this.start();
   } else {
     console.log("In master process: " + syscalls.getpid());
     count--;
     if (count > 0) {
       this.fork(count);
     } else {
       syscalls.waitpid(-1); // Wait for all children prorcess to stop
     }
   }
 }
Beispiel #2
0
HttpServer.prototype.fork = function(workers) {
  if (syscalls.fork() == 0) {
    console.log("In a child process: " + syscalls.getpid())
    this.start()
  } else {
    console.log("In the master process: " + syscalls.getpid())
    workers--
    if (workers > 0) {
      this.fork(workers)
    } else {
      syscalls.waitpid(-1) // Wait for all the children process to exit
    }
  }
}
var server = new HttpServer(function(request, response) {
  if (request.url == "/slow") {
    var objects = [];
        
    // for (var i=0; i < 10000000; i++) {
    //   objects.push(new Object()); // pretend we're computing something here
    // };

    var i = 0;
    function compute() {
      for (var j = 0; j < 100000; j++, i++) {
        objects.push(new Object()); // pretend we're computing something here
      };

      if (i < 10000000) {
        i++;
        loop.nextTick(compute);
      } else {
        response.send("slow request done\n");        
      }
    }

  } else {
    response.send("from pid: " + syscalls.getpid() + "\n");
  }
});
Beispiel #4
0
var server = new HttpServer(function(req, res) {
  if (req.url == "/slow") {
    var objects = []
        
    // for (var i = 0; i < 10000000; i++) {
    //   objects.push(new Object()) // pretend we're computing something here
    // }

    var i = 0
    function compute() {
      for (var j = 0; j < 100000; j++) {
        objects.push(new Object())
      }
      
      if (i < 10000000) {
        i++
        loop.nextTick(compute)        
      } else {
        // done
        res.send("slow request done\n")
      }
    }
    compute()

  } else {
    res.send("from pid: " + syscalls.getpid() + "\n")
  }
})
var server = new HttpServer(function(request, response) {
  response.send("from pid: " + syscalls.getpid() + "\n");
});