mtuc

0.0.1 • Public • Published

Maximum transmission unit controller. Build Status

Maximum transmission unit controller makes sending data over TCP more efficient, faster! The Maximum transmission unit (MTU) sets the maximum size of a packet of bytes to be sent over the network wire. When you have many messages to send that are each less in size that the MTU setting, it is much more efficient to buffer these messages up to best fit the MTU and then send, this is what this module does.

TCP has a inbuilt feature called 'noDelay', also called the Nagle algorithm. This algorithm when enabled: 'noDelay = false', does a similar job as this module. However this module provides even faster results and fine tuning controls. It is possible to use both the Nagle algorithm and this module together, or separately.

MTUC works well with data framing modules 'messages', such as: SMP, AMP, MQTT.

Installation

npm install mtuc

Examples

See examples folder. To print use preview, eg: node examples/mtuc.js --preview

var mtuc = require('mtuc');     // npm install mtuc
var net  = require('net');      // TCP
 
 
// TCP server.
var server = net.createServer(function(sock){
 
  sock.on('data', function(chunk){
    console.log('chunk', chunk);
  });
 
}).listen(8888);
 
 
// TCP client.
var clientsocket = net.connect(8888);
 
// as example mtu size set to 10, production should be ~ 1500 or 9000.
var mtucontoller = new mtuc({mtu: 10}, clientsocket);   // {options}, socket (can be either server or client sockets).
 
var data = 'abcdefghijklmnopqrstuvwxyz';    // 26 bytes.
 
mtucontoller.send(new Buffer(data));    // send( <Buffer> ), returns true if socket overflowing.

Benchmarking

See bm folder to run benchmarking tests.

Results

Using a WebSocket connection naked-websocket and sending 200 byte SMP messages, I get over 300,000 messages per second.

---------------------------------------------
| RESULTS ~
---------------------------------------------
|     median: 322,581 ops/s
|       mean: 275,587 ops/s
|      total: 2,750,084 ops in 9.979s
|    through: 55.39 MB/s
---------------------------------------------

Tips (Linux)

To view your MTU setting

netstat -i

Or

ifconfig

To change a MTU setting of say the eth0 network to 9000 bytes (temp)

sudo ifconfig eth0 mtu 9000

Options

 mtu: 1500,        // Maximum transmission unit size in bytes.
 delay: 100,       // ms to delay before flushing if buffer batch is smaller than mtu.
 noDelay: false,   // if true, disable this the mtu-controller and write to the socket immediately.

License

Choose either: MIT or Apache 2.0.

Package Sidebar

Install

npm i mtuc

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • fluidecho