Git Product home page Git Product logo

rust-mongodb-example's Introduction

ACTIX WEB - MONGODB EXAMPLE

A web server, written in Rust, using actix-web framework.

Web server exposes:

  • GET /hello endpoint, and writes name query string value to mongodb as a document({name: $name-query-string}).
  • GET /get endpoint which finds one document from db.

HOW TO RUN

  • start a mongod deamon locally (mongodb://localhost:27017)
  • run cargo build --release
  • run ./target/release/rust-mongo-example

GET /hello endpoint will be exposed.

HOW TO TEST

curl http://localhost:3000/hello?name=joe

Success should be returned and {name: "joe"} document should have been written in mydb database, users collection.

PERFORMANCE

In order to see the performance of Rust as a web server with I/O bound tasks, I benchmarked this project against a NodeJS web server(using NestJS) which does the same task. Here are results:

Rust

Rust 1.x

autocannon -c 500 http://localhost:3000/hello?name=joe Running 10s test @ http://localhost:3000/hello?name=joe 500 connections

Avg Latency: 3.74 ms

Avg Req/Sec: 17731.2

Req/Bytes counts sampled once per second.

177k requests in 10.14s, 14.2 MB read 315 errors (293 timeouts)

Rust 2.0

  • /hello

autocannon -c 50 http://localhost:3000/hello?name=joe Running 10s test @ http://localhost:3000/hello?name=joe 50 connections

Avg Latency: 2.15 ms

Avg Req/Sec: 18686.19

Req/Bytes counts sampled once per second.

206k requests in 11.04s, 16.9 MB read

  • /get

autocannon -c 50 http://localhost:3000/get Running 10s test @ http://localhost:3000/get 50 connections

Avg Latency: 1.27 ms

Avg Req/Sec: 18760

Req/Bytes counts sampled once per second.

206k requests in 11.05s, 33.8 MB read

NodeJS (clustered using pm2 -- pm2 start main.js -i max)

autocannon -c 500 http://localhost:3000/hello?name=joe Running 10s test @ http://localhost:3000/hello?name=joe 500 connections

Avg Latency: 75.06 ms

Avg Req/Sec: 6637.4

Req/Bytes counts sampled once per second.

66k requests in 10.22s, 17.8 MB read

CONTRIBUTE

Feel free to contribute, you may want to add extra endpoints, benchmark against different stacks, etc.

rust-mongodb-example's People

Contributors

mehmetsefabalik avatar

Watchers

 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.