Code Monkey home page Code Monkey logo

uwsgi-rust's Introduction

uwsgi-rust

uWSGI and Rust integration plugin

This plugin is an experimental effort to support Rust runtime into uWSGI.

Consider it a proof of concept.

To build (and use) the plugin you need at least a rust-1.x stable environment installed (rustc/cargo binaries must be in the system PATH)

Installation

uwsgi --build-plugin https://github.com/unbit/uwsgi-rust

will generate the rust_plugin.so uWSGI plugin

Or you can make a monolithic build using the network installer (currently probably broken on Linux, works on OSX)

curl http://uwsgi.it/install | UWSGI_EMBED_PLUGINS="rust=https://github.com/unbit/uwsgi-rust" bash -s nolang /tmp/uwsgi

(this will result in the /tmp/uwsgi binary)

Usage

Currently uWSGI expects Rust apps to be managed as shared/dynamic libraries:

use std::collections::HashMap;

#[no_mangle]
pub extern fn application(environ: HashMap<&str, &str>) -> (String, Vec<(String, String)>, Vec<Vec<u8>>) {

        for (k, v) in environ.iter() {
                println!("{} = {}", *k, *v);
        }

        let mut v = vec![];
        v.push((String::from("Content-Type"), String::from("text/plain")));
        v.push((String::from("Foo"), String::from("Bar")));

        let mut body = vec![];

        body.push(String::from("Hello").into_bytes());

        return (String::from("200 OK"), v, body);
}

running

cargo build --release --manifest-path examples/Cargo.toml

will result in librust_uwsgi_app.so under examples/target/release/

This new library can be loaded in the uWSGI core with the standard --dlopen option. Finally you only need to tell uWSGI which rust function to execute ('application' in this case) at every request:

[uwsgi]
; load the rust plugin (if needed, rememebr you can eventually make monolithic builds)
plugin = rust
; bind to http port 8080
http-socket = :8080
; load the library app
dlopen = ./examples/target/release/librust_uwsgi_app.so
; set 'application' as the entry point
rust-fn = application

; enable master
master = true
; spawn 10 threads in each process/worker
threads = 10
; spawn 8 processes/workers
processes = 8

Status

prefork and layzy-apps modes are both supported

multiprocessing works

multithreading works (included spawning threads from rust)

Notes

pub extern fn application(environ: HashMap<&str, &str>) -> (String, Vec<(String, String)>, Vec<Vec<u8>>);

is not the final prototype for the entry point (and absolutely not the best one, expecially the Vec<Vec<u8>> return value could be very inefficient). Feel free to propose more approaches (we can eventually support multiple of them).

Currently we are still investigating the best approach for accessing the request body (maybe a Reader object could be a good solution).

Monolithic builds on Linux x86_64 looks broken. We are investigating on it.

uwsgi-rust's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.