Skip to content

Instantly share code, notes, and snippets.

@tomusdrw
Created June 21, 2017 14:03
Show Gist options
  • Select an option

  • Save tomusdrw/01f4b5c76e779a4e96cff8c0e36f17db to your computer and use it in GitHub Desktop.

Select an option

Save tomusdrw/01f4b5c76e779a4e96cff8c0e36f17db to your computer and use it in GitHub Desktop.
Nodejs:
'use strict';
const Hapi = require('hapi');
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: 'localhost',
port: 3002
});
// Add the route
server.route({
method: 'GET',
path:'/',
handler: function (request, reply) {
return reply(Date.now());
}
});
// Start the server
server.start((err) => {
if (err) {
throw err;
}
console.log('Server running at:', server.info.uri);
});
Rust:
extern crate time;
extern crate hyper;
extern crate futures;
use hyper::header;
use hyper::server::{Http, Request, Response, Service};
struct Time;
impl Service for Time {
type Request = Request;
type Response = Response;
type Error = hyper::Error;
type Future = futures::future::FutureResult<Self::Response, Self::Error>;
fn call(&self, _req: Request) -> Self::Future {
let now = time::now_utc();
let spec = now.to_timespec();
let time = spec.sec * 1000 + spec.nsec as i64 / 1_000_000;
let now = format!("{}", time);
futures::future::ok(
Response::new()
.with_header(header::ContentLength(now.len() as u64))
.with_body(now)
)
}
}
fn main() {
let addr = "127.0.0.1:3001".parse().unwrap();
let server = Http::new().bind(&addr, || Ok(Time)).unwrap();
server.run().unwrap();
}
Results:
$ wrk -t 10 -d 30s -c 1000 --latency http://127.0.0.1:3002/ # JS+Hapi
Running 30s test @ http://127.0.0.1:3002/
10 threads and 1000 connections
24/360 Thread Stats Avg Stdev Max +/- Stdev
Latency 536.89ms 160.39ms 1.39s 82.31%
Req/Sec 193.91 141.67 730.00 68.08%
Latency Distribution
50% 520.01ms
75% 540.08ms
90% 623.96ms
99% 1.08s
51325 requests in 30.09s, 11.27MB read
Socket errors: connect 0, read 0, write 0, timeout 264
Requests/sec: 1705.95
Transfer/sec: 383.50KB
$ wrk -t 10 -d 30s -c 1000 --latency http://127.0.0.1:3001/ # Rust
Running 30s test @ http://127.0.0.1:3001/
10 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 14.98ms 11.46ms 451.05ms 99.34%
Req/Sec 6.83k 1.09k 13.11k 78.13%
Latency Distribution
50% 14.12ms
75% 15.56ms
90% 17.62ms
99% 23.42ms
2039715 requests in 30.07s, 173.12MB read
Requests/sec: 67822.30
Transfer/sec: 5.76MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment