Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about worker & concurrent serve incoming http request #707

Closed
tangkhaiphuong opened this issue Jul 15, 2018 · 1 comment
Closed
Labels
question A question (converts to discussion)

Comments

@tangkhaiphuong
Copy link

tangkhaiphuong commented Jul 15, 2018

I intend to use Rocket replace Node.js for static file handler base on example: https://github.com/SergioBenitez/Rocket/tree/master/examples/static_files

The main point here use NamedFile structure and after look in deep implement:
https://github.com/SergioBenitez/Rocket/blob/f171dc9d095b9b1f63ba5bb69fbbbdf4aef7ccf2/core/lib/src/response/named_file.rs

I found that if the incoming request for the large file (ex over 1GB) the total request per second is decreasing vs node.js static file handler.

So there are some points here:

  1. Rocket start with the fixed number of worker. Mean if any incoming request, a worker in the pool will handler it? (If pool have 10 workers, then at the same time can handler 10 requests concurrently)
  2. If all worker takes more time to handler request until done (ex. large process/ download file) another new incoming request must wait for any free worker? (I found that it another request must wait)

So the node.js handler in a different way by can accept all connection and by using event loop and serve a chunk of the file then response concurrently.
With Rocket, if the request for the large file and all worker are busy to read the file and can't accept the new incoming request, then the connecting timeout raise at the client.

So how to resolve this case like node.js? mean can accept all connection and we have many concurrent threads read chunk bytes of file and response to the client.

Express

var express = require('express');
var app = express();
var path = require('path');
var public = path.join(__dirname, 'public');
process.env.UV_THREADPOOL_SIZE = 64;

app.get('/', function (req, res) {
    res.sendFile(path.join(public, 'index.html'));
});

app.use('/', express.static(public));

app.listen(8080);

Rocket

#![feature(plugin, decl_macro)]
#![plugin(rocket_codegen)]

extern crate rocket;

use std::io;
use std::path::{Path, PathBuf};

use rocket::response::NamedFile;

#[get("/")]
fn index() -> io::Result<NamedFile> {
    NamedFile::open("public/index.html")
}

#[get("/<file..>")]
fn files(file: PathBuf) -> Option<NamedFile> {
    NamedFile::open(Path::new("public/").join(file)).ok()
}

fn rocket() -> rocket::Rocket {
    rocket::ignite().mount("/", routes![index, files])
}

fn main() {
    rocket().launch();
}

Run benchmark (https://github.com/aliostad/SuperBenchmarker)

Express (Node.js)

sb -u http://localhost:8080/abc.pdf -n 100 -c 10
Starting at 7/15/2018 9:40:13 PM
[Press C to stop the test]
100     (RPS: 2.9)
---------------Finished!----------------
Finished at 7/15/2018 9:40:47 PM (took 00:00:34.1470019)
Status 200:    100

RPS: 2.9 (requests/second)
Max: 4285ms
Min: 1662ms
Avg: 3135.3ms

  50%   below 3135ms
  60%   below 3250ms
  70%   below 3369ms
  80%   below 3500ms
  90%   below 3879ms
  95%   below 4003ms
  98%   below 4264ms
  99%   below 4285ms
99.9%   below 4285ms

Rocket

sb -u http://localhost:8000/abc.pdf -n 100 -c 10
Starting at 7/15/2018 9:40:12 PM
[Press C to stop the test]
100     (RPS: 2.9)
---------------Finished!----------------
Finished at 7/15/2018 9:40:47 PM (took 00:00:34.9820037)
Status 200:    100

RPS: 2.8 (requests/second)
Max: 11932ms
Min: 1125ms
Avg: 3121.9ms

  50%   below 3104ms
  60%   below 3222ms
  70%   below 3391ms
  80%   below 3542ms
  90%   below 3858ms
  95%   below 4141ms
  98%   below 8506ms
  99%   below 11932ms
99.9%   below 11932ms
@SergioBenitez
Copy link
Member

So how to resolve this case like node.js? mean can accept all connection and we have many concurrent threads read chunk bytes of file and response to the client.

If I understand correctly, you're asking if it's possible to configure Rocket so that it handle requests in the way that Node.JS does. The answer is no: doing so would mean that Rocket handles requests asynchronously, which would require rearchitecting the HTTP sublayer. This is scheduled to happen soon as is being tracked in #17.

@SergioBenitez SergioBenitez added the question A question (converts to discussion) label Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question (converts to discussion)
Projects
None yet
Development

No branches or pull requests

2 participants