Skip to content

montanaflynn/latency-header-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latency Headers Benchmark

Tool to benchmark latency header enabled HTTP server responses. Returns the following metrics:

  • outgoing network latency: time between client sending the request and server receiving it
  • server processing latency: time between server receiving the request and sending the response
  • incoming network latency: time between server sending the response and client receiving it
  • total round trip latency: time between client sending the request and receiving response

The original proof-of-concept has more details and examples.

Usage

latencyHeadersBenchmark(requestSent, headers)

  • requestSent integer - Timestamp of when the request was sent
  • headers object - Required headers object with the following properties
    • x-request-received integer Timestamp of when the request was received by the server
    • x-response-sent integer Timestamp of when the response was sent by the server

Note: All timestamps are milliseconds since epoch

Example

// Require http for the request
var http = require('http')

// Require latency-headers-benchmark 
var latencyBenchmark = require('latency-headers-benchmark')

// Save the timestamp of when the request was sent as its required
var requestSent = new Date().getTime()

// Send the request to a server that returns the latency headers
http.get("http://localhost:1337", function(res) {

  // Run the benchmark
  var results = latencyBenchmark(requestSent, res.headers)

  // Output the results
  console.log(results)

})

Try it out

An example server and app is included in this repo for your convenience.

# Clone this repo
git clone git@github.com:montanaflynn/latency-header-benchmark.git

# CD to the example dir
cd latency-header-benchmark/example

# Install this package (npmception?)
npm install

# Start the server in the background
node server.js &

# Run the app
node app.js

# Kill the example server
pkill latencyServer

Servers

MIT license

Copyright (c) 2014, Montana Flynn (http://anonfunction.com/)

About

Benchmark HTTP requests incoming, outgoing, processing and roundtrip latencies

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published