:zap: fast http framework for rust

Overview

zap

GitHub issues Travis GitHub stars Crates.io Crates.io

The mission of zap is, to deliver a basic, but fast rust web server library.

Documentation

About

This code is based on tokio's minihttp project, so a big thanks to them. (source)

The goal of this project is, to show how fast Rust can be. It isn't made for huge complex applications, just a test project for benchmark reasons.

How to use

Add the following to your Cargo.toml:

[dependencies]
zap = "0.0.4"

Speed

So zap is not only fast, it is wapping 2.96 times faster than iron, which is based on hyper. Benchmarks below:

Benchmark Code

Iron

This code had been taken from the ironframework.io webpage.

extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "Hello World!")))
    }

    Iron::new(hello_world).http("localhost:3000").unwrap();
}

Zap

This example can be run, by:

$ git clone https://github.com/oltdaniel/zap && cd zap
$ cargo run --example hello-world --release
extern crate zap;

use std::io::Error as ZapError;
use zap::prelude::*;

struct HelloWorld;

impl Handler for HelloWorld {
    type Request = Request;
    type Response = Response;
    type Error = ZapError;
    type Future = ZapResult;

    fn call(&self, _: Request) -> ZapResult {
        let mut resp = Response::new();

        resp.body("Hello World!");

        resp.ok()
    }
}

fn main() {
    let addr = "0.0.0.0:8080".parse().unwrap();
    let mut server = Server::new(Http, addr);
    server.threads(8);
    server.serve(|| Ok(HelloWorld));
}

Benchmark Results

The benchmark results have been computed with this command: wrk -t16 -c500 -d10s http://127.0.0.1:8080 --latency

Technical details about the server:

  • Intel Core I7-6700K, hyper-threaded
  • 16GB RAM, 2400MHZ

Detailed results: in the wiki.

Iron

[...]
Requests/sec: 307581.17
Transfer/sec:     33.44MB

Zap

[...]
Requests/sec: 912832.31
Transfer/sec:     40.90MB

Credits & License

Daniel Oltmanns & others

Basically do what you'd like to.

GitHub license

Comments
  • bytes - memory allocation

    bytes - memory allocation

    As the benchmark results show:

    test tests::bench_allocate_pieces ... bench:       2,501 ns/iter (+/- 80)
    test tests::bench_allocate_pile   ... bench:       1,279 ns/iter (+/- 74)
    

    Allocating a big pile is faster then allocating it in small pieces. The problem is, collecting the data we need to write and then push it into the buffer.

    opened by 0x1daniel 3
  • performance - CPU heavy requests block threads

    performance - CPU heavy requests block threads

    Since we don't process each request apart from another, CPU heavy requests block the threads.

    Can be solved by Accepting requests with go Ok(HandlerName)

    bug enhancement 
    opened by daniel-Q6wUOI 2
  • requets - Empty reply on more than 16 headers

    requets - Empty reply on more than 16 headers

    Cause we need to give httparse a fixed size of headers, I want to get rid of it. So let's build a custom implementation of HTTP Request parsing.

    It should work as the following:

    • Just make a new bytes::BytesMut object out of the headers
    • when a header is requested, search in the BytesMut and return an array of result (why an array? Headers can be defined more than one times, alternative: Keep first header value, ignore others)

    This can lead to a performance improvement!?

    enhancement help wanted 
    opened by daniel-Q6wUOI 2
  • Compare it to other implementations

    Compare it to other implementations

    Hi,

    It would be nice if you could explain just in few sentences what implementation strategy you've chosen that makes your implementation faster.

    I'm the co-author of tk-http yet another http implementation in rust. It's also different from hyper in several things, in particular of how buffering is done and makes API more low-level allowing more optimizations on application level (i.e. de/serialize right into connection buffer, etc.). Also, we don't try to parse headers into type-safe things proactively (i.e. only parse headers need for this specific handler) which also saves CPU and avoids many memory allocations.

    I haven't tested performance lately, as we focus more on correctness, but we are already running our implementation in production and it works pretty nice (as part of swindon project).

    By writing this I'm trying to say that if your implementation makes similar assumptions and optimizations it would be great to join our effort.

    wiki 
    opened by tailhook 2
  • performance - Benchmarks show bad performance

    performance - Benchmarks show bad performance

    As we can see in the benchmark results by running cargo bench:

    Running target/release/deps/push_bytes-00e4ab3141864ae0
    
    running 6 tests
    test tests::bench_all_combined      ... bench:          26 ns/iter (+/- 1)
    test tests::bench_convert_and_push  ... bench:           6 ns/iter (+/- 0)
    test tests::bench_extend_from_slice ... bench:           8 ns/iter (+/- 0)
    test tests::bench_fastwrite         ... bench:          13 ns/iter (+/- 1)
    test tests::bench_push_to_buffer    ... bench:           6 ns/iter (+/- 0)
    test tests::bench_string_to_push    ... bench:           6 ns/iter (+/- 0)
    
    test result: ok. 0 passed; 0 failed; 0 ignored; 6 measured; 0 filtered out
    

    A combination of all functions we use is a bad option. Also we should get rid of FastWrite and convert it by our own, that saves us some time as test tests::bench_fastwrite and test tests::bench_string_to_push show.

    Any ideas how to get the last ns out of the IO writing part?

    enhancement 
    opened by daniel-Q6wUOI 1
Releases(v0.0.4)
Owner
Daniel Oltmanns
▓ ▒ ▓ ░ ▓ ▒ ▓ ▒ ▓ █ ░
Daniel Oltmanns
[OUTDATED] A light HTTP framework for Rust

Rustful A light HTTP framework for Rust, with REST-like features. The main purpose of Rustful is to create a simple, modular and non-intrusive foundat

Erik Hedvall 873 Nov 12, 2022
Fully async-await http server framework

Saphir is a fully async-await http server framework for rust The goal is to give low-level control to your web stack (as hyper does) without the time

Richer Archambault 83 Dec 19, 2022
Node.js http server framework powered by Hyper native binding.

hnsjs POC project. Install this test package yarn add @hnsjs/core Support matrix node10 node12 node14 node15 Windows x64 ✓ ✓ ✓ ✓ Windows x32 ✓ ✓ ✓ ✓

LongYinan 18 Nov 23, 2022
Host These Things Please - a basic http server for hosting a folder fast and simply

http Host These Things Please - a basic HTTP server for hosting a folder fast and simply Selected features See the manpage for full list. Symlinks fol

thecoshman 367 Dec 23, 2022
Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.

Actix Web Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust Features Supports HTTP/1.x and HTTP/2 Streaming and pipelining

Actix 16.3k Jan 8, 2023
A fast, boilerplate free, web framework for Rust

Tower Web A web framework for Rust with a focus on removing boilerplate. API Documentation Tower Web is: Fast: Fully asynchronous, built on Tokio and

Carl Lerche 969 Dec 22, 2022
Simple http server in Rust (Windows/Mac/Linux)

How it looks like? Screenshot Command Line Arguments Simple HTTP(s) Server 0.6.1 USAGE: simple-http-server [FLAGS] [OPTIONS] [--] [root] FLAGS:

LinFeng Qian 788 Dec 28, 2022
An HTTP library for Rust

hyper A fast and correct HTTP implementation for Rust. HTTP/1 and HTTP/2 Asynchronous design Leading in performance Tested and correct Extensive produ

null 11k Jan 7, 2023
Low level HTTP server library in Rust

tiny-http Documentation Tiny but strong HTTP server in Rust. Its main objectives are to be 100% compliant with the HTTP standard and to provide an eas

null 785 Dec 29, 2022
Akasio is a simple HTTP server that redirects traffic based on a JSON redirect table. This is its Rust implementation.

This page is inaccurate and is pending updates. Akasio (Rust) Description Akasio is a simple HTTP server that redirects traffic based on a JSON redire

K4YT3X 5 May 2, 2022
service_policy_kit is a Rust based toolkit for verifying HTTP services against policies.

Service Policy Kit service_policy_kit is a Rust based toolkit for verifying HTTP services against policies. You can: Build a complete testing framewor

null 19 Dec 5, 2022
Completely OBSOLETE Rust HTTP library (server and client)

OBSOLETION NOTICE This library is DEAD. It was a useful experiment and is now being replaced under the scope of the Teepee (experimentation grounds at

Chris Morgan 390 Dec 1, 2022
Archibald is my attempt at learning Rust and writing a HTTP 1.1 web server.

Archibald To be a butler, is to be able to maintain an even-temper, at all times. One must have exceptional personal hygiene and look sharp and profes

Daniel Cuthbert 4 Jun 20, 2022
🌟 For when you really just want to serve some files over HTTP right now!

miniserve - a CLI tool to serve files and dirs over HTTP For when you really just want to serve some files over HTTP right now! miniserve is a small,

Sven-Hendrik Haase 4.1k Dec 31, 2022
Add Facebook and Google authentication to your HTTP REST API in Actix-web

I created this project while learning Rust. Project shows how to handle Facebook and Google token verification in Rust using Actix-Web. Hope this help

null 37 Dec 31, 2022
RUSTENGINE is the high-assurance HTTP server.

RUSTENGINE Table of Contents RUSTENGINE Table of Contents About RUSTENGINE Inspiration with Rust Features Compares with Nginx Build & Run About this R

FUNNY SYSTEMS 10 Aug 27, 2021
OxHTTP is a very simple synchronous HTTP client and server

OxHTTP is a very simple synchronous implementation of HTTP 1.1 in Rust. It provides both a client and a server.

Oxigraph 13 Nov 29, 2022
A synchronous HTTP server built on hyper.

Astra Astra is a synchronous HTTP server built on top of hyper. use astra::{Body, Response, Server}; fn main() { Server::bind("localhost:3000")

Ibraheem Ahmed 23 Nov 27, 2022
Operator is a web server. You provide a directory and Operator serves it over HTTP.

Operator Operator is a web server. You provide a directory and Operator serves it over HTTP. It serves static files the way you'd expect, but it can a

Matt Kantor 6 Jun 6, 2022