<commit_before># Tiamat

A forking server for node.js - think multi process non blocking server

## Install

    npm install -g tiamat

## Running with Tiamat

Tiamat loads a worker.js script that should export a run method.  The run method should return your server.

For example, a simple way to expose your HTTP server would be:

    exports.run = function(config, next) {
      var http  = require("http");
      var server = http.createServer(function(req, res) {
        res.end("Hello World");
      });
      next(server); // let tiamat handle binding your server
    };

The server can be an HTTP Server or any other kind of TCP server.

Tiamat simply passes the listening file descriptor down to each worker. Inside of each worker process Tiamat, will require the worker.js script,
invoke run, and call listenFD on the returned server object.

## The Config File

In the configuration file you tell Tiamat where you want things like stdout and stderr to be redirected.
How many worker processes to start, what port to listen on etc...

    exports.load = function() {
      return {
        tcp: 'tcp4',
        backlog: 128,
        listen_addr: "127.0.0.1",
        listen_port: 1337,
        workers: 2,
        timeout: 45,
        worker_app: __dirname + "/test/worker1.js",
        daemonize: true,
        working_directory: __dirname,
        stderr_path: __dirname + "/stderr.log",
        stdout_path: __dirname + "/stdout.log",
        pidfile: __dirname + "/pidfile.pid",
        before_exec: function() {
          console.error("before exec");
        },
        before_fork: function() {
          console.error("before fork");<commit_msg>update with notes on using express<commit_after># Tiamat

A forking server for node.js - think multi process non blocking server

## Install

    npm install -g tiamat

## Running with Tiamat

Tiamat loads a worker.js script that should export a run method.  The run method should return your server.

For example, a simple way to expose your HTTP server would be:

    exports.run = function(config, next) {
      var http  = require("http");
      var server = http.createServer(function(req, res) {
        res.end("Hello World");
      });
      next(server); // let tiamat handle binding your server
    };

The server can be an HTTP Server or any other kind of TCP server.

Tiamat simply passes the listening file descriptor down to each worker. Inside of each worker process Tiamat, will require the worker.js script,
invoke run, and call listenFD on the returned server object.

## Using Tiamat with Express

    var express     = require('express'),
        app         = module.exports = express.createServer(),

    app.get('/', function(req, res) {
      res.send('active');
    });

    if (!process.env.TIAMAT) {
      app.listen(process.env.PORT || 3000);
    }

The only thing special here is to not have your app.js bind, instead because it exports the expressServer, tiamat will handle binding for you.

    tiamat -s app.js

## The Config File

In the configuration file you tell Tiamat where you want things like stdout and stderr to be redirected.
How many worker processes to start, what port to listen on etc...

    exports.load = function() {
      return {
        tcp: 'tcp4',
        backlog: 128,
        listen_addr: "127.0.0.1",
        listen_port: 1337,
        workers: 2,
        timeout: 45,
        worker_app: __dirname + "/test/worker1.js",
        daemonize: true,
        working_directory: __dirname,
        stderr_path: __dirname + "/stderr.log",
        stdout_path: __dirname + "/stdout.log",
        pidfile: __dirname + "/pidfile.pid",
        before_exec: function() {
          console.error("before exec");
        },
        before_fork: function() {
          console.error("before fork");
{'fraction_non_alphanumeric': 0.0906463478717814, 'fraction_numerical': 0.010509721492380452, 'mean_word_length': 2.667630057803468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2665791', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1043, 'n_words': 425}