Latency Headers PoC
Adding HTTP headers to http responses enables developers to gain a better view into their API layer's latency and networking bottlenecks.
Explaination
Basically there are two headers introduced in this proof of concept:
x-request-received
is set by the server with the timestamp of when the request was receivedx-response-sent
is set by the server with the timestamp of when the response was sent
With these headers in place the client can then determine the following:
- 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
Complete Example
server.js
// Load the http modulevar http = ; // Make it easy to pkill from npmprocesstitle = "latencyServer" // Create the servervar server = http; // Listen on localhost:1337server;
app.js
// Require http for requestsvar http = // Save the timestamp of when the request was sent as its requiredvar requestSent = // Send the request to a server that returns the latency headershttp
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
Related projects
Copyright (c) 2014, Montana Flynn (http://anonfunction.com/)